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.
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.
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
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.
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.