CodeDeploy Hands OnΒΆ
Before we start using CodeDeploy we need to create 2 new IAM roles:
A service role
When creating a role, we can choose an AWS Service as CodeDeploy and it will allow us to choose common use cases:
EC2 Service Role
Our EC2 instance must be able to pull the data from S3, so we need to add a role for that as well.
AmazonS3ReadOnlyAccess
permission is sufficient for that role.
Now we can create an CodeDeploy application.
Then we can create an EC2 instance we can deploy to. Make sure it has the EC2 Service role.
We'll also allow access from port 80.
Now we can ssh into the instance and run following commands:
$ sudo yum update
$ sudo yum install ruby
$ 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
Once the EC2 is set up we need to create a deployment group in the CodeDeploy application. Their basically a set of EC2 instances, for example, that you are going to deploy to. Like dev instances, production instances etc.
We can attach tags to our instances:
Now we fill in the deployment group form:
Now we can create a new deployment.
We can create a new S3 bucket and modify the buildspec.yml to upload the files to that S3 bucket.