diff --git a/packages/cdk-blue-green-container-deployment/lambda-file-sizes.json b/packages/cdk-blue-green-container-deployment/lambda-file-sizes.json index 292a9dc16..3989ae063 100644 --- a/packages/cdk-blue-green-container-deployment/lambda-file-sizes.json +++ b/packages/cdk-blue-green-container-deployment/lambda-file-sizes.json @@ -1 +1 @@ -[{"timestamp":1643739695237,"files":[{"filename":"ecs-deployment-group/index.js","previous":148006,"size":147762,"diff":-244},{"filename":"ecs-service/index.js","previous":147514,"size":147469,"diff":-45}]},{"timestamp":1643739156615,"files":[{"filename":"ecs-deployment-group/index.js","previous":147762,"size":148006,"diff":244},{"filename":"ecs-service/index.js","previous":147469,"size":147514,"diff":45}]},{"timestamp":1643738715672,"files":[{"filename":"ecs-deployment-group/index.js","previous":148006,"size":147762,"diff":-244},{"filename":"ecs-service/index.js","previous":147514,"size":147469,"diff":-45}]},{"timestamp":1643738518282,"files":[{"filename":"ecs-deployment-group/index.js","previous":0,"size":148006,"diff":148006},{"filename":"ecs-service/index.js","previous":0,"size":147514,"diff":147514}]},{"timestamp":1643732386377,"files":[{"filename":"ecs-deployment-group/index.js","previous":147762,"size":0,"diff":-147762},{"filename":"ecs-service/index.js","previous":147469,"size":0,"diff":-147469}]},{"timestamp":1642109009944,"files":[{"filename":"ecs-deployment-group/index.js","previous":145598,"size":147762,"diff":2164},{"filename":"ecs-service/index.js","previous":145304,"size":147469,"diff":2165}]},{"timestamp":1639256487176,"files":[{"filename":"ecs-deployment-group/index.js","previous":145308,"size":145598,"diff":290},{"filename":"ecs-service/index.js","previous":145014,"size":145304,"diff":290}]},{"timestamp":1637794842477,"files":[{"filename":"ecs-deployment-group/index.js","previous":145307,"size":145308,"diff":1},{"filename":"ecs-service/index.js","previous":145016,"size":145014,"diff":-2}]},{"timestamp":1637781788109,"files":[{"filename":"ecs-deployment-group/index.js","previous":144989,"size":145307,"diff":318},{"filename":"ecs-service/index.js","previous":144998,"size":145016,"diff":18}]},{"timestamp":1637708323927,"files":[{"filename":"ecs-deployment-group/index.js","previous":0,"size":144989,"diff":144989},{"filename":"ecs-service/index.js","previous":0,"size":144998,"diff":144998}]}] +[{"timestamp":1674711096157,"files":[{"filename":"ecs-deployment-group/index.js","previous":147762,"size":147762,"diff":0},{"filename":"ecs-service/index.js","previous":147469,"size":147475,"diff":6}]},{"timestamp":1643739695237,"files":[{"filename":"ecs-deployment-group/index.js","previous":148006,"size":147762,"diff":-244},{"filename":"ecs-service/index.js","previous":147514,"size":147469,"diff":-45}]},{"timestamp":1643739156615,"files":[{"filename":"ecs-deployment-group/index.js","previous":147762,"size":148006,"diff":244},{"filename":"ecs-service/index.js","previous":147469,"size":147514,"diff":45}]},{"timestamp":1643738715672,"files":[{"filename":"ecs-deployment-group/index.js","previous":148006,"size":147762,"diff":-244},{"filename":"ecs-service/index.js","previous":147514,"size":147469,"diff":-45}]},{"timestamp":1643738518282,"files":[{"filename":"ecs-deployment-group/index.js","previous":0,"size":148006,"diff":148006},{"filename":"ecs-service/index.js","previous":0,"size":147514,"diff":147514}]},{"timestamp":1643732386377,"files":[{"filename":"ecs-deployment-group/index.js","previous":147762,"size":0,"diff":-147762},{"filename":"ecs-service/index.js","previous":147469,"size":0,"diff":-147469}]},{"timestamp":1642109009944,"files":[{"filename":"ecs-deployment-group/index.js","previous":145598,"size":147762,"diff":2164},{"filename":"ecs-service/index.js","previous":145304,"size":147469,"diff":2165}]},{"timestamp":1639256487176,"files":[{"filename":"ecs-deployment-group/index.js","previous":145308,"size":145598,"diff":290},{"filename":"ecs-service/index.js","previous":145014,"size":145304,"diff":290}]},{"timestamp":1637794842477,"files":[{"filename":"ecs-deployment-group/index.js","previous":145307,"size":145308,"diff":1},{"filename":"ecs-service/index.js","previous":145016,"size":145014,"diff":-2}]},{"timestamp":1637781788109,"files":[{"filename":"ecs-deployment-group/index.js","previous":144989,"size":145307,"diff":318},{"filename":"ecs-service/index.js","previous":144998,"size":145016,"diff":18}]},{"timestamp":1637708323927,"files":[{"filename":"ecs-deployment-group/index.js","previous":0,"size":144989,"diff":144989},{"filename":"ecs-service/index.js","previous":0,"size":144998,"diff":144998}]}] diff --git a/packages/cdk-blue-green-container-deployment/src/__tests__/ecs-service.test.ts b/packages/cdk-blue-green-container-deployment/src/__tests__/ecs-service.test.ts index cbcef06a1..75accb5c1 100644 --- a/packages/cdk-blue-green-container-deployment/src/__tests__/ecs-service.test.ts +++ b/packages/cdk-blue-green-container-deployment/src/__tests__/ecs-service.test.ts @@ -1,4 +1,4 @@ -import { expect as expectCDK, haveResource } from '@aws-cdk/assert'; +import { anything, expect as expectCDK, haveResource } from '@aws-cdk/assert'; import * as cdk from 'aws-cdk-lib'; import * as ecs from 'aws-cdk-lib/aws-ecs'; import * as elb from 'aws-cdk-lib/aws-elasticloadbalancingv2'; @@ -32,6 +32,40 @@ describe('EcsService', () => { }), ); }); + + test('Creates a BlueGreenService custom resource without a DesiredCount', () => { + expectCDK(stack).notTo( + haveResource('Custom::BlueGreenService', { + DesiredCount: anything(), + }), + ); + }); + }); + + describe('with desiredCount', () => { + const stack = new cdk.Stack(app, 'MyStackWithDesiredCount'); + const cluster = new ecs.Cluster(stack, 'Cluster'); + const prodTargetGroup = new elb.ApplicationTargetGroup(stack, 'ProdTargetGroup', { vpc: cluster.vpc }); + const testTargetGroup = new elb.ApplicationTargetGroup(stack, 'TestTargetGroup', { vpc: cluster.vpc }); + const taskDefinition = new DummyTaskDefinition(stack, 'DummyTaskDefinition', { image: 'nginx' }); + + new EcsService(stack, 'Service', { + cluster, + serviceName: 'My Service', + prodTargetGroup, + testTargetGroup, + taskDefinition, + propagateTags: PropagateTags.SERVICE, + desiredCount: 3, + }); + + test('sets the desired count', () => { + expectCDK(stack).to( + haveResource('Custom::BlueGreenService', { + DesiredCount: 3, + }), + ); + }); }); describe('with tag propagation', () => { diff --git a/packages/cdk-blue-green-container-deployment/src/__tests__/lambdas/ecs-service/index.test.ts b/packages/cdk-blue-green-container-deployment/src/__tests__/lambdas/ecs-service/index.test.ts index a127ae7c5..8fa5f189e 100644 --- a/packages/cdk-blue-green-container-deployment/src/__tests__/lambdas/ecs-service/index.test.ts +++ b/packages/cdk-blue-green-container-deployment/src/__tests__/lambdas/ecs-service/index.test.ts @@ -81,6 +81,44 @@ describe('createHandler', () => { }, }); }); + + describe('with desired count', () => { + test('sends the specified desired count', async () => { + await handleCreate( + { + ...defaultEvent, + RequestType: 'Create', + ResourceProperties: { + ...defaultEcsServiceResourceProperties, + DesiredCount: 4, + }, + }, + defaultContext, + defaultLogger, + ); + + expect(mockCreateRequest).toHaveBeenCalledWith(expect.objectContaining({ desiredCount: 4 })); + }); + }); + + describe('without desired count', () => { + test('sends 1 (default) as the desired count', async () => { + await handleCreate( + { + ...defaultEvent, + RequestType: 'Create', + ResourceProperties: { + ...defaultEcsServiceResourceProperties, + desiredCount: undefined, + }, + }, + defaultContext, + defaultLogger, + ); + + expect(mockCreateRequest).toHaveBeenCalledWith(expect.objectContaining({ desiredCount: 1 })); + }); + }); }); describe('updateHandler', () => { @@ -222,4 +260,61 @@ describe('updateHandler', () => { expect(mockTagResourceRequest).not.toHaveBeenCalled(); }); + + describe('with desired count', () => { + test('sends the desired count', async () => { + await handleUpdate( + { + ...defaultEvent, + RequestType: 'Update', + PhysicalResourceId: 'foo', + ResourceProperties: { + ...defaultEcsServiceResourceProperties, + DesiredCount: 3, + }, + OldResourceProperties: { + ...defaultEcsServiceResourceProperties, + DesiredCount: 2, + }, + }, + defaultContext, + defaultLogger, + ); + expect(mockUpdateRequest).toHaveBeenCalledWith( + expect.objectContaining({ + cluster: 'foo', + deploymentConfiguration: {}, + desiredCount: 3, + healthCheckGracePeriodSeconds: 3, + service: 'foo', + }), + ); + }); + }); + + describe('without desired count', () => { + test('does not send the desired count', async () => { + await handleUpdate( + { + ...defaultEvent, + RequestType: 'Update', + PhysicalResourceId: 'foo', + ResourceProperties: { + ...defaultEcsServiceResourceProperties, + DesiredCount: undefined, + }, + OldResourceProperties: { + ...defaultEcsServiceResourceProperties, + }, + }, + defaultContext, + defaultLogger, + ); + expect(mockUpdateRequest).toHaveBeenCalledWith( + expect.objectContaining({ + desiredCount: undefined, + }), + ); + }); + }); }); diff --git a/packages/cdk-blue-green-container-deployment/src/ecs-service.ts b/packages/cdk-blue-green-container-deployment/src/ecs-service.ts index e5bae9c5a..2faaa4d3d 100644 --- a/packages/cdk-blue-green-container-deployment/src/ecs-service.ts +++ b/packages/cdk-blue-green-container-deployment/src/ecs-service.ts @@ -80,7 +80,7 @@ export class EcsService extends Construct implements IConnectable, IEcsService, serviceName, launchType = LaunchType.FARGATE, platformVersion = '1.4.0', - desiredCount = 1, + desiredCount, prodTargetGroup, testTargetGroup, taskDefinition, diff --git a/packages/cdk-blue-green-container-deployment/src/lambdas/ecs-service/index.ts b/packages/cdk-blue-green-container-deployment/src/lambdas/ecs-service/index.ts index 3202d470c..c23234368 100644 --- a/packages/cdk-blue-green-container-deployment/src/lambdas/ecs-service/index.ts +++ b/packages/cdk-blue-green-container-deployment/src/lambdas/ecs-service/index.ts @@ -21,7 +21,7 @@ export interface BlueGreenServiceProps { taskDefinition: string; launchType: string; platformVersion: string; - desiredCount: number; + desiredCount?: number; subnets: string[]; securityGroups: string[]; targetGroupArn: string; @@ -81,7 +81,7 @@ export const handleCreate: OnCreateHandler = async (event): Promise