0

Is it possible to have CodeDeploy automatically start a new instance "just like the last one" each time I deploy a new revision?

Thank you.

nfwlpw
  • 1
  • Do you want CodeDeploy to launch an instance and then deploy to it? Or just create a duplicate of the instance that it is deploying to? – Rodrigo Murillo Jan 12 '16 at 20:44
  • Ideally a brand new instance (like using the default RHEL AMI) not cloning an existing instance. – nfwlpw Jan 13 '16 at 15:24

3 Answers3

1

I think you would want to use Cloudformation to launch the instance, and have it pull the latest updates using Codedeploy.

I don't think you can use it the other way around, i.e. have CodeDeploy call Cloudformation.

http://docs.aws.amazon.com/codedeploy/latest/userguide/how-to-use-cloud-formation-template.html

E.J. Brennan
  • 45,870
  • 7
  • 88
  • 116
  • Thanks for the link, however it looks like Cloud Formation only supports Amazon Linux and not RHEL. Looks like CLI is my best option – nfwlpw Jan 13 '16 at 15:27
0

CodeDeploy doesn't do the instance management at the moment, so ideally you have to manage your instances through other AWS service.

In your case, looks like you want to spin up new instance for every new deployment, I think you can use CloudFormation to create a workflow that spins up a new instance and deploys new revision to it. Or you can use AWS lambda to create a workflow that automatically creates instance and deploys from S3. Here is a blog post about how to set up automatically deploy from S3.

Bangxi Yu
  • 191
  • 3
0

Yes, you can have CodeDeploy create a new instance during the deployment lifecycle, or any task you need during deployment, using lifecycle event hooks, via the AppSpec file.

For example, during the ValidateService event, you could call the AWS CLI to run a start-instance command to launch a new instance.

Here is an example of an AppSpec file:

os: linux
files:
  - source: Config/config.txt
    destination: webapps/Config
  - source: source
    destination: /webapps/myApp
hooks:
  BeforeInstall:
    - location: Scripts/UnzipResourceBundle.sh
    - location: Scripts/UnzipDataBundle.sh
  AfterInstall:
    - location: Scripts/RunResourceTests.sh
      timeout: 180
  ApplicationStart:
    - location: Scripts/RunFunctionalTests.sh
      timeout: 3600
  ValidateService:
    - location: Scripts/StartInsance.sh
      timeout: 3600
      runas: codedeployuser

Here the ValidateService event calls Scripts/StartInsance.sh which can be coded to launch an instance.

You may need to provide some logic to prevent deployments to multiple instances from launching more than one instance.

Rodrigo Murillo
  • 13,080
  • 2
  • 29
  • 50