Step 4: Deploy your WordPress application
Now you deploy the sample WordPress application revision you uploaded to Amazon S3. You can 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
Use the AWS CLI or the console to deploy your application revision.
To deploy your application revision (CLI)
-
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 service role ARN, call the create-deployment-group command to create a deployment group named
WordPress_DepGroup
, associated with the application namedWordPress_App
, using the Amazon EC2 tag namedCodeDeployDemo
and deployment configuration namedCodeDeployDefault.OneAtATime
:aws deploy create-deployment-group \ --application-name WordPress_App \ --deployment-group-name WordPress_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
WordPress_App
, the deployment configuration namedCodeDeployDefault.OneAtATime
, and the deployment group namedWordPress_DepGroup
, using the application revision namedWordPressApp.zip
in the bucket namedamzn-s3-demo-bucket
:aws deploy create-deployment \ --application-name WordPress_App \ --deployment-config-name CodeDeployDefault.OneAtATime \ --deployment-group-name WordPress_DepGroup \ --s3-location bucket=amzn-s3-demo-bucket,bundleType=zip,key=WordPressApp.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, 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.
-
In the list of applications, choose WordPress_App.
-
On the Deployment groups tab, choose Create deployment group.
-
In Deployment group name, enter
WordPress_DepGroup
. -
Under Deployment type, choose In-place deployment.
-
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
.Note
After you type
CodeDeployDemo
, a 1 should appear under Matching instances to confirm CodeDeploy found one matching Amazon EC2 instance. -
In Deployment configuration, choose CodeDeployDefault.OneAtATime.
-
In Service role ARN, choose the service role ARN, and then choose Create deployment group.
-
Choose Create deployment.
-
In Deployment group choose
WordPress_DepGroup
. -
Next to Repository type, choose My application is stored in Amazon S3. In Revision location, enter the location of the sample WordPress 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 WordPressApp.zip.
-
On the Overview tab, copy the value of the Link field to your clipboard.
It might look something like this:
https://s3.amazonaws.com/amzn-s3-demo-bucket/WordPressApp.zip
-
Return to the CodeDeploy console, and in Revision location, paste the Link field value.
-
If a message appears in the File type list stating the file type could not be detected, choose .zip.
-
(Optional) Type a comment in the Deployment description box.
-
Expand Deployment group overrides, and from Deployment configuration, choose CodeDeployDefault.OneAtATime.
-
Choose Start 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
WordPress_App
and the deployment group namedWordPress_DepGroup
:aws deploy list-deployments --application-name WordPress_App --deployment-group-name WordPress_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 the name of the deployment. After a deployment fails, a message that describes the reason for the failure is displayed.
-
In Instance activity, more information about the deployment 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 the one described in 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 WordPress installation is working. Use
the public DNS address of the Amazon EC2 instance, followed by /WordPress
, to view
your site 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 of
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/WordPress
When you view the site in your browser, you should see a WordPress welcome page that looks similar to the following:
![WordPress welcome page](/images/codedeploy/latest/userguide/images/WordPress-Welcome-Page-013118.png)
If your Amazon EC2 instance does not have an HTTP inbound rule added to its security group, then the WordPress welcome page does not appear. If you see a message that says the remote server is not responding, make sure the security group for your Amazon EC2 instance has the inbound rule. For more information, see Add an inbound rule that allows HTTP traffic to your Amazon Linux or RHEL Amazon EC2 instance.