Continuous Deployment using AWS
Tags: Deployment, AWS, DevOps

In this story, we will see step by step implementation of automated software deployment using AWS. We will create a pipeline using AWS CodePipeline which builds, tests, and deploys the code for every change made in the code. I have used the GitHub repository for source code. AWS Elastic Beanstalk as the deployment target for the sample app. If any changes are made to the source repository the app will automatically update the live application. Let's get started with the implementation. A list of steps to be implemented is given below.

Create a deployment environment Sample source code Create a pipeline Activate pipeline to deploy code Commit a change and update the app

A detailed explanation of the steps given below.

Create a deployment environment

Using AWS Elastic Beanstalk for setting up and configuring EC2 instances. It helps host web applications and provides needed infrastructure.

Create a new application by clicking Create Application.

Give Application name as Webapplication in the given field.

Choose PHP from the drop-down menu and then click Create application.

The environment will be ready for application deployment. It creates an Amazon EC2 instance, a security group, an Auto Scaling group, an Amazon S3 bucket, Amazon CloudWatch alarms, and a domain name for the application.

2. Sample source code

Source code is taken from the GitHub repository. The pipeline will retrieve code from GitHub and follows the deployment process. We will Fork the sample code from the below repository. Fork a copy of the repository to the GitHub account by clicking the Fork button in the upper-right corner.

https://github.com/awslabs/aws-codepipeline-s3-aws-codedeploy_linux

3. Create a pipeline

We will create and configure a pipeline for source and deploy.

Click here to open the AWS CodePipeline console.

Click Create pipeline to create a pipeline for application.

Enter the name of Pipeline as DemoPipeline and click Next step.

Select Source as GitHub(Version 1) and Connect to GitHub.

Authorize the AWS CodePipeline by clicking Authorize aws-codesuite.

After providing GitHub credentials for authorization Authentication request will be processed click Confirm after authorization.

The source stage will show the success message after authorization as below.

Provide a Repository from the dropdown and choose the repository to be used as a source for the pipeline. Here we will select aws-codepipeline-s3-aws-codedeploy_linux which we forked in the GitHub account. Select Branch as master and click Next.

We will skip the optional Add build stage.

In the Deploy provider select AWS Elastic Beanstalk. Application name to be selected as Webapplication. Select Environment name as Webapplication-env and click Next step.

4. Activate pipeline to deploy code

Once all the details look ok click Create pipeline.

As soon as we create a pipeline the pipeline automatically starts to run. It takes a while to complete the execution of the complete pipeline. We can see below the successful execution of Source.

After successful completion of execution of the Deploy stage will start and after successful execution, it will look like below.

In the status area of the Deploy stage, click AWS Elastic Beanstalk. Select the Webapplication link from the Environment name

Click URL available under Webapplication-env.

We can see the Web application successfully deployed using AWS.

5. Commit a change and update the app

Let's make some changes in code on the GitHub repository to verify automatic deployment using AWS. Open the Index.html file and click the Edit icon.

Update the file by changing the file from line no 30 as below. as click the Commit changes button.

As soon as we commit changes to the GitHub repository we can Demopipeline automatically starts the execution of the Source. In some time both Source and Deploy stage will be completed successfully

If we click the URL from the Deploy stage again we can see the changes made to the Index.html file are visible.