Prerequisites
Before we get started, you need to make sure you have the following prerequisites:
- An AWS account
- An application to deploy
- A CodeDeploy deployment group
- The AWS CLI installed on your local machine
Step 1: Create an Application
First, you need to create an application in AWS CodeDeploy. You can do this using the AWS CLI with the following command:
aws deploy create-application --application-name <application-name> --compute-platform Server
This command creates an application with the specified name and specifies the compute platform as Server. You can replace <application-name>
with the name of your application.
Step 2: Create a Deployment Group
Next, you need to create a deployment group within your application. You can do this using the AWS CLI with the following command:
aws deploy create-deployment-group --application-name <application-name> --deployment-group-name <deployment-group-name> --ec2-tag-filters Key=<tag-key>,Value=<tag-value> --service-role-arn <service-role-arn>
This command creates a deployment group with the specified name and sets the EC2 instances that are part of the deployment group using the --ec2-tag-filters
parameter. You can replace <deployment-group-name>
with the name of your deployment group, <tag-key>
and <tag-value>
with the EC2 instance tag that you want to use to filter the instances, and <service-role-arn>
with the Amazon Resource Name (ARN) of the IAM role that CodeDeploy uses to perform deployments.
Step 3: Create a Revision
Next, you need to create a revision of your application to deploy. You can do this using the AWS CLI with the following command:
aws deploy create-deployment --application-name <application-name> --deployment-config-name CodeDeployDefault.AllAtOnce --deployment-group-name <deployment-group-name> --description "<description>" --file-exists-behavior OVERWRITE --revision revisionType=S3,s3Location={bucket=<bucket>,key=<key>,bundleType=zip}
This command creates a deployment of the application revision specified in the S3 bucket with the specified key. You can replace <application-name>
with the name of your application, <deployment-group-name>
with the name of your deployment group, <description>
with a description of the deployment, <bucket>
with the name of your S3 bucket, <key>
with the key of your application bundle in the S3 bucket.
Step 4: Deploy the Revision
Finally, you can deploy the revision of your application to the deployment group using the AWS CLI with the following command:
aws deploy create-deployment --application-name <application-name> --deployment-config-name CodeDeployDefault.AllAtOnce --deployment-group-name <deployment-group-name> --description "<description>" --file-exists-behavior OVERWRITE --revision revisionType=S3,s3Location={bucket=<bucket>,key=<key>,bundleType=zip}
This command deploys the revision specified in the S3 bucket with the specified key to the deployment group specified in the command. You can replace <application-name>
with the name of your application, <deployment-group-name>
with the name of your deployment group, <description>
with a description of the deployment, <bucket>
with the name of your S3 bucket, <key>
with the key of your application bundle in the S3 bucket.
And that’s it! Your application should now be deployed to the specified deployment group.
Note: You can also use the AWS Management Console