- This is the project developed as part of the AWS course. The project is a simple Travel Guide application that gives information about various travel destinations.
- It utilizes various AWS services under free-tier limits, making it beginner-friendly.
- We faced a lot of challenges during development and deployment, so we've documented everything in detail to help others who might run into similar issues.
- It is second version of the project:
- This version is more advanced and includes additional features and services than previous beginner version.
- Project Details
- Steps to run
- To make changes
- Steps to deploy
- Important Instructions
- Cleanup
- Contributions
- License
- Contact
- Build a simple Travel Guide app that provides destination info using AWS services.
- Demonstrate how to easily deploy a project using common AWS components.
- Add some dynamic content than simple application.
- Integrate multiple free tier AWS services in a single project.
- Responsive web UI that works well on different screen sizes.
- Utilization of AWS services for compute, authentication, storage, translation, and email notifications.
- The project is not meant for real-world use or as an impactful solution. Its main purpose is to demonstrate how different AWS services can be used together in a beginner-friendly setup.
- So, following strict best practices or writing production-ready code wasn't the main focus.
To run the project locally on your device first, follow these steps:
-
Create fork of the repository:
- Click on the
Forkbutton at the top right corner of this page to create a copy of the repository in your GitHub account. - This will also help to easily deploy the project on AWS later.
- Now, you have your own copy of the project repository in your GitHub account.
- Click on the
-
Clone the repository from your GitHub account:
# Replace the <your-username> with your GitHub username git clone https://github.com/<your-username>/aws_advanced_project.git cd aws_advanced_project
-
Create a virtual environment and install the required packages:
# Create virtual environment python -m venv venv # Activate virtual environment (Windows): ./venv/Scripts/activate # Linux: source venv/bin/activate # Install required packages pip install -r requirements.txt
-
Set up environment variables:
- Copy the
.env.examplefile to.envfile and fill in the required values in the.envfile. - For the env variables, you first need to setup various AWS services, that part is covered in deployment section.
- Copy the
-
Run the Flask application:
python app.py
-
Now, server is live and project can be accessed at
http://localhost:5000/in your browser. -
You can make any changes in the code files and push them to your GitHub repository.
Caution
Avoid doing anything un-necessary in the AWS console, unless you know what you are doing.
It can lead to unexpected charges on your AWS account.
Don't forget to stop or terminate the resources after you are done with the project.
More details are here in Important Instructions and Cleanup sections.
- Assuming that you have already created a fork of the repository and cloned it to your local machine.
- If you have made any changes to the code, make sure to commit and push those changes to GitHub (to your own version of the project).
- Some files like
.envare git-ignored and hence, need to be updated manually on the EC2 instance later. See this section for more details.
Tip
AWS resources can be used across various regions.
Make sure that you always select the same region for all the resources you create, to avoid any issues later. (Regions are visible in the top right corner of the AWS console.)
Default region is us-east-1, so you can use that for all the resources.
- To serve our application, we need a compute instance that can run the Flask application.
- But, before setting up the EC2 instance, we need to create a security group that allows incoming traffic on port 5000 (or any other port you want to use).
- Follow these steps to create a security group:
- Go to the AWS Console and log in to your AWS account.
- Navigate to the EC2 service. (You can search for "EC2" in the search bar.)
- In the left sidebar, click on Security Groups under Network & Security.
- Click on the Create security group button.
- Name your security group something like
travel-guide-sgand a description likeSecurity group for travel guide application. - Under Inbound rules, click on Add rule. Add the following rules:
Sr Type Protocol Port Range Source Explanation 1 Custom TCP Rule TCP 5000 Anywhere-IPv4 Allow incoming traffic on port 5000 for the Flask application 2 MySQL/Aurora TCP 3306 Anywhere-IPv4 Allow incoming traffic on port 3306 for RDS MySQL database 3 SSH TCP 22 My IP (or Anywhere-IPv4) Allow incoming traffic on port 22 for SSH access - Under Outbound rules, by default all traffic protocols and destinations are allowed. You can leave it as it is.
- Now, you have a security group that allows incoming traffic on port 5000 from anywhere (IPv4).
- And, allowing SSH on port 22 also allows you to use SFTP if needed. Instead of My IP, you can also select Anywhere-IPv4 for SSH rule if facing issues.
- You can also add rules for IPv6 if you want to allow traffic from IPv6 addresses as well.
- In the project code files, static assets are served from the EC2 instance itself.
- Optionally, you can use S3 to serve the static assets.
- Make the below mentioned changes first:
- Uncomment the S3 bucket code in the
static/script.jsandtemplates/place_detail.html. - Comment out the flask serve static code at same places.
- Fill in the S3 URL in the env variable file.
- Uncomment the S3 bucket code in the
- From AWS Console, navigate to the S3 service, and create a new S3 bucket:
- Name you bucket something like
travel-guide-project(or any unique name) - Other settings can be left as default.
- Block Public Access settings for this bucket section and uncheck the Block all public access option. Acknowledge the warning and click on Create bucket button.
- Add
Bucket Policyto allow public access to the bucket, [Your bucket > Permissions tab > Bucket policy > Edit]:{ "Version": "2012-10-17", "Statement": [ { "Sid": "PublicReadGetObject", "Effect": "Allow", "Principal": "*", "Action": "s3:GetObject", "Resource": "arn:aws:s3:::travel-guide-project/*" } ] } - Make sure you replace
travel-guide-projectwith your actual bucket name in the above policy. - Click on Save changes.
- Name you bucket something like
- Now, you can add all the assets from static/images directory to the S3 bucket using same file upload method.
- Now, we can set up an EC2 instance to run our Flask application.
- Go to AWS Console > EC2 service > Instances (left sidebar) > Launch Instances button.
- These are some recommended settings, but you can change them as per your requirements:
- Names and tags: Enter some name for the instance, like
travel-guide-server. - Application and OS Images: Amazon Linux.
- Instance Type:
- Select t2.micro or any free tier eligible instance type.
- Our project is lightweight and can run on any minimum configuration instance.
- Key Pair (login):
- Create a new key pair, with any name like
travel-guide-key. - Rest can be left as default. Create key and save downloaded
.pemfile securely. - We need it in order to access the instance via SSH.
- Create a new key pair, with any name like
- Network Settings:
- Under firewall settings, you will see the security group section.
- Click on Select an existing security group and select the security group you created earlier (
travel-guide-sg).
- Configure Storage: You can leave the default settings as they are.
- Click on Launch Instances button to launch the instance.
- Names and tags: Enter some name for the instance, like
- After the instance is launched, you can see the success message with the instance ID (i-xxxxxx).
- Now the instance can be checked in the Instances section in the left sidebar of the EC2 service page.
- Our project uses a MySQL database to store the destination data.
- Go to AWS Console > Aurora and RDS > Databases (left sidebar) > Create database button.
- These are some recommended settings, but you can change them as per your requirements:
- Database creation method: Standard Create.
- Engine type: MySQL.
- Templates: Free tier.
- Availability & durability: Single AZ deployment (1 instance).
- DB instance identifier:
travel-guide-db(or any name you want). - Master username:
admin(or any username you want). - Master password: Set a strong password and remember it, we will need it later.
- DB instance size: db.t2.micro (any free tier eligible).
- Storage: Leave default settings as they are.
- Connectivity:
- Virtual Private Cloud (VPC): Default VPC.
- Public access: Yes.
- VPC security groups: Choose existing and select the security group you created earlier (
travel-guide-sg).
- Click on Create database button to create the RDS instance.
- After the database is created, it will take some time to be available.
- Once the status changes to
Available, click on the database name to see the details. - Note down the Endpoint value, we will need it to connect to the database from our Flask application.
- It will be something like
<name>.<id>.<zone>.rds.amazonaws.com.
- Will add this soon...
Finally, we can deploy the Flask application on the EC2 instance.
-
Connect to the EC2 instance:
- AWS Console > EC2 service > Instances > Your instance > Connect.
- Or use ssh to connect from your terminal:
ssh -i /path/to/your-key.pem ec2-user@<your-ec2-public-ip>
- Run the following commands:
# Update the package manager sudo yum update -y # Install Python 3 and git sudo yum install python3 git -y
-
Clone the project repository:
- Run the following command to clone the project repository:
git clone https://github.com/<your-username>/aws_advanced_project.git cd aws_beginner_project
- If you want to use S3, make sure that updated code files are already pushed to your GitHub repository.
- Run the following command to clone the project repository:
-
Install the required packages in virtual environment:
python3 -m venv venv source venv/bin/activate pip install -r requirements.txt -
Set up environment variables:
- We need to create a
.envfile on the EC2 instance with all the required environment variables. - First make copy of the
.env.examplefile:cp .env.example .env
- Now, using
nanoorvim, open the.envfile and fill in the required values:sudo nano .env # Save and exit (in nano: Ctrl+O, Enter, Ctrl+X)
- We need to create a
-
Run the Flask application:
python app.py &
-
Free-tier limits: Make sure to stay within the free-tier limits of AWS services to avoid unexpected charges.
-
Instance type: Use only
free-tier eligibleinstance types liket2.microto avoid charges. -
Stop vs Terminate EC2:
- Stop: Stopping the instance will not delete it, and you will still be charged for the EBS volume attached to it.
- Terminate: Terminating the instance will delete it and you will not be charged for the instance or the EBS volume.
-
Region:
- Make sure to select the same region for all AWS services to avoid any billing surprises.
- It is visible in the top right corner of the AWS console.
-
Billing alerts:
- Set up billing alerts in the AWS console to get notified if your usage exceeds the free-tier limits.
- You can do this by going to the Billing and Cost Management section in the AWS console and setting up a budget.
-
RDS
- Avoid turning on RDS Backups, or make sure to delete the backups after you are done with the project.
- Also delete the RDS Subnet Group created for the RDS instance, if you created one.
|
|
|
| Bhushan Songire | Ujjawal Kumar |
- If you want to contribute to this project, please feel free to fork the repository and create a pull request.
- Project is licensed under the GNU General Public License v3.0 (GPL-3.0).
- See the LICENSE file for details.
- You are allowed to use code with same license and proper attribution to the original author(s).
- Email : bhushanbsongire@gmail.com
- Email : Ujjawal