-
Notifications
You must be signed in to change notification settings - Fork 1
CICD Setup for EC2
Juhi edited this page May 25, 2020
·
14 revisions
Below is the process to setup continuous deployment to AWS EC2 instance with source code in github.
-
CodeDeploy Service Role -- This role gives codedeploy access to target instances (EC2 / lambda). It also provides cloudwatch, SNS access for alerts & notification
- Go to IAM roles and click on create role
- Select CodeDeploy service and CodeDeploy use case for deployment to EC2
- Add tags if required, give appropriate name and create the role
-
EC2 Role -- This role gives code deploy agent installed on EC2 instance, access to read S3 srtifacts
- To understand where S3 came into picture, we need to understand how codedeploy works. Check this page for a short brief. <>
- Create a new role selecting EC2 service with AmazonS3ReadOnlyAccess policy
- Add tags if required, give appropriate name and create the role
#!/bin/bash
# Installing CodeDeploy Agent
sudo yum update
sudo yum install ruby
# Download the agent (replace the region)
wget https://aws-codedeploy-eu-west-3.s3.eu-west-3.amazonaws.com/latest/install
chmod +x ./install
sudo ./install auto
sudo service codedeploy-agent status
The status should look something like this -- The AWS CodeDeploy agent is running with pid xxxx
Refer FAQ if you get 0 pid
- Specify source of the file / directory that needs to be synced to AWS instance
- Specify destination absolute path on the AWS instance where source needs to be synced
- Add the dependency installation script in AfterInstall
- Specify the instructions to start / reload server in AfterInstall
5. Create CodeDeploy Application
- Select EC2 / On-premises as the compute platform and create the application
- Under the created application, go to deployment groups tab
- Add a name & select IAM role #1
- Select in-place deployment for maintaining the instance (There is option to select blue-green deployment which will create new instances against a load balancer and de-register original ones)
- Select Amazon EC2 instances with default deployment settings
- For the simplest configuration, load balancing & rollbacks can be disabled
7. Create AWS CodePipeline
- In the source provider, select github with