Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Elastic Beanstalk Configuration files
.elasticbeanstalk/
43 changes: 43 additions & 0 deletions docs/beanstalk/01_Getting_Started/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Getting Started

Before you can create resources in AWS you will first need to configure your local environment.

Note that the EB CLI requires Python to be installed on your system.

### AWS Authentication Keys

1) Login into your AWS Educate account and select "AWS Account" on the top right


2) Select "AWS Educate Starter Account" which should open a new tab

![AWS Educate account details selection](./images/1_Account_Details.png)


3) Select the "Account Details" button and you will be presented with

![AWS Educate account details window](./images/2_AWS_API_Creds.png)


4) Using your favorite editor copy the entire contents of the "AWS CLI" section to the `~/.aws/credentials` file on Mac/Linux and `%UserProfile%\.aws\credentials` on Windows.
More information can be found in the [CLI Configuration Docs](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html)

<br>
<br>
Now that your API credentials are saved, you will be able to authenticate against your AWS account using CLI tools as well as programs that use the AWS SDK. Note that AWS Educate tokens expire after 3 hours, so please repeat these steps if you receive an expired session error.
<br>
<br>

### Install and Configure the EB CLI
EB ClI - See installation [instructions](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install-advanced.html) for your OS

Once installed check that the CLI is installed by running:

```
eb --version
EB CLI 3.19.3 (Python 3.8.5)
```

---

Next: [Creating EB Environment](../02_Creating_EB_Environment/README.md)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
87 changes: 87 additions & 0 deletions docs/beanstalk/02_Creating_EB_Environment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Creating Your Elastic Beanstalk Environment

Now that you have the EB CLI installed, you will be able to push your Backend (Server) code to Elastic Beanstalk in your AWS account.

Note that all of the following will take place withing the `server` directory.

## Initializing Your Elastic Beanstalk Project

Initializing your Elastic Beanstalk project will create a `.elasticbeanstalk` folder which will contain a configuration file with information about your EB deployment.


<br>
1) Run the `eb init` command which will prompt you for a few questions. You make your selection by typing the matching number or character and pressing "Enter".
Make sure to select the "US East (N. Virginia)" option which should be #1.

![Running "eb init" command and selecting Option 1 <US East N. Virginia>)](./images/EB_CLI_INIT_1_Select_Region.png)


<br>
2) You will now be prompted to either create an application or select an existing on. Enter the number for "Create a new Application"

![Selecting "Create a new Application" option](./images/EB_CLI_INIT_2_Create_New_App.png)


<br>
3) Next you will be prompted to enter the name of your project. In this example "CSCL" was used. Feel free to use a different name.
Comment thread
steve-louis marked this conversation as resolved.

![Entering the name for our EB application](./images/EB_CLI_INIT_3_Set_Name.png)


<br>
4) Now you will be asked if you are "using Node.js", enter `y` or "yes". Next, choose the "Node.js 12" option which should be #1.

![Enter "y" to confirm that you are using "Node.js" and select "Node.js 12"](./images/EB_CLI_INIT_4_Configure_Platform.png)


<br>
5) You will be prompted to create an "SSH key pair". Enter `y`to accept. When prompted for a name, you must enter the same name that was referenced earlier in the deployment. Since we used "CSCL" earlier, it should be "cscl".

![Enter 'y' to create an SSH key pair and enter the name "cscl"](./images/EB_CLI_INIT_5_SSH_Key_Setup.png)


<br>
6) You will be prompted to enter a passphrase. Press "Enter" two times to enter a blank passphrase if you don't wish to use one. Setting a passphrase will require you to enter it whenever you attempt to connect to your server using SSH.


![Entering SSH passphrase. Setting it to <Blank> by pressing Enter twice.](./images/EB_CLI_INIT_6_SSH_Key_Passphrase.png)


<br>
7) Congrats! Your EB environment has been initialized locally. You will notice a new folder called `elasticbeanstalk` which will contain your configuration file.

![SSH key generated output showing that the initialization is complete](./images/EB_CLI_INIT_7_Finish.png)


## Creating your EB environment in AWS

Now that your configuration has been initialized. The EB CLI will use your config in `.elasticbeanstalk` and the deployment configs in `.ebextensions` to create your environment.

<br>
Making sure that you are still in the `server` directory. Run the `eb crreate` command followed by the name of the environment you are creating. You will be able to create multiple environments and also delete it later. So don't worry if you need to change the name.

![Running the "eb create production" command to create our EB environment](./images/EB_CLI_Create_1_CSCL.png)

Once you kick off the deployment, EB CLI will display the log events on your console. This can take a few minutes, so feel free to check back later.

Once finished you will be presented with the output.

![Output of entire EB deployment and successful message](./images/EB_CLI_Create_2_CSCL_Finished.png)
<br>
<br>
This deployment create the following resources:

- API Gateway: Used to proxy (pass along) your HTTP requests to your Beanstalk server. This allows you to connect using HTTPS which will allow your Frontend to call your Backend server without generating any security errors.

- EC2 Instance running MongoDB: This server is using a Bitnami Image containing MongoDB. This is where your database will live.

- Elastic Beanstalk deployment: This represents a number of resources which include an EC2 instance where your code will be running.


## Updating the Code

Whenever you are ready to update your code on AWS. Run the `eb deploy` command. You can provide an environment name if you have more than one using `eb deploy <environment name>`.

---

Next: [Setting Up Mongo](../03_Setting_Up_Mongo/README.md)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
157 changes: 157 additions & 0 deletions docs/beanstalk/03_Setting_Up_Mongo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# Configuring MongoDB

After deploying your application to AWS you will need to access your MongoDB server so that you can import your database data. First you will need to add an entry in the Security Group which can be thought as a Firewall rule and then retrieving the MongoDB credentials from the logs.

One of the easiest ways to access and manage a Mongo database is to use [MongoDB Compass](https://www.mongodb.com/try/download/compass). Download and install it and follow the instructions down below.

## Getting MongoDB Credentials

First, you will be getting your MongoDB username and password. The server imaged used to create this database server .

Follow the [instrcutions](https://docs.bitnami.com/aws/faq/get-started/find-credentials/#option-1-find-password-by-checking-the-system-log-on-the-aws-cloud-console-ec2) to learn how you can retrieve those credentials. Make sure to save that information for now. It will be necessary for later steps.

## Getting MongoDB IPs
Your MongoDB server will have two IPs. A Private one used to access it within your Virtual Private Cloud (VPC) network. The other is a Public one used to access it over the internet.

<br>
1) Make you r way to the EC2 dashboard by typing "EC2" in the search bar and selecting "EC2". You will be presented with the EC2 dashboard.

![Screenshot of EC2 dashboard](./images/Connecting_To_Mongo/MongoServer_1_EC2_Dashboard_Screen.png)


<br>
2) Click on the "Instances" link to view all of your current EC2 instances.

![Instances overview screen](./images/Connecting_To_Mongo/MongoServer_2_EC2_Dashboard_Select_Instances.png)


<br>
3) On this screen you will see all of your instances. There should only be two at the moment. One for MongoDB and one for Elastic Beanstalk.

![Instances overview screen](./images/Connecting_To_Mongo/MongoServer_3_EC2_Instances.png)


<br>
4) To the right you should see the Public IP address for your MongoDB instance. Look at the instance named "CSCL_DB". Do note this Public IP address.

![Instances overview screen with highlited public IP address](./images/Connecting_To_Mongo/MongoServer_4_EC2_Get_Public_IP.png)


<br>
5) Click on the "Instance ID" of the "CSCL_DB" instance to go to the Instance Profile screen. Here you will see lots of information about your instance, including monitoring metrics. Do note the Private IP address.

![CSCL_DB instance profile screen. Highlighted private IP address](./images/Connecting_To_Mongo/MongoServer_5_EC2_Get_Private_IP.png)

## Granting Access to MongoDB Server From Current IP
Now that you have the IP addresses of your MongoDB server. You will need to open up a port so that you can access it from your local machine.

<br>
1) First you will need to click the "Security Group" link in the left-side menu.

![EC2 Dashboard highlighting "Security Groups" in left side menu](./images/Connecting_To_Mongo/sg_add_current_ip_for_Mongo_1_select_sg.png)



<br>
2) On this screen you will see all of your current Security Groups. Locate the one with a description of "Lock MongoDB down to webserver access" and click the "Security Group ID" link.

![Security Groups dashboard highlighting "Lock MongoDB down to webserver access" description of MongoDB SG](./images/Connecting_To_Mongo/sg_add_current_ip_for_Mongo_2_locate_mongo_sg.png)


<br>
3) On this screen you will see information about the Security Group associated with the MongoDB server. You should only see a single Inbound rule and an unrestricted Outbound rule. Click the "Edit Inbound Rule" button.

![Highlighted the "Edit Inbound Rule" button on the Security Group overview screen](./images/Connecting_To_Mongo/sg_add_current_ip_for_Mongo_3_sg_profile_screen.png)



<br>
4) On this screen you will be able to add and remove rules. You will only need to add a single rule to grant yourself access to the Mongo Server.

![Highlighting "Add rule" button on Security Groups Inbound Rules screen](./images/Connecting_To_Mongo/sg_add_current_ip_for_Mongo_4_add_new_rule.png)


<br>
5) For the Type select "Custom TCP". For the "Port Range" enter "27017". For the source, select "My IP" which should populate the next field with your current IP address. Feel free to add a description if you wish.

![EC2 Dashboard highlighting "Security Groups" in left side menu](./images/Connecting_To_Mongo/sg_add_current_ip_for_Mongo_5_select_myip.png)


<br>
6) Once your new rule has been added, click "Save Rules"

![EC2 Dashboard highlighting "Security Groups" in left side menu](./images/Connecting_To_Mongo/sg_add_current_ip_for_Mongo_6_IP_added.png)


<br>
7) You will be taken to the Secrurity Group page where you can review all the Inbound rules again.

![EC2 Dashboard highlighting "Security Groups" in left side menu](./images/Connecting_To_Mongo/sg_add_current_ip_for_Mongo_7_summary.png)


<br>
At this point, your MongoDB server will be accessible from your current IP address and the Elastic Beanstalk server. If you are using a VPN or public IP, remember to remove access as soon as you are done.

## Constructing the MongoDB Connection String

Now that we have the database credentials, the private and public ip address of your MongoDB server, you can create the connection strings. Use the following template to construct your connection strings, one will be used to access the database from your local machine and the other from the EB server.

Public Connection String:
```
mongodb://<username>:<password>@<publicIP>/admin
```

Private Connection String (used by your backend server):
```
mongodb://<username>:<password>@<privateIp>/cscl?authSource=admin
```
*Note that "cscl" in the Private connection string is the name of your database. Update the connection string accordingly if you are using a different database.*

## Connecting to MongoDB Using MongoDB Compass and Importing Your Data
Now that you have network access to the database, you can use MongoDB Compass to connect to it and import your data.

<br>
1) In MongoDB Compass click "New Connection" and enter the "Public Connection String" you created earlier in the text field then click "CONNECT".

![MongoDB Compass connection creation screen with Public Connection String](./images/Mongo_Compass/1_Mongo_Compass_connect_to_server.png)


<br>
2) Once logged in you will be presented with the current databases on your MongoDB server. Click the "CREATE DATABASE" button at the top to create a new database.

![MongoDB Compass Databases screen listing all current databases](./images/Mongo_Compass/2_Mongo_Compass_create_db_screen.png)


<br>
3) On this form, enter the desired database name. For these instructions "cscl" will be used for the database. "items" will be used for the collection name. Click "Create Database" once done.

![MongoDB Compass create database form with "csc" database and "items" collection](./images/Mongo_Compass/3_Mongo_Compass_creating_database_and_collection.png)


<br>
4) Once your database is created you will be presented with the list of all databases. Select the database you created, i.e. "cscl".

![MongoDB Compass databases list with "cscl" highligthed](./images/Mongo_Compass/4_Mongo_Compass_select_database.png)


<br>
5) Select the collection that you created under your database, i.e. "items"

![MongoDB Compass collections list for "cscl" database with "items" highlighted](./images/Mongo_Compass/5_Mongo_Compass_select_collection.png)


<br>
6) Click the "ADD DATA" button in the upper-left, and select "Import File".

![MongoDB](./images/Mongo_Compass/6_Mongo_Compass_import_file_button.png)


<br>
7) Select the JSON file provided to you in the ![template repository](https://github.com/Hack-Diversity/template-mini-project-db) or your own MongoDB backup. Enable the Options that you would like, and click "IMPORT".

![MongoDB](./images/Mongo_Compass/7_Mongo_Compass_import_file_submit.png)

---
Congrats! You now have loaded data into your Mongo database in the cloud. Feel free to remove your IP address entry from the Security Group to remove access to your Database server.

Next: [Connecting the Backend to MongoDB](../04_Connecting_Backend_to_Mongo)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions docs/beanstalk/04_Connecting_Backend_to_Mongo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Connecting The Backend to MongoDB
You will now update your backend server so it will be able to connect to the MongoDB server. This will be achieved by providing a connection string using an Environment Variable.
Here is an helpful [video](https://www.youtube.com/watch?v=ADh_OFBfdEE) explaining what Environment Variables are.

## Updating Your Backend Environment

Retrieve the Private IP connection string you created in the previous sections. Make sure that you are in the `server` directory and use the `eb setenv` command to update your backend server's environment variables. Note that you can use `eb list` to view the available environments.

The format is:
```shell
MONGO_CONNECTION_STRING=<PRIVATE_CONNECTION_STRING> -e <EB_ENVIRONMENT>
```

![eb list and eb setenv commands on the terminal](./images/ebcli_setting_mongo_conn_string.png)

---

Once deployed, your backend server will be able to connect to your MongoDB Database.

Next: [Wrapping Up](../05_Wrapping_Up/README.md)
47 changes: 47 additions & 0 deletions docs/beanstalk/05_Wrapping_Up/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Wrapping UP
Congrats for making it this far, you're almost all set up and ready to fully deploy your app. You will now be retrieving your backend's Gateway URL which will be used in your Frontend environment to fetch, create and update data using your API.

## Getting Your API URL
<br>
1) In the AWS console, search for "API Gateway" and click "API Gateway".

![AWS console search for "API Gateway"](./images/1_API_Gateway_Menu_Selection.png)


<br>
2) You should only see a single API called "CSCL-HTTPS-Proxy". Click the link to view the configuration.

![API Gateway dashboard listing current APIs](./images/2_Select_CSCL_HTTPS_Proxy.png)


<br>
3) On this screen, you will see your API Gateway's URL. This is the URL that will be used to access your API in Elastic Beanstalk.

![CSCL-HTTPS-Proxy API Gateway details page listing the URL](./images/3_Get_API_Gateway_URL.png)

## Testing
Now that you have the URL you can test it by copying it to your browser and pressing enter. You should see the response from the root (`/`) route of your API.
Also, you can test using Curl or Postman


Curl)

![Terminal with curl command to API Gateway. Printing "Hello World!"](./images/Testing_1_Curl.png)


Postman)
![Postman window showing successful call to API Gateway. Pringin "Hello World!"](./images/Testing_2_Postman.png)


## What's Next

To delete all resources created by your deployment, run the `eb terminate <environment>` command.

![eb terminate command on terminal](./images/eb_terminate_output.png)

---

Next up is to create your frontend using AWS Amplify. Make sure to note the API Gateway URL because it will be used in the Frontend deployment.

[Amplify Deployment Documentation](../../amplify/README.md)

30 changes: 30 additions & 0 deletions docs/beanstalk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Deploying The Client Using AWS Elastic Beanstalk
Elastic Beanstalk is an Amazon service which gives Developers the ability to quickly deploy an application to the cloud without having worry about complex configuration and the management of cloud resources. For the API Server (Backend) and database, this will involve using the EB CLI tool to trigger an automated deployment to create a single API server, and a Mongo database server, along with the necessary resources to get your environment up and running.

You can find more information at the [Elastic Beanstalk Product Page](https://aws.amazon.com/elasticbeanstalk/).

## Getting Started
1) Set up your AWS account. You should have received that information from a member of the Hack team.

2) Set up your GitHub account. If you're reading this, there is a good chance that you have already done that.

3) Fork this repository under your team or personal account.

## Preparing For the Deployment
A deployment is pushing a version of your code to an environment (developmernt, production, etc...). This version of your application is usually available to your end users, in this case it will be publicly available on the internet. By following the steps below, your code will be packaged and automatically deployed to AWS Elastic Beanstalk. There will be some manual steps for the initial deployment, but all subsequent deployments will only update your code..

Please follow the instructions in the linked sections below to deploy your API to AWS:

1) [Setup](./01_Getting_Started/README.md)

2) [Creating Your Elastic Beanstalk Environment](./02_Creating_EB_Environment/README.md)

3) [Setting Up Mongo](./03_Setting_Up_Mongo/README.md)

4) [Connecting Backend to Mongo](./04_Connecting_Backend_To_Mongo/README.md)

5) [Wrapping Up](./05_Wrapping_Up/README.md)


### Conclusion
Now that your app has been deployed to AWS Elastic Beanstalk, you will be able to retrieve, edit, and create data through your API over the internet. Please explore the Elastic Beanstalk dashboard for other neat features. Also, do remember to open an issue on this repository if you find any mistakes with these instructions.
Loading