AWS CodeDeploy automates your software deployments, allowing for reliable and rapid deployment. CodeDeploy can be used to deploy the application to Amazon EC2, AWS Fargate, AWS Lambda, or your on-premises servers.
There is no additional charge for using CodeDeploy to deploy on AWS services – EC2, Lambda, Fargate. There is an additional charge when CodeDeploy is used to deploy the application on an on-premise server.
Once you sign in to AWS, start by selecting CodeDeploy under Services.

Under CodeDeploy, Select Applications -> Create Application.

Enter the Application Name and select compute platform drop-down. This will be EC2/On-premise.

Once you created an Application, from the Applications dashboard, click on the Application and select Create Deployment Group.

For Create Deployment Group, enter the information in the form. An example is shown below

The tag used is specified by us in the EC2 section.

Now, once the deployment group is created successfully, click on create deployment. This step is required to grant CodeDeploy access the GitHub Repo.

Select My application is stored in Github. Give it a name, and select Connect to GitHub.

This opens up another tab where you might need to login to GitHub again and grant access.

Once you do the above, exit the window. There is no need to click on the Create Deployment button. We will trigger the deployment from GitHub.
If this is the first time that the organization is linking CodeDeploy to GitHub, there are additional steps that need to be performed on GitHub.
Go to the GitHub Setting page.

Under your personal account, go to Applications, Authorized OAuth Apps tab.

Click on the Application you want to grant organization access to. Click on Grant organization access. You can only do this if your GitHub admin has created a role which allows you grant permissions to third-party applications. If not, contact your administrator.

You can confirm the permissions by clicking on the Third-party access of your organization.

Finally, add your AWS user credentials with permission to access CodeDeploy to GitHub Secrets.
CodeDeploy deploys the application in 7 different stages. At each stage, you need to provide a script. For our mock services these sit under the scripts/ folder in our GitHub (see link at end of blog). The appspec.yml file is needed to specify the location of the scripts. This file also includes the source and the destination of the executable. For this example, ApplicationStart.sh has the following information: