Project Deployment on AWS with CI/CD and GitHub

Ashish Pratap Singh
5 min readNov 25, 2020

In this article we will see how to successfully deploy a Python project on AWS using CI/CD pipeline, GitHub, Elastic Beanstalk and configure it with EC2 Instance.

GitHub CI/CD Pipeline with AWS Elastic Beanstalk

To extent this, I have outlined below the necessary five steps to deploy Flask application in AWS:

1: Create Flask Application
2: Create an IAM user on AWS
3: Create Elastic Beanstalk Application
4: Create S3 Bucket on AWS
5: Create Private Repository on GitHub
6: configure EC2 private IP with Elastic Beanstalk application

START:

1: Create Flask Application
Create a Flask Application and run it locally before moving on next step. You can also Visit here to see how to give a folder structure for a web development.

Folder Structure
Flask Folder Structure

2: Create an IAM user on AWS
To configure the Flask Project on AWS, we need access_key_id and secret_access_key from Identity and Access Management(IAM) in AWS.
Click here to create IAM user on AWS, choose Attach existing policies directly while setting permissions and search permission for AmazonS3FullAccess and AWSElasticBeanstalkFullAccess.

3: Create Elastic Beanstalk Application
To deploy this Flask application we need to create an Elastic Beanstalk application, follow below steps to create Elastic Beanstalk application:
a) Click here to redirect on the AWS Elastic Beanstalk page and Click on Create a new environment.

Create an Elastic Beanstalk Environment

b) Select Web server Environment to Run a website, web application, or web API that serves HTTP requests and click on Select.

c) Fill the details for the selected web server environment:
i) Application Information: Enter Elastic Beanstalk application name and you environment will created automatically you can edit it if you need.
ii) Platform: Choose your language platform like Python, node, go. In my case I’ll select Python for my project.
iii) Application Code: Select Sample Application and click on Create Environment it’ll take few minutes ( hardly 5–10min) to create and start your Elastic Beanstalk environment application.
iv) It’ll automatically create an environment in EC2 instance with Elastic Beanstalk environment name, later we’ll configure EC2 private IP with Elastic Beanstalk application.

Application Name
Application Environment Name
Choose your Platform
Select Sample application for Deployment purpose
It’ll take few minutes
Elastic Beanstalk environment created

After created environment click on the environment link and page looks like this

4: Create S3 Bucket on AWS
We need to create a s3 Bucket to store the zip file that will create in GitHub while CI/CD pipeline processing start.
follow necessary steps to create S3 Bucket:
a) Click here to redirect on AWS S3 Bucket page and click on Create Bucket.
b) Enter Bucket name and click on Create Bucket.
Note: Created Bucket Access field is Bucket and objects not public

5: Create Private Repository on GitHub
Create a private GitHub Repository.
Follow necessary steps to configure GitHub with AWS.
a) Push your code in this private repository.
b) Go on the Settings Tab and select Secrets from left nav-bar, from Secrets click on New repository secret to add new secrets field in this private repository.

from Settings select Secrets to secret key of an AWS IAM user
Enter Secret Name and Value (from IAM)
After added Name and Value your screen looks like this in the Secrets fields

c) Go on the Action Tab and click on setup a workflow yourself available below the Get started with GitHub Actions.
d) a main.yml file will be created you need to edit it with such code that indicates CI and CD pipeline in the Action Tab. Click here to get main.yml file. This main.yml will be active whenever you push your code in GitHub Repo.

GitHub Action Tab click on set up a workflow yourself
a min.yml file created click here to get code

e) Commit this main.yml file and go to the Action Tab there you are able to see the CI/CD pipeline process running and after few minutes it’s affect will be shown in the AWS Elastic Beanstalk environment with Health OK. To check the effect click in the environment-url.

Successfully Deploy project on Elastic Benstalk

6: Configure EC2 private IP with Elastic Beanstalk application
Follow necessary steps to Configuring EC2 with Elastic Beanstalk.
a) Click Here to go to the Elastic Beanstalk Application page and select your application.

Elastic Beanstalk Applications List
Single Elastic Beanstalk Environment
Status of Elastic Beanstalk

b) Click on the Configuration tab from left nav-bar and Edit instances

Edit the Instances

c) From EC2 Security Group check the both field with the same name of your environment and click on Apply.

Check both field having same environment name

Conclusion

This is kind of the successfully deployment of any project on AWS with CI/CD pipeline through GitHub . If you liked this article, feel free to give it a clap or two and if you have any questions or queries, please leave them in the comments below.

Thank You. :)

--

--