Menu
AWS for DevOps
Getting Started Guide

Step 4: Set Up for AWS CodeDeploy

In this step, you will create AWS resources that AWS CodeDeploy will use to deploy the source code to the deployment target (an Amazon EC2 instance running Amazon Linux).

If you want to deploy with AWS Elastic Beanstalk, go to Step 5: Elastic Beanstalk Setup.

If you want to deploy with AWS OpsWorks, go to Step 6: AWS OpsWorks Setup.

To log in to and explore the deployment target, you will need an Amazon EC2 key pair. You can use the key pair you created or identified in Step 2.2: Create a Key Pair.

The following procedure uses an AWS CloudFormation template to create an AWS CodeDeploy application, deployment group, service role, and an IAM instance profile, and to launch an Amazon Linux instance. (To view the contents of the AWS CloudFormation template, see CodeDeploySetup.template.) To learn how to create these resources in other ways, such as with the AWS Management Console or the AWS Command Line Interface (AWS CLI), see the following topics in the AWS CodeDeploy User Guide:

To create the AWS CodeDeploy resources

  1. Use the AWS CloudFormation console to create a stack in the US East (N. Virginia) region based on the following Amazon S3 template URL: https://s3.amazonaws.com/aws-for-devops/cfn-templates/CodeDeploySetup.template

    On the Specify Details page, the setttings in the Parameters area are used to:

    • Create an AWS CodeDeploy default service role and IAM instance profile. The service role enables AWS CodeDeploy to interact with dependent AWS services on the user's behalf. The IAM instance profile enables associated Amazon EC2 instances to interact with dependent AWS services.

    • Create an AWS CodeDeploy application and deployment group, and associate the new service role with the new deployment group.

    • Launch an Amazon EC2 instance running Amazon Linux and install the AWS CodeDeploy agent on the instance. This instance allows users to log in to it by using the SSH protocol and to access it by using the HTTP protocol. The new instance profile is attached to the instance.

    To accept these default settings, type your Amazon EC2 key pair name (for example, the one you created in Step 2.2: Create a Key Pair) into KeyPair, and then go to step 2 of this procedure.

    Alternatively, you may want to experiment with these default settings by running this template multiple times to create AWS CodeDeploy, IAM, and Amazon EC2 resources for this walkthrough. For example, later on you may want to create more AWS CodeDeploy deployment groups or launch more Amazon Linux instances that are compatible with AWS CodeDeploy.

    The following table shows which settings to choose in the Parameters area.

    I want to create a new AWS CodeDeploy application.

    Leave Application set to the default value of New. For ApplicationName, type the name for the new application.

    Note

    Set Application to Skip if you only want to create a new AWS CodeDeploy service role, instance profile, or instance.

    I want to create a new AWS CodeDeploy deployment group.

    Leave DeploymentGroup set to the default value of New. For DeploymentGroupName, type the name of the new application.

    A deployment group must be associated with an application. Set Application to New or Existing, and in ApplicationName, type the name of the new or existing AWS CodeDeploy application to associate it with the new deployment group.

    A deployment group must have an Amazon EC2 tag filter key and value so that AWS CodeDeploy knows which instances to deploy to. Type the key in TagKey, and type the value in TagValue.

    A deployment group must have an AWS CodeDeploy service role. Set ServiceRole to New to create a new service role and associate it with the new deployment group, or set it to Existing to associate an existing service with the new deployment group. If you choose Existing, type the Amazon Resource Name (ARN) of the service role in ServiceRoleARN.

    Note

    Set DeploymentGroup to Skip if you only want to create a new AWS CodeDeploy service role, instance profile, or instance.

    I want to create a new AWS CodeDeploy service role.

    Leave ServiceRole set to the default value of New.

    Note

    Set ServiceRole to Skip if you only want to launch a new Amazon Linux instance that is compatible with AWS CodeDeploy.

    If you choose Existing and specify the service role's ARN in ServiceRoleARN, the service role must be compatible with AWS CodeDeploy. For more information, see Step 3: Create a Service Role for AWS CodeDeploy in the AWS CodeDeploy User Guide.

    I want to launch a new Amazon Linux instance that is compatible with AWS CodeDeploy.

    Leave CreateInstance set to the default value of New.

    For InstanceType, type the value of the Amazon EC2 instance type to launch.

    For TagKey, type the Amazon EC2 tag filter key to associate with the instance.

    For TagValue, type Amazon EC2 tag filter value to associate with the instance.

    For KeyPair, type the name of the existing Amazon EC2 key pair you will use to log in to the launched instance.

    For InstanceProfile, if you choose Existing, type the name (not ARN) of the IAM instance profile in InstanceProfileName. The IAM instance profile must be compatible with AWS CodeDeploy. For more information, see Step 4: Create an IAM Instance Profile for Your Amazon EC2 Instances in the AWS CodeDeploy User Guide.

  2. When CREATE_COMPLETE is displayed for Status for the stack, you can view the resources created by the stack. Otherwise, go to Step 7.1: Create and Run the Pipeline for AWS CodeDeploy.

To explore the AWS CodeDeploy resources created by the stack

  1. Open the AWS CodeDeploy console at https://console.aws.amazon.com/codedeploy/.

  2. In the AWS region selector, choose US East (N. Virginia).

  3. On the Applications page, choose the AWS CodeDeploy application.

  4. On the Application details page, in the Deployment groups area, expand the deployment group's name.

To explore the IAM resources created by the stack

  1. In the AWS CloudFormation console, choose the Resources tab for the stack.

  2. If you created an IAM instance profile, for CodeDeployInstanceProfileRole, choose the Physical ID link.

  3. If you created a service role, for CodeDeployServiceRole, choose the Physical ID link.

To explore the Amazon EC2 resources created by the stack

  1. In the AWS CloudFormation console, choose the Resources tab for the stack.

  2. If you launched an instance, for CodeDeployInstance, choose the Physical ID link to view details about the instance.

  3. To view details about the security group for the launched instance, in the Amazon EC2 console, on the Description tab for the instance, choose the Security groups link.

  4. To log in to the launched instance, follow the instructions in Connect to Your Linux Instance in the Amazon EC2 User Guide for Linux Instances.

  5. To confirm the AWS CodeDeploy agent is running on the launched instance, log in to the instance and then run the sudo service codedeploy-agent status command. If the agent is running, the output should start with The AWS CodeDeploy agent is running.

  6. Go to Step 7.1: Create and Run the Pipeline for AWS CodeDeploy.