Categorygithub.com/cdklabs/cdk-ecs-codedeploy-go/cdklabscdkecscodedeploy
modulepackage
0.0.341
Repository: https://github.com/cdklabs/cdk-ecs-codedeploy-go.git
Documentation: pkg.go.dev

# README

CDK ECS CodeDeploy

cdk-constructs: Experimental npm version Maven Central PyPI version NuGet version Gitpod Ready-to-Code Mergify

This project contains CDK constructs to create CodeDeploy ECS deployments.

Installation

TypeScript
yarn add @cdklabs/cdk-ecs-codedeploy
Java

See https://mvnrepository.com/artifact/io.github.cdklabs/cdk-ecs-codedeploy

Python

See https://pypi.org/project/cdklabs.ecs-codedeploy/

C#

See https://www.nuget.org/packages/Cdklabs.CdkEcsCodeDeploy/

Deployments

CodeDeploy for ECS can manage the deployment of new task definitions to ECS services. Only 1 deployment construct can be defined for a given EcsDeploymentGroup.

var deploymentGroup iEcsDeploymentGroup
var taskDefinition iTaskDefinition


cdklabscdkecscodedeploy.NewEcsDeployment(&EcsDeploymentProps{
	DeploymentGroup: DeploymentGroup,
	TargetService: &TargetService{
		TaskDefinition: *TaskDefinition,
		ContainerName: jsii.String("mycontainer"),
		ContainerPort: jsii.Number(80),
	},
})

The deployment will use the AutoRollbackConfig for the EcsDeploymentGroup unless it is overridden in the deployment:

var deploymentGroup iEcsDeploymentGroup
var taskDefinition iTaskDefinition


cdklabscdkecscodedeploy.NewEcsDeployment(&EcsDeploymentProps{
	DeploymentGroup: DeploymentGroup,
	TargetService: &TargetService{
		TaskDefinition: *TaskDefinition,
		ContainerName: jsii.String("mycontainer"),
		ContainerPort: jsii.Number(80),
	},
	AutoRollback: &AutoRollbackConfig{
		FailedDeployment: jsii.Boolean(true),
		DeploymentInAlarm: jsii.Boolean(true),
		StoppedDeployment: jsii.Boolean(false),
	},
})

By default, the deployment will timeout after 30 minutes. The timeout value can be overridden:

var deploymentGroup iEcsDeploymentGroup
var taskDefinition iTaskDefinition


cdklabscdkecscodedeploy.NewEcsDeployment(&EcsDeploymentProps{
	DeploymentGroup: DeploymentGroup,
	TargetService: &TargetService{
		TaskDefinition: *TaskDefinition,
		ContainerName: jsii.String("mycontainer"),
		ContainerPort: jsii.Number(80),
	},
	Timeout: awscdk.Duration_Minutes(jsii.Number(60)),
})

API Canaries

CodeDeploy can leverage Cloudwatch Alarms to trigger automatic rollbacks. The ApiCanary construct simplifies the process for creating CloudWatch Synthetics Canaries to monitor APIs. The following code demonstrates a canary that monitors https://xkcd.com/908/info.0.json and checks the JSON response to assert that safe_title has the value of 'The Cloud'.

canary := cdklabscdkecscodedeploy.NewApiCanary(stack, jsii.String("Canary"), &ApiCanaryProps{
	BaseUrl: jsii.String("https://xkcd.com"),
	DurationAlarmThreshold: awscdk.Duration_Seconds(jsii.Number(5)),
	ThreadCount: jsii.Number(5),
	Steps: []apiTestStep{
		&apiTestStep{
			Name: jsii.String("info"),
			Path: jsii.String("/908/info.0.json"),
			JmesPath: jsii.String("safe_title"),
			ExpectedValue: jsii.String("The Cloud"),
		},
	},
})

Application Load Balanced CodeDeployed Fargate Service

An L3 construct named ApplicationLoadBalancedCodeDeployedFargateService extends ApplicationLoadBalancedFargateService and adds support for deploying new versions of the service with AWS CodeDeploy. Additionally, an Amazon CloudWatch Synthetic canary is created via the ApiCanary construct and is monitored by the CodeDeploy deployment to trigger rollback if the canary begins to alarm.

var cluster iCluster
var image containerImage

service := cdklabscdkecscodedeploy.NewApplicationLoadBalancedCodeDeployedFargateService(stack, jsii.String("Service"), &ApplicationLoadBalancedCodeDeployedFargateServiceProps{
	Cluster: Cluster,
	TaskImageOptions: &ApplicationLoadBalancedTaskImageOptions{
		Image: *Image,
	},
	ApiTestSteps: []apiTestStep{
		&apiTestStep{
			Name: jsii.String("health"),
			Path: jsii.String("/health"),
			JmesPath: jsii.String("status"),
			ExpectedValue: jsii.String("ok"),
		},
	},
})

Local Development

yarn install
yarn build
yarn test

To run an integration test and update the snapshot, run:

yarn integ:ecs-deployment:deploy

To recreate snapshots for integration tests, run:

yarn integ:snapshot-all

Security

See CONTRIBUTING for more information.

License

This project is licensed under the Apache-2.0 License.

# Packages

Package jsii contains the functionaility needed for jsii packages to initialize their dependencies and themselves.

# Functions

Checks if `x` is a construct.
Returns true if the construct was created by CDK, and false otherwise.
Check whether the given construct is a Resource.
Checks if `x` is a construct.
Checks if `x` is a construct.
Experimental.
Experimental.
Constructs a new instance of the ApplicationLoadBalancedCodeDeployedFargateService class.
Constructs a new instance of the ApplicationLoadBalancedCodeDeployedFargateService class.
Experimental.
Experimental.
Experimental.
Experimental.

# Structs

Experimental.
Experimental.
The properties for the ApplicationLoadBalancedCodeDeployedFargateService service.
Lifecycle hooks configuration.
Network configuration for ECS services that have a network type of `awsvpc`.
Construction properties of EcsDeployment.
Describe the target for CodeDeploy to use when creating a deployment for an ecs.EcsDeploymentGroup.

# Interfaces

A CloudWatch Synthetic Canary for monitoring APIs.
A Fargate service running on an ECS cluster fronted by an application load balancer and deployed by CodeDeploy.
Represents an AppSpec to be used for ECS services.
A CodeDeploy Deployment for a Amazon ECS service DeploymentGroup.