Skip to content

Commit

Permalink
Switch to GuEc2AppExperimental for CloudFormation autoscaling deplo…
Browse files Browse the repository at this point in the history
…yments
  • Loading branch information
akash1810 committed Jul 29, 2024
1 parent 4f96638 commit 0b315ed
Show file tree
Hide file tree
Showing 4 changed files with 908 additions and 667 deletions.
81 changes: 79 additions & 2 deletions cdk/lib/__snapshots__/cdk-playground.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Object {
"GuVpcParameter",
"GuSubnetListParameter",
"GuSubnetListParameter",
"GuPlayApp",
"GuEc2AppExperimental",
"GuDistributionBucketParameter",
"GuCertificate",
"GuInstanceRole",
Expand Down Expand Up @@ -113,7 +113,44 @@ Object {
},
},
"Resources": Object {
"AsgReplacingUpdatePolicy78CF34D5": Object {
"Properties": Object {
"PolicyDocument": Object {
"Statement": Array [
Object {
"Action": "cloudformation:SignalResource",
"Effect": "Allow",
"Resource": Object {
"Ref": "AWS::StackId",
},
},
Object {
"Action": "elasticloadbalancing:DescribeTargetHealth",
"Effect": "Allow",
"Resource": "*",
},
],
"Version": "2012-10-17",
},
"PolicyName": "AsgReplacingUpdatePolicy78CF34D5",
"Roles": Array [
Object {
"Ref": "InstanceRoleCdkplaygroundC280027A",
},
],
},
"Type": "AWS::IAM::Policy",
},
"AutoScalingGroupCdkplaygroundASGD6E49F0F": Object {
"CreationPolicy": Object {
"AutoScalingCreationPolicy": Object {
"MinSuccessfulInstancesPercent": 100,
},
"ResourceSignal": Object {
"Count": 1,
"Timeout": "PT5M",
},
},
"Properties": Object {
"HealthCheckGracePeriod": 120,
"HealthCheckType": "ELB",
Expand Down Expand Up @@ -188,6 +225,14 @@ Object {
},
},
"Type": "AWS::AutoScaling::AutoScalingGroup",
"UpdatePolicy": Object {
"AutoScalingReplacingUpdate": Object {
"WillReplace": true,
},
"AutoScalingScheduledAction": Object {
"IgnoreUnmodifiedGroupSizeProperties": true,
},
},
},
"CertificateCdkplayground47FCF7D9": Object {
"DeletionPolicy": "Retain",
Expand Down Expand Up @@ -1683,13 +1728,45 @@ Object {
"",
Array [
"#!/bin/bash
function exitTrap(){
exitCode=$?
cfn-signal --stack ",
Object {
"Ref": "AWS::StackId",
},
" --resource AutoScalingGroupCdkplaygroundASGD6E49F0F --region eu-west-1 --exit-code $exitCode || echo 'Failed to send Cloudformation Signal'
}
trap exitTrap EXIT
mkdir -p $(dirname '/cdk-playground/cdk-playground.deb')
aws s3 cp 's3://",
Object {
"Ref": "DistributionBucketName",
},
"/playground/PROD/cdk-playground/cdk-playground.deb' '/cdk-playground/cdk-playground.deb'
dpkg -i /cdk-playground/cdk-playground.deb",
dpkg -i /cdk-playground/cdk-playground.deb
# GuEc2AppExperimental UserData Start
INSTANCE_ID=$(ec2metadata --instance-id)
STATE=$(aws elbv2 describe-target-health --target-group-arn ",
Object {
"Ref": "TargetGroupCdkplayground7A453FC2",
},
" --region eu-west-1 --targets Id=$INSTANCE_ID,Port=9000 --query \\"TargetHealthDescriptions[0].TargetHealth.State\\")
until [ \\"$STATE\\" == \\"\\\\\\"healthy\\\\\\"\\" ]; do
echo \\"Instance not yet healthy within target group. Current state $STATE. Sleeping...\\"
sleep 5
STATE=$(aws elbv2 describe-target-health --target-group-arn ",
Object {
"Ref": "TargetGroupCdkplayground7A453FC2",
},
" --region eu-west-1 --targets Id=$INSTANCE_ID,Port=9000 --query \\"TargetHealthDescriptions[0].TargetHealth.State\\")
done
# GuEc2AppExperimental UserData End",
],
],
},
Expand Down
6 changes: 4 additions & 2 deletions cdk/lib/cdk-playground.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { GuApiLambda, GuPlayApp } from '@guardian/cdk';
import { GuApiLambda } from '@guardian/cdk';
import { AccessScope } from '@guardian/cdk/lib/constants/access';
import { GuCertificate } from '@guardian/cdk/lib/constructs/acm';
import type { GuStackProps } from '@guardian/cdk/lib/constructs/core';
import { GuStack, GuStringParameter } from '@guardian/cdk/lib/constructs/core';
import { GuCname } from '@guardian/cdk/lib/constructs/dns';
import { GuFastlyLogsIamRole } from '@guardian/cdk/lib/constructs/iam';
import { GuEc2AppExperimental } from '@guardian/cdk/lib/experimental/patterns/ec2-app';
import type { App } from 'aws-cdk-lib';
import { Duration } from 'aws-cdk-lib';
import { InstanceClass, InstanceSize, InstanceType } from 'aws-cdk-lib/aws-ec2';
Expand All @@ -26,7 +27,8 @@ export class CdkPlayground extends GuStack {
const ec2App = 'cdk-playground';
const ec2AppDomainName = 'cdk-playground.gutools.co.uk';

const { loadBalancer } = new GuPlayApp(this, {
const { loadBalancer } = new GuEc2AppExperimental(this, {
applicationPort: 9000,
app: ec2App,
instanceType: InstanceType.of(InstanceClass.T4G, InstanceSize.MICRO),
access: { scope: AccessScope.PUBLIC },
Expand Down
Loading

0 comments on commit 0b315ed

Please sign in to comment.