CodeDeploy
Simfra's CodeDeploy supports all three compute platforms - EC2/Server, Lambda, and ECS. Deployments progress through the same lifecycle events as real AWS, with a background worker advancing each phase.
Prerequisites
SIMFRA_DOCKER=truefor EC2/Server and ECS targets- Lambda deployments work without Docker
EC2/Server Deployment
Create an Application
aws --endpoint-url http://localhost:4599 codedeploy create-application \
--application-name my-app \
--compute-platform Server
Create a Deployment Group
aws --endpoint-url http://localhost:4599 codedeploy create-deployment-group \
--application-name my-app \
--deployment-group-name prod \
--ec2-tag-filters Key=Name,Value=web,Type=KEY_AND_VALUE \
--service-role-arn arn:aws:iam::000000000000:role/codedeploy-role
Create a Deployment
aws --endpoint-url http://localhost:4599 codedeploy create-deployment \
--application-name my-app \
--deployment-group-name prod \
--revision revisionType=S3,s3Location={bucket=my-artifacts,key=app.zip,bundleType=zip}
Check Deployment Status
aws --endpoint-url http://localhost:4599 codedeploy get-deployment \
--deployment-id d-XXXXXXXXX
Deployment State Machine
Every deployment progresses through these states:
Created --> Queued --> InProgress --> Succeeded
\-> Failed
\-> Stopped
- Created: Deployment registered, waiting to be queued
- Queued: Waiting for any in-progress deployment in the same group to finish
- InProgress: Targets are being deployed to, lifecycle events executing
- Succeeded/Failed/Stopped: Terminal states
Lifecycle Events
EC2/Server (without load balancer)
ApplicationStop --> DownloadBundle --> BeforeInstall --> Install -->
AfterInstall --> ApplicationStart --> ValidateService
EC2/Server (with load balancer)
BeforeBlockTraffic --> BlockTraffic --> AfterBlockTraffic -->
ApplicationStop --> DownloadBundle --> BeforeInstall --> Install -->
AfterInstall --> ApplicationStart --> ValidateService -->
BeforeAllowTraffic --> AllowTraffic --> AfterAllowTraffic
Lambda
BeforeAllowTraffic --> AllowTraffic --> AfterAllowTraffic
ECS
BeforeInstall --> Install --> AfterInstall --> TestTraffic -->
AfterAllowTestTraffic --> BeforeAllowTraffic --> AllowTraffic -->
AfterAllowTraffic
Deployment Configurations
All predefined deployment configurations are available:
| Configuration | Platform | Behavior |
|---|---|---|
CodeDeployDefault.AllAtOnce |
Server | Deploy to all instances simultaneously |
CodeDeployDefault.HalfAtATime |
Server | Deploy to 50% of instances at a time |
CodeDeployDefault.OneAtATime |
Server | Deploy one instance at a time |
CodeDeployDefault.LambdaAllAtOnce |
Lambda | Shift all traffic immediately |
CodeDeployDefault.LambdaCanary10Percent5Minutes |
Lambda | 10% canary, then full after 5 min |
CodeDeployDefault.ECSAllAtOnce |
ECS | Shift all traffic immediately |
CodeDeployDefault.ECSCanary10Percent5Minutes |
ECS | 10% canary, then full after 5 min |
Create custom configurations with create-deployment-config:
aws --endpoint-url http://localhost:4599 codedeploy create-deployment-config \
--deployment-config-name MyCustomConfig \
--compute-platform Server \
--minimum-healthy-hosts type=FLEET_PERCENT,value=75
Lambda Deployments
aws --endpoint-url http://localhost:4599 codedeploy create-application \
--application-name my-lambda-app \
--compute-platform Lambda
aws --endpoint-url http://localhost:4599 codedeploy create-deployment-group \
--application-name my-lambda-app \
--deployment-group-name prod \
--deployment-config-name CodeDeployDefault.LambdaAllAtOnce \
--service-role-arn arn:aws:iam::000000000000:role/codedeploy-role
aws --endpoint-url http://localhost:4599 codedeploy create-deployment \
--application-name my-lambda-app \
--deployment-group-name prod \
--revision '{"revisionType":"AppSpecContent","appSpecContent":{"content":"{\"version\":0.0,\"Resources\":[{\"myFunction\":{\"Type\":\"AWS::Lambda::Function\",\"Properties\":{\"Name\":\"my-function\",\"Alias\":\"live\",\"CurrentVersion\":\"1\",\"TargetVersion\":\"2\"}}}]}"}}'
ECS Deployments
aws --endpoint-url http://localhost:4599 codedeploy create-application \
--application-name my-ecs-app \
--compute-platform ECS
aws --endpoint-url http://localhost:4599 codedeploy create-deployment-group \
--application-name my-ecs-app \
--deployment-group-name prod \
--deployment-config-name CodeDeployDefault.ECSAllAtOnce \
--service-role-arn arn:aws:iam::000000000000:role/codedeploy-role \
--ecs-services serviceName=my-service,clusterName=my-cluster
Cross-Service Integration
- S3: Revision bundles are downloaded from S3 for Server deployments.
- EC2: Server targets are resolved by matching EC2 instance tags against the deployment group's tag filters.
- Lambda: Lambda function versions and aliases are updated during deployment.
- ECS: ECS services are updated with new task definitions during blue/green deployments.
- CodePipeline: When triggered by a pipeline, deployments are created and polled automatically.
Next Steps
- CodePipeline - orchestrate pipelines with CodeDeploy deploy stages
- CodeBuild - build artifacts before deployment
- Writing ECS Tasks - write tasks for ECS blue/green deployments