Skip to content

Commit

Permalink
fix(experimental-ec2-pattern): Set ASG DesiredCapacity
Browse files Browse the repository at this point in the history
During a deployment, CloudFormation updates the min and desired.

During a rollback (e.g. if the healthcheck failed), CloudFormation only resets the min.
The desired is still elevated, meaning the service is over provisioned.

Explicitly setting the desired property of the ASG ensures CloudFormation rollback puts the ASG back to the initial state,
e.g. correctly provisioned.
  • Loading branch information
akash1810 committed Aug 20, 2024
1 parent 1b97ea0 commit 00ef046
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ exports[`The GuEc2AppExperimental pattern matches the snapshot 1`] = `
},
},
"Properties": {
"DesiredCapacity": "1",
"HealthCheckGracePeriod": 120,
"HealthCheckType": "ELB",
"LaunchTemplate": {
Expand Down
14 changes: 14 additions & 0 deletions src/experimental/patterns/ec2-app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ describe("The GuEc2AppExperimental pattern", () => {
expect(Template.fromStack(stack).toJSON()).toMatchSnapshot();
});

it("should create an ASG with min, max, and desired capacity set", () => {
const stack = simpleGuStackForTesting();

new GuEc2AppExperimental(stack, { ...initialProps(stack), scaling: { minimumInstances: 5 } });

Template.fromStack(stack).hasResource("AWS::AutoScaling::AutoScalingGroup", {
Properties: {
MinSize: "5",
MaxSize: "10",
DesiredCapacity: "5",
},
});
});

it("should create an ASG with a resource signal count that matches the min instances", () => {
const stack = simpleGuStackForTesting();

Expand Down
2 changes: 2 additions & 0 deletions src/experimental/patterns/ec2-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export class GuEc2AppExperimental extends GuEc2App {
const { userData, role } = autoScalingGroup;
const cfnAutoScalingGroup = autoScalingGroup.node.defaultChild as CfnAutoScalingGroup;

cfnAutoScalingGroup.desiredCapacity = minimumInstances.toString();

cfnAutoScalingGroup.metricsCollection = [
{
/*
Expand Down

0 comments on commit 00ef046

Please sign in to comment.