On our journey of making a CI/CD pipeline on AWS with these tools, we have completed AWS CodeCommit & CodeBuild.
Next few days we'll learn these tools/services:
CodeDeploy
CodePipeline
S3
What is CodeDeploy?
- AWS CodeDeploy is a deployment service that automates application deployments to Amazon EC2 instances, on-premises instances, serverless Lambda functions, or Amazon ECS services.
CodeDeploy can deploy application content that runs on a server and is stored in Amazon S3 buckets, GitHub repositories, or Bitbucket repositories. CodeDeploy can also deploy a serverless Lambda function. You do not need to make changes to your existing code before you can use CodeDeploy.
Task-01 : Configuring dependencies with Creation of Deployment.
Read about Appspec.yaml file for CodeDeploy.
Deploy index.html file on EC2 machine using nginx
you have to setup a CodeDeploy agent in order to deploy code on EC2
Create an instance in AWS.
Clone the CodeCommit repository to the server as we saw the same in my previous blog. The repository contained an HTML web application code.
We also created a buildspec.yaml file while building our code.
Build the code in the AWS CodeBuild section in the management section and the code is deployed successfully with the application running and stored in the S3 bucket.
Now, let's navigate to the CodeDeploy section in AWS.
Create an application by providing the name and compute platform. Here we are using EC2 instance.
The application is created now. Now create a deployment group.
Before that, we need to give access to deployment to access the AWS resource for which we need to create a role in IAM. Provide all the necessary access as mentioned below.
Provide the deployment group name, and service role and enter the ARN id from the above role.
Provide the EC2 instance details in Environment configuration.
Provide the below configurations. Now, create the deployment.
A deployment group is now created.
We need to install the CodeDeploy agent on the server for which we need to write a script file with all the dependencies.
Run the script file and all the dependencies are installed now on the server.
Task-02 : Executing the code build and deployment
- Add appspec.yaml file to CodeCommit Repository and complete the deployment process.
App Spec file is required to create a bridge between the AWS CodeDeploy and EC2 instance. Create the yaml file.
Create the dependency files as well for installing and starting nginx on the server.
Make sure to change the bbuildspec.yml file so that the CodeBuild will build the appspec.yml file and transfer the artifact to S3 bucket.
Commit the code and transfer all to the CodeCommit repository.
You can view the new code files in the CodeCommit repository.
Build the project now.
Now create a deployment in the deployment group that we made previously.
Provide the S3 artifactory details. This will pull the code at the time of CodeDeploy. Then create the deployment.
Execute the deployment. But we can see the code is not getting deployed.
Create a role for giving access to EC2 instance with all the neccessary permission policies as shown below.
Now, navigate to the instance and modify the IAM role. Select the IAM role created above.
Restart the codedeploy-agent in the EC2 instance.
Finally, the Code deploy is successful.
Verify the Public IP of the instance to view the Webpage.
Thanks for reading my article. Have a nice day.
You can follow me on LinkedIn for my daily updates:- linkedin.com/in/bandan-kumar-sahoo-131412203