Menu
AWS CodeDeploy
User Guide (API Version 2014-10-06)

Create an Amazon EC2 Instance for AWS CodeDeploy (AWS CloudFormation Template)

You can use our AWS CloudFormation template to quickly launch an Amazon EC2 instance running Amazon Linux or Windows Server. You can use the AWS CLI, the AWS CodeDeploy console, or the AWS APIs to launch the instance with the template. In addition to launching the instance, the template does the following:

  • Instructs AWS CloudFormation to give the instance permission to participate in AWS CodeDeploy deployments.

  • Tags the instance so AWS CodeDeploy can find it during a deployment.

  • Installs and runs the AWS CodeDeploy agent on the instance.

You don't have to use our AWS CloudFormation to set up an Amazon EC2 instance. For alternatives, see Working with Instances.

We do not provide an AWS CloudFormation template for Amazon EC2 instances running Ubuntu Server or Red Hat Enterprise Linux (RHEL).

Important

If you use the AWS CloudFormation template to launch Amazon EC2 instances, the calling IAM user must have access to AWS CloudFormation and AWS services and actions on which AWS CloudFormation depends. If you have not followed the steps in Step 1: Provision an IAM User to provision the calling IAM user, you must at least attach the following policy:

Copy
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "cloudformation:*", "codedeploy:*", "ec2:*", "iam:AddRoleToInstanceProfile", "iam:CreateInstanceProfile", "iam:CreateRole", "iam:DeleteInstanceProfile", "iam:DeleteRole", "iam:DeleteRolePolicy", "iam:GetRole", "iam:PassRole", "iam:PutRolePolicy", "iam:RemoveRoleFromInstanceProfile" ], "Resource": "*" } ] }

Launch an Amazon EC2 Instance with the AWS CloudFormation Template (AWS CLI)

Follow the instructions in Getting Started to install and configure the AWS CLI for use with AWS CodeDeploy.

Before you call the create-stack command, you must have an Amazon EC2 instance key pair to enable SSH access to the Amazon EC2 instance running Amazon Linux or RDP access to the Amazon EC2 instance running Windows Server. Type the key pair name only, not the key pair file extension.

To find a key pair name, open the Amazon EC2 console at https://console.aws.amazon.com/ec2. In the navigation pane, under Network & Security, choose Key Pairs, and note the key pair name in the list.

To generate a key pair, see Creating Your Key Pair Using Amazon EC2. Be sure the key pair is created in one of the regions listed in Region and Endpoints in the AWS General Reference. Otherwise, you won't be able to use the instance key pair with AWS CodeDeploy.

  1. Use our AWS CloudFormation template in a call to the create-stack command. This stack will launch a new Amazon EC2 instance with the AWS CodeDeploy agent installed.

    To launch an Amazon EC2 instance running Amazon Linux:

    Copy
    aws cloudformation create-stack \ --stack-name CodeDeployDemoStack \ --template-url templateURL \ --parameters ParameterKey=InstanceCount,ParameterValue=1 ParameterKey=InstanceType,ParameterValue=t1.micro \ ParameterKey=KeyPairName,ParameterValue=keyName ParameterKey=OperatingSystem,ParameterValue=Linux \ ParameterKey=SSHLocation,ParameterValue=0.0.0.0/0 ParameterKey=TagKey,ParameterValue=Name \ ParameterKey=TagValue,ParameterValue=CodeDeployDemo \ --capabilities CAPABILITY_IAM

    To launch an Amazon EC2 instance running Windows Server:

    Copy
    aws cloudformation create-stack --stack-name CodeDeployDemoStack --template-url template-url --parameters ParameterKey=InstanceCount,ParameterValue=1 ParameterKey=InstanceType,ParameterValue=t1.micro ParameterKey=KeyPairName,ParameterValue=keyName ParameterKey=OperatingSystem,ParameterValue=Windows ParameterKey=SSHLocation,ParameterValue=0.0.0.0/0 ParameterKey=TagKey,ParameterValue=Name ParameterKey=TagValue,ParameterValue=CodeDeployDemo --capabilities CAPABILITY_IAM

    template-url is one of the following:

    • http://s3.amazonaws.com/aws-codedeploy-us-east-1/templates/latest/CodeDeploy_SampleCF_Template.json (for the US East (N. Virginia) region)

    • http://s3-us-east-2.amazonaws.com/aws-codedeploy-us-east-2/templates/latest/CodeDeploy_SampleCF_Template.json (for the US East (Ohio) region)

    • http://s3-us-west-1.amazonaws.com/aws-codedeploy-us-west-1/templates/latest/CodeDeploy_SampleCF_Template.json (for the US West (N. California) region)

    • http://s3-us-west-2.amazonaws.com/aws-codedeploy-us-west-2/templates/latest/CodeDeploy_SampleCF_Template.json (for the US West (Oregon) region)

    • http://s3-ca-central-1.amazonaws.com/aws-codedeploy-ca-central-1/templates/latest/CodeDeploy_SampleCF_Template.json (for the Canada (Central) region)

    • http://s3-eu-west-1.amazonaws.com/aws-codedeploy-eu-west-1/templates/latest/CodeDeploy_SampleCF_Template.json (for the EU (Ireland) region)

    • http://s3-eu-west-2.amazonaws.com/aws-codedeploy-eu-west-2/templates/latest/CodeDeploy_SampleCF_Template.json (for the EU (London) region)

    • http://s3-eu-central-1.amazonaws.com/aws-codedeploy-eu-central-1/templates/latest/CodeDeploy_SampleCF_Template.json (for the EU (Frankfurt) region)

    • http://s3-ap-northeast-1.amazonaws.com/aws-codedeploy-ap-northeast-1/templates/latest/CodeDeploy_SampleCF_Template.json (for the Asia Pacific (Tokyo) region)

    • http://s3-ap-northeast-2.amazonaws.com/aws-codedeploy-ap-northeast-2/templates/latest/CodeDeploy_SampleCF_Template.json (for the Asia Pacific (Seoul) region)

    • http://s3-ap-southeast-1.amazonaws.com/aws-codedeploy-ap-southeast-1/templates/latest/CodeDeploy_SampleCF_Template.json (for the Asia Pacific (Singapore) region)

    • http://s3-ap-southeast-2.amazonaws.com/aws-codedeploy-ap-southeast-2/templates/latest/CodeDeploy_SampleCF_Template.json (for the Asia Pacific (Sydney) region)

    • http://s3-ap-south-1.amazonaws.com/aws-codedeploy-ap-south-1/templates/latest/CodeDeploy_SampleCF_Template.json (for the Asia Pacific (Mumbai) region)

    • http://s3-sa-east-1.amazonaws.com/aws-codedeploy-sa-east-1/templates/latest/CodeDeploy_SampleCF_Template.json (for the South America (São Paulo) region)

    • https://s3.cn-north-1.amazonaws.com.cn/aws-codedeploy-cn-north-1/templates/latest/CodeDeploy_SampleCF_Template.json (for the China (Beijing) region)

    This command creates an AWS CloudFormation stack named CodeDeployDemoStack, using the AWS CloudFormation template in the specified Amazon S3 bucket. The Amazon EC2 instance is based on the t1.micro instance type, but you can use any type. It is tagged with the value CodeDeployDemo, but you can tag it with any value. It has the specified instance key pair applied.

  2. Call the describe-stacks command to verify the AWS CloudFormation stack named CodeDeployDemoStack was successfully created:

    Copy
    aws cloudformation describe-stacks --stack-name CodeDeployDemoStack --query "Stacks[0].StackStatus" --output text

    Do not proceed until the value CREATE_COMPLETE is returned.

To verify the AWS CodeDeploy agent is running on the Amazon EC2 instance, see Managing AWS CodeDeploy Agent Operations, and then proceed to Create an Application.

Launch an Amazon EC2 Instance with the AWS CloudFormation Template (Console)

Before you begin, you must have an instance key pair to enable SSH access to the Amazon EC2 instance running Amazon Linux or RDP access to the instance running Windows Server. Type the key pair name only, not the key pair file extension.

To find a key pair name, open the Amazon EC2 console at https://console.aws.amazon.com/ec2. In the navigation pane, under Network & Security, choose Key Pairs, and note the key pair name in the list.

To generate a new key pair, see Creating Your Key Pair Using Amazon EC2. Be sure the key pair is created in one of the regions listed in Region and Endpoints in AWS General Reference. Otherwise, you won't be able to use the instance key pair with AWS CodeDeploy.

  1. Sign in to the AWS Management Console and open the AWS CloudFormation console at https://console.aws.amazon.com/cloudformation/.

    Important

    Sign in to the AWS Management Console with the same account you used in Getting Started. On the navigation bar, in the region selector, choose one of the regions listed in Region and Endpoints in AWS General Reference. AWS CodeDeploy supports these regions only.

  2. Choose Create Stack.

  3. In Choose a template, choose Specify an Amazon S3 template URL. In the box, type one of the following, and then choose Next.

    • http://s3.amazonaws.com/aws-codedeploy-us-east-1/templates/latest/CodeDeploy_SampleCF_Template.json (for the US East (N. Virginia) region)

    • http://s3-us-east-2.amazonaws.com/aws-codedeploy-us-east-2/templates/latest/CodeDeploy_SampleCF_Template.json (for the US East (Ohio) region)

    • http://s3-us-west-1.amazonaws.com/aws-codedeploy-us-west-1/templates/latest/CodeDeploy_SampleCF_Template.json (for the US West (N. California) region)

    • http://s3-us-west-2.amazonaws.com/aws-codedeploy-us-west-2/templates/latest/CodeDeploy_SampleCF_Template.json (for the US West (Oregon) region)

    • http://s3-ca-central-1.amazonaws.com/aws-codedeploy-ca-central-1/templates/latest/CodeDeploy_SampleCF_Template.json (for the Canada (Central) region)

    • http://s3-eu-west-1.amazonaws.com/aws-codedeploy-eu-west-1/templates/latest/CodeDeploy_SampleCF_Template.json (for the EU (Ireland) region)

    • http://s3-eu-west-2.amazonaws.com/aws-codedeploy-eu-west-2/templates/latest/CodeDeploy_SampleCF_Template.json (for the EU (London) region)

    • http://s3-eu-central-1.amazonaws.com/aws-codedeploy-eu-central-1/templates/latest/CodeDeploy_SampleCF_Template.json (for the EU (Frankfurt) region)

    • http://s3-ap-northeast-1.amazonaws.com/aws-codedeploy-ap-northeast-1/templates/latest/CodeDeploy_SampleCF_Template.json (for the Asia Pacific (Tokyo) region)

    • http://s3-ap-northeast-2.amazonaws.com/aws-codedeploy-ap-northeast-2/templates/latest/CodeDeploy_SampleCF_Template.json (for the Asia Pacific (Seoul) region)

    • http://s3-ap-southeast-1.amazonaws.com/aws-codedeploy-ap-southeast-1/templates/latest/CodeDeploy_SampleCF_Template.json (for the Asia Pacific (Singapore) region)

    • http://s3-ap-southeast-2.amazonaws.com/aws-codedeploy-ap-southeast-2/templates/latest/CodeDeploy_SampleCF_Template.json (for the Asia Pacific (Sydney) region)

    • http://s3-ap-south-1.amazonaws.com/aws-codedeploy-ap-south-1/templates/latest/CodeDeploy_SampleCF_Template.json (for the Asia Pacific (Mumbai) region)

    • http://s3-sa-east-1.amazonaws.com/aws-codedeploy-sa-east-1/templates/latest/CodeDeploy_SampleCF_Template.json (for the South America (São Paulo) region)

    • https://s3.cn-north-1.amazonaws.com.cn/aws-codedeploy-cn-north-1/templates/latest/CodeDeploy_SampleCF_Template.json (for the China (Beijing) region)

  4. In the Stack name box, type a name for the stack (for example, CodeDeployDemoStack).

  5. In Parameters, type the following, and then choose Next.

    • For InstanceCount, type the number of instances you want to launch. (We recommend you leave the default of 1.)

    • For InstanceType, type the instance type you want to launch (or leave the default of t1.micro).

    • For KeyPairName, type the instance key name.

    • For OperatingSystem box, type Windows to launch instances running Windows Server (or leave the default of Linux).

    • For SSHLocation, type the IP address range to use for connecting to the instance with SSH or RDP (or leave the default of 0.0.0.0/0).

      Important

      The default of 0.0.0.0/0 is provided for demonstration purposes only. AWS CodeDeploy does not require Amazon EC2 instances to have unrestricted access to ports. As a best practice, we recommend restricting access to SSH (and HTTP) ports. For more information, see Tips for Securing Your Amazon EC2 Instance.

    • For TagKey, type the instance tag key AWS CodeDeploy will use to identify the instances during deployment (or leave the default of Name).

    • For TagValue, type the instance tag value AWS CodeDeploy will use to identify the instances during deployment (or leave the default of CodeDeployDemo).

  6. On the Options page, leave the option boxes blank, and choose Next.

    Important

    AWS CloudFormation tags are different from AWS CodeDeploy tags. AWS CloudFormation uses tags to simplify administration of your infrastructure. AWS CodeDeploy uses tags to identify Amazon EC2 instances. You specified AWS CodeDeploy tags on the Specify Parameters page.

  7. On the Review page, in Capabilities, select the I acknowledge that AWS CloudFormation might create IAM resources box, and then choose Create.

    After AWS CloudFormation has created the stack and launched the Amazon EC2 instances, in the AWS CloudFormation console, CREATE_COMPLETE will be displayed in the Status column. This process can take several minutes.

To verify the AWS CodeDeploy agent is running on the Amazon EC2 instances, see Managing AWS CodeDeploy Agent Operations, and then proceed to Create an Application.