David shows you how to
install the AWS CodeDeploy agent
on an EC2 instance running Windows

DavidLantz_Dublin_0518

I want to install the AWS CodeDeploy agent on my Amazon Elastic Compute Cloud (EC2) Windows instance. How can I do that using launch configurations?

You can install the AWS CodeDeploy agent using launch configurations in one of the following ways:

  • During instance launch configuration, add Windows PowerShell commands that download and install the agent.
  • Launch instances from a custom Amazon Machine Image (AMI) that has AWS CodeDeploy installed.

During instance launch configuration, add Windows PowerShell commands that download and install the agent

Note: The following steps use Amazon EC2 Auto Scaling launch configurations, but you can apply the instructions to individual instances as well.

1.    Open the Amazon EC2 console.

2.    From the navigation pane, under Auto Scaling, choose Launch Configurations.

3.    Choose Create Launch Configuration.

4.    Choose a Microsoft Windows AMI that is supported by the AWS CodeDeploy agent.

5.    Choose an instance type, then choose Next: Configure details.
Note: The minimum recommended EC2 instance type for running Windows Server is t2.medium.

6.    For Name, type a name for the launch configuration.

7.    For IAM role, choose an AWS Identity and Access Management (IAM) role that is compatible with the permissions you need to use with AWS CodeDeploy.

8.    Expand Advanced Details.

9.    For User data, enter the following Windows PowerShell commands that download and install the AWS CodeDeploy agent:

<powershell>
Set-ExecutionPolicy RemoteSigned
Import-Module AWSPowerShell
$REGION = (ConvertFrom-Json (Invoke-WebRequest -Uri http://169.254.169.254/latest/dynamic/instance-identity/document -UseBasicParsing).Content).region
New-Item -Path c:\temp -ItemType "directory" -Force 
powershell.exe -Command Read-S3Object -BucketName aws-codedeploy-$REGION -Key latest/codedeploy-agent.msi -File c:\temp\codedeploy-agent.msi
//Start-Sleep -Seconds 30 *optional
Start-Process c:\temp\codedeploy-agent.msi /quiet /l c:\temp\host-agent- log.txt
</powershell>

Note: For both new and existing instances, we recommend that you install the AWS CodeDeploy agent updater for Windows Server. On new instances, you can install the updater instead of the agent.

10.    Complete the storage and security group set up for your launch configuration. Optionally, you can choose Skip to review.

11.    Choose Create launch configuration.

Launch instances from a custom AMI that has AWS CodeDeploy installed

You can create an AMI from one EC2 Windows instance that has AWS CodeDeploy installed, and then launch more instances using that custom AMI.

You must make the following configurations on the instance that you use to create the AMI. To avoid deployment failures, these configurations require that all provisioning steps and dependencies are complete before starting the agent.

1.    Connect to the instance.

2.    Run the following PowerShell command to set the AWS CodeDeploy agent to a stopped state and to change its startup type to be manual:

Set-Service -Name 'codedeployagent' -StartupType 'manual' -Status 'stopped'

3.    Add the following command to the instance's user data. The command starts the AWS CodeDeploy agent and changes its startup type to be automatic:

Warning: This command must be the last command executed in the instance's user data.

Set-Service -Name 'codedeployagent' -StartupType 'automatic' -Status 'running'

After you create a custom AMI from the instance, you can use the AMI to launch other instances with the AWS CodeDeploy agent already installed.


Did this page help you? Yes | No

Back to the AWS Support Knowledge Center

Need help? Visit the AWS Support Center

Published: 2018-06-15