The CDK Construct Library for AWS CodeDeploy
Applications
To create a new CodeDeploy Application that deploys to EC2/on-premise instances:
import codedeploy = require('@aws-cdk/aws-codedeploy');
const application = new codedeploy.ServerApplication(this, 'CodeDeployApplication', {
applicationName: 'MyApplication',
});
To import an already existing Application:
const application = codedeploy.ServerApplicationRef.import(this, 'ExistingCodeDeployApplication', {
applicationName: 'MyExistingApplication',
});
Deployment Groups
To create a new CodeDeploy Deployment Group that deploys to EC2/on-premise instances:
const deploymentGroup = new codedeploy.ServerDeploymentGroup(this, 'CodeDeployDeploymentGroup', {
application,
deploymentGroupName: 'MyDeploymentGroup',
autoScalingGroups: [asg1, asg2],
installAgent: true,
});
All properties are optional - if you don't provide an Application,
one will be automatically created.
To import an already existing Deployment Group:
const deploymentGroup = codedeploy.ServerDeploymentGroupRef.import(this, 'ExistingCodeDeployDeploymentGroup', {
application,
deploymentGroupName: 'MyExistingDeploymentGroup',
});
Deployment Configurations
You can also pass a Deployment Configuration when creating the Deployment Group:
const deploymentGroup = new codedeploy.ServerDeploymentGroup(this, 'CodeDeployDeploymentGroup', {
deploymentConfig: codedeploy.ServerDeploymentConfig.AllAtOnce,
});
The default Deployment Configuration is ServerDeploymentConfig.OneAtATime
.
You can also create a custom Deployment Configuration:
const deploymentConfig = new codedeploy.ServerDeploymentConfig(this, 'DeploymentConfiguration', {
deploymentConfigName: 'MyDeploymentConfiguration',
minHealthyHostCount: 2,
minHealthyHostPercentage: 75,
});
Or import an existing one:
const deploymentConfig = codedeploy.ServerDeploymentConfigRef.import(this, 'ExistingDeploymentConfiguration', {
deploymentConfigName: 'MyExistingDeploymentConfiguration',
});
Use in CodePipeline
This module also contains an Action that allows you to use CodeDeploy with AWS CodePipeline.
Example:
import codepipeline = require('@aws-cdk/aws-codepipeline');
const pipeline = new codepipeline.Pipeline(this, 'MyPipeline', {
pipelineName: 'MyPipeline',
});
const deployStage = new codepipeline.Stage(this, 'Deploy', {
pipeline,
}));
new codedeploy.PipelineDeployAction(this, 'CodeDeploy', {
stage: deployStage,
inputArtifact: buildAction.artifact,
applicationName: 'YourCodeDeployApplicationName',
deploymentGroupName: 'YourCodeDeployDeploymentGroupName',
});