CodeCommit CodeDeploy and CodePipeline in AWS
- Create a CodeCommit repository in CodeCommit console
- git clone ssh://git-codecommit.us-west-2.amazonaws.com/v1/repos/MyDemoRepo to a Localfolder ie tmp
- Add sample code to your local cloned repository
/tmp
|-- MyDemoRepo
|-- appspec.yml
|-- index.html
|-- LICENSE.txt
|-- scripts
|-- install_dependencies
|-- start_server
|-- stop_server - Commit All the files into local Directory and the push it in to AWS Code Commit Repository
- cd /tmp/MyDemoRepo
- git add -A
- git commit -m "Add sample application files"
- git push
- Create an EC2 instance role
- Choose Create role.
- Under Select type of trusted entity, select AWS service. Under Choose a use case, select EC2, and then choose Next: Permissions.
- Search for and select the policy named AmazonEC2RoleforAWSCodeDeploy, and then choose Next: Tags.
- Choose Next: Review. Enter a name for the role (for example, EC2InstanceRole).
- Create a EC2 Instance with IAM role EC2InstanceRole and below bash script
#!/bin/bash
yum -y update
yum install -y ruby
yum install -y aws-cli
cd /home/ec2-user
aws s3 cp s3://aws-codedeploy-us-east-2/latest/install . --region us-east-2
chmod +x ./install
./install auto - Create a role that allows CodeDeploy to perform deployments
- Choose Create role.
- Under Select type of trusted entity, select AWS service. Under Choose a use case, select CodeDeploy, and then choose Next: Permissions. The AWSCodeDeployRole managed policy is already attached to the role.
- Choose Next: Tags, and Next: Review.
- Enter a name for the role (for example, CodeDeployRole), and then choose Create role.
- Create an application in CodeDeploy
- If the Applications page does not appear, on the AWS CodeDeploy menu, choose Applications.
- Choose Create application.
- In Application name, enter MyDemoApplication.
- In Compute Platform, choose EC2/On-premises.
- Choose Create application.
- Create deployment group
- In Deployment group name, enter MyDemoDeploymentGroup.
- In Service Role, choose the service role you created earlier (for example, CodeDeployRole).
- Under Deployment type, choose In-place.
- Under Environment configuration, choose Amazon EC2 Instances. In the Key field, enter Name. In the Value field, enter the name you used to tag the instance (for example, MyCodePipelineDemo).
- Under Deployment configuration, choose CodeDeployDefault.OneAtaTime.
- Under Load Balancer, make sure Enable load balancing is not selected. You do not need to set up a load balancer or choose a target group for this example.
- Expand the Advanced section. Under Alarms, if any alarms are listed, choose Ignore alarm configuration.
- Choose Create deployment group.
- To create a CodePipeline pipeline
- Choose Create pipeline.
- In Step 1: Choose pipeline settings, in Pipeline name, enter MyFirstPipeline.
- In Service role, choose New service role to allow CodePipeline to create a service role in IAM.
- Leave the settings under Advanced settings at their defaults, and then choose Next.
- In Step 2: Add source stage, in Source provider, choose AWS CodeCommit. In Repository name, choose the name of the CodeCommit repository you created in Step 1: Create a CodeCommit repository. In Branch name, choose main, and then choose Next step.
After you select the repository name and branch, a message displays the Amazon CloudWatch Events rule to be created for this pipeline. - Under Change detection options, leave the defaults. This allows CodePipeline to use Amazon CloudWatch Events to detect changes in your source repository.
- Choose Next.
- In Step 3: Add build stage, choose Skip build stage, and then accept the warning message by choosing Skip again. Choose Next.
In Step 5: Review, review the information, and then choose Create pipeline. - The pipeline starts running after it is created. It downloads the code from your CodeCommit repository and creates a CodeDeploy deployment to your EC2 instance. You can view progress and success and failure messages as the CodePipeline sample deploys the webpage to the Amazon EC2 instance in the CodeDeploy deployment.
No Comments Yet!!