Step 4: Deploy your Hello World application
Now you deploy the sample Hello World application revision you uploaded to Amazon S3. You use the AWS CLI or the CodeDeploy console to deploy the revision and monitor the deployment's progress. After the application revision is successfully deployed, you check the results.
Topics
Deploy your application revision with CodeDeploy
You can deploy your application using the CLI or the console.
To deploy your application revision (CLI)
-
First, the deployment needs a deployment group. However, before you create the deployment group, you need a service role ARN. A service role is an IAM role that gives a service permission to act on your behalf. In this case, the service role gives CodeDeploy permission to access your Amazon EC2 instances to expand (read) their Amazon EC2 instance tags.
You should have already followed the instructions in Create a service role (CLI) to create a service role. To get the ARN of the service role, see Get the service role ARN (CLI) .
-
Now that you have the ARN, call the create-deployment-group command to create a deployment group named
HelloWorld_DepGroup
, associated with the application namedHelloWorld_App
, using the Amazon EC2 instance tag namedCodeDeployDemo
and deployment configuration namedCodeDeployDefault.OneAtATime
, with the service role ARN:aws deploy create-deployment-group --application-name HelloWorld_App --deployment-group-name HelloWorld_DepGroup --deployment-config-name CodeDeployDefault.OneAtATime --ec2-tag-filters Key=Name,Value=CodeDeployDemo,Type=KEY_AND_VALUE --service-role-arn
serviceRoleARN
Note
The create-deployment-group command provides support for creating triggers that result in the sending of Amazon SNS notifications to topic subscribers about specified events in deployments and instances. The command also supports options for automatically rolling back deployments and setting up alarms to stop deployments when monitoring thresholds in Amazon CloudWatch alarms are met. Commands for these actions are not included in this tutorial.
-
Before you create a deployment, the instances in your deployment group must have the CodeDeploy agent installed. You can install the agent from the command line with AWS Systems Manager with the following command:
aws ssm create-association --name AWS-ConfigureAWSPackage --targets Key=tag:Name,Values=CodeDeployDemo --parameters action=Install,name=AWSCodeDeployAgent --schedule-expression "cron(0 2 ? * SUN *)"
This command creates an association in Systems Manager State Manager that will install the CodeDeploy agent and then attempt to update it at 2:00 every Sunday morning. For more information about the CodeDeploy agent, see Working with the CodeDeploy agent. For more information about Systems Manager, see What is AWS Systems Manager.
-
Now call the create-deployment command to create a deployment associated with the application named
HelloWorld_App
, the deployment configuration namedCodeDeployDefault.OneAtATime
, and the deployment group namedHelloWorld_DepGroup
, using the application revision namedHelloWorld_App.zip
in the bucket namedamzn-s3-demo-bucket
:aws deploy create-deployment --application-name HelloWorld_App --deployment-config-name CodeDeployDefault.OneAtATime --deployment-group-name HelloWorld_DepGroup --s3-location bucket=amzn-s3-demo-bucket,bundleType=zip,key=HelloWorld_App.zip
To deploy your application revision (console)
-
Before you use the CodeDeploy console to deploy your application revision, you need a service role ARN. A service role is an IAM role that gives a service permission to act on your behalf. In this case, the service role gives CodeDeploy permission to access your Amazon EC2 instances to expand (read) their Amazon EC2 instance tags.
You should have already followed the instructions in Create a service role (console) to create a service role. To get the ARN of the service role, see Get the service role ARN (console) .
-
Now that you have the ARN, you can use the CodeDeploy console to deploy your application revision.
Sign in to the AWS Management Console and open the CodeDeploy console at https://console.aws.amazon.com/codedeploy
. Note
Sign in with the same user that you set up in Getting started with CodeDeploy.
In the navigation pane, expand Deploy, then choose Applications.
-
Choose HelloWorld_App.
-
On the Deployment groups tab, choose Create deployment group.
-
In Deployment group name, enter
HelloWorld_DepGroup
. -
In Service Role, choose the name of the service role.
-
In Deployment type, choose In-place.
-
In Environment configuration, select Amazon EC2 instances.
-
In Agent configuration with AWS Systems Manager, keep the defaults.
-
In Key, enter
Name
. -
In Value, enter
CodeDeployDemo
. -
In Deployment configuration, choose CodeDeployDefault.OneAtATime.
-
In Load Balancer, clear Enable load balancing.
-
Choose Create deployment group.
-
Choose Create deployment.
-
In Deployment group, choose HelloWorld_DepGroup
-
In Revision type, choose My application is stored in Amazon S3, and then in Revision location, enter the location of the sample Hello World application revision you previously uploaded to Amazon S3. To get the location:
Open the Amazon S3 console at https://console.aws.amazon.com/s3/
. -
In the list of buckets, choose amzn-s3-demo-bucket (or the name of the bucket where you uploaded your application revision).
-
In the list of objects, choose HelloWorld_App.zip.
-
In the Overview tab, choose Copy path.
-
Return to the CodeDeploy console, and in Revision Location, paste the Link field value.
-
For Revision file type, choose .zip.
-
(Optional) Enter a comment in Deployment description.
-
Choose Create deployment. Information about your newly created deployment appears on the Deployments page.
Monitor and troubleshoot your deployment
Use the AWS CLI or the console to monitor and troubleshoot your deployment.
Topics
To monitor and troubleshoot your deployment (CLI)
-
Get the deployment's ID by calling the list-deployments command against the application named
HelloWorld_App
and the deployment group namedHelloWorld_DepGroup
:aws deploy list-deployments --application-name HelloWorld_App --deployment-group-name HelloWorld_DepGroup --query "deployments" --output text
-
Call the get-deployment command with the deployment ID:
aws deploy get-deployment --deployment-id
deploymentID
--query "deploymentInfo.status" --output text -
The command returns the deployment's overall status. If successful, the value is
Succeeded
.If the overall status is
Failed
, you can call commands such as list-deployment-instances and get-deployment-instance to troubleshoot. For more troubleshooting options, see Analyzing log files to investigate deployment failures on instances.
To monitor and troubleshoot your deployment (console)
On the Deployments page in the CodeDeploy console, you can monitor your deployment's status in the Status column.
To get more information about your deployment, especially if the Status column value has any value other than Succeeded:
-
In the Deployments table, choose your deployment ID. After a deployment fails, a message that describes the reason for the failure appears in the deployment's details page.
-
. More information about the deployment's instances is displayed. After a deployment fails, you might be able to determine on which Amazon EC2 instances and at which step the deployment failed.
-
If you want to do more troubleshooting, you can use a technique like View Instance Details. You can also analyze the deployment log files on an Amazon EC2 instance. For more information, see Analyzing log files to investigate deployment failures on instances.
Verify your deployment
After your deployment is successful, verify your installation is working. Use the public DNS address of the Amazon EC2 instance to view the web page in a web browser. (To get the public DNS value, in the Amazon EC2 console, choose the Amazon EC2 instance, and on the Description tab, look for the value in Public DNS.)
For example, if the public DNS address of your Amazon EC2 instance is
ec2-01-234-567-890.compute-1.amazonaws.com
, you would use the following URL:
http://ec2-01-234-567-890.compute-1.amazonaws.com
If successful, you should see a Hello World webpage.