@guardian/cdk 63.3.0 → 63.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/constructs/core/stack.js +1 -1
- package/lib/constructs/core/stack.js.map +1 -1
- package/lib/constructs/loadbalancing/alb/application-listener.d.ts +2 -2
- package/lib/constructs/loadbalancing/alb/application-listener.d.ts.map +1 -1
- package/lib/constructs/loadbalancing/alb/application-listener.js +1 -1
- package/lib/constructs/loadbalancing/alb/application-listener.js.map +1 -1
- package/lib/experimental/constructs/riff-raff-deployment-id.d.ts +8 -0
- package/lib/experimental/constructs/riff-raff-deployment-id.d.ts.map +1 -0
- package/lib/experimental/constructs/riff-raff-deployment-id.js +21 -0
- package/lib/experimental/constructs/riff-raff-deployment-id.js.map +1 -0
- package/lib/experimental/patterns/ec2-app.d.ts.map +1 -1
- package/lib/experimental/patterns/ec2-app.js +2 -15
- package/lib/experimental/patterns/ec2-app.js.map +1 -1
- package/lib/experimental/patterns/gu-load-balanced-app.d.ts +337 -0
- package/lib/experimental/patterns/gu-load-balanced-app.d.ts.map +1 -0
- package/lib/experimental/patterns/gu-load-balanced-app.js +451 -0
- package/lib/experimental/patterns/gu-load-balanced-app.js.map +1 -0
- package/lib/patterns/ec2-app/base.d.ts +10 -2
- package/lib/patterns/ec2-app/base.d.ts.map +1 -1
- package/lib/patterns/ec2-app/base.js +5 -1
- package/lib/patterns/ec2-app/base.js.map +1 -1
- package/package.json +1 -1
|
@@ -88,7 +88,7 @@ class GuStack extends aws_cdk_lib_1.Stack {
|
|
|
88
88
|
this.addTag("App", this.app);
|
|
89
89
|
}
|
|
90
90
|
if (this.riffRaffProjectName) {
|
|
91
|
-
this.addTag("gu:riff-raff
|
|
91
|
+
this.addTag("gu:riff-raff:project", this.riffRaffProjectName);
|
|
92
92
|
}
|
|
93
93
|
if (this.repositoryName) {
|
|
94
94
|
this.addTag(constants_1.MetadataKeys.REPOSITORY_NAME, this.repositoryName);
|
|
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,CAAC,CAAC;IACnD,CAAC;IAED;;;;;;;OAOG;IACK,mBAAmB;QACzB,IAAI;YACF,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,uBAAW,CAAC,cAAc,CAAuB,CAAC;YACjG,MAAM,aAAa,GAAW,cAAc,IAAI,IAAA,wBAAkB,GAAE,CAAC;YACrE,OAAO,IAAA,uBAAW,EAAC,aAAa,CAAC,CAAC,SAAS,CAAC;SAC7C;QAAC,MAAM;YACN,OAAO,CAAC,IAAI,CACV,+CAA+C,uBAAW,CAAC,cAAc,0CAA0C,CACpH,CAAC;YACF,OAAO,SAAS,CAAC;SAClB;IACH,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqDG;IACI,iBAAiB,CAAC,SAAqB,EAAE,EAAE,SAAS,EAAE,MAAM,EAAqB;QACtF,MAAM,EACJ,IAAI,EAAE,EAAE,EAAE,EAAE,YAAY,EAAE,GAC3B,GAAG,SAAS,CAAC;QAEb,YAA2B,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;QAC1D,yBAAW,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,0BAA0B,EAAE,OAAO,SAAS,aAAa,MAAM,EAAE,CAAC,CAAC;IACvG,CAAC;CACF;AA/KD,0BA+KC","sourcesContent":["import type { App, CfnElement, StackProps } from \"aws-cdk-lib\";\nimport { Annotations, Aspects, CfnParameter, LegacyStackSynthesizer, Stack, Tags } from \"aws-cdk-lib\";\nimport type { IConstruct } from \"constructs\";\nimport gitUrlParse from \"git-url-parse\";\nimport { CfnIncludeReporter } from \"../../aspects/cfn-include-reporter\";\nimport { CfnParameterReporter } from \"../../aspects/cfn-parameter-reporter\";\nimport { Metadata } from \"../../aspects/metadata\";\nimport { ContextKeys, MetadataKeys, TrackingTag } from \"../../constants\";\nimport { gitRemoteOriginUrl } from \"../../utils/git\";\nimport type { StackStageIdentity } from \"./identity\";\nimport type { GuStaticLogicalId } from \"./migrating\";\n\nexport interface GuStackProps extends Omit<StackProps, \"stackName\"> {\n /**\n * The Guardian stack being used (as defined in your riff-raff.yaml).\n * This will be applied as a tag to all of your resources.\n */\n stack: string;\n\n /**\n * The stage being used (as defined in your riff-raff.yaml).\n * This will be applied as a tag to all of your resources.\n */\n stage: string;\n\n /**\n * Optional name of the app. If defined, all resources will have an App tag.\n */\n app?: string;\n\n /**\n * The name of the Riff-Raff project used to deploy these resources.\n * Used as the value of the `gu:riff-raff-project` tag on all resources.\n * If using {@link GuRoot} or {@link RiffRaffYamlFile}, this value is also used in the location of the generated `riff-raff.yaml`.\n *\n * @see https://github.com/guardian/riffraff-platform\n */\n riffRaffProjectName?: string;\n\n /**\n * The AWS CloudFormation stack name (as shown in the AWS CloudFormation UI).\n * @defaultValue the `GU_CFN_STACK_NAME` environment variable\n */\n cloudFormationStackName?: string;\n /**\n * Set this to true to stop the GuStack from tagging all of your AWS resources.\n * This should only be turned on as part of an initial migration from CloudFormation.\n */\n withoutTags?: boolean;\n\n /**\n * Set to disable CDK metadata. Only for internal use (for disabling for some\n * snapshot tests). We rely on tracking data to prioritise future work so\n * please do not override this.\n */\n withoutMetadata?: boolean;\n}\n\n/**\n * GuStack provides the `stack` and `stage` parameters to a template.\n * It also takes the `app` in the constructor.\n *\n * GuStack will add the Stack, Stage and App tags to all resources.\n *\n * GuStack also adds the tag `X-Gu-CDK-Version`.\n * This tag allows us to measure adoption of this library.\n * It's value is the version of guardian/cdk being used, as defined in `package.json`.\n * As a result, the change sets between version numbers will be fairly noisy,\n * as all resources receive a tag update.\n * It is recommended to upgrade the version of @guardian/cdk being used in two steps:\n * 1. Bump the library, apply the tag updates\n * 2. Make any other stack changes\n *\n * Typical usage is to extend GuStack:\n *\n * ```typescript\n * class MyStack extends GuStack {\n * constructor(scope: App, id: string, props: GuStackProps) {\n * super(scope, id, props)\n * }\n *\n * // add resources here\n * }\n * ```\n */\nexport class GuStack extends Stack implements StackStageIdentity {\n public readonly stack: string;\n public readonly stage: string;\n public readonly app: string | undefined;\n public readonly riffRaffProjectName: string | undefined;\n\n /**\n * The repository name, if it can be determined from the context or the git remote origin url.\n * If it cannot be determined from either of these sources, it will be `undefined`.\n */\n public readonly repositoryName: string | undefined;\n\n /**\n * A helper function to add a tag to all resources in a stack.\n *\n * Note: tags will be listed in alphabetical order during synthesis.\n *\n * @param key the tag name\n * @param value the value of the tag\n * @param applyToLaunchedInstances whether or not to apply the tag to instances launched in an ASG.\n * @protected\n */\n protected addTag(key: string, value: string, applyToLaunchedInstances: boolean = true): void {\n // TODO add validation for `key` and `value`\n // see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-resource-tags.html\n Tags.of(this).add(key, value, { applyToLaunchedInstances });\n }\n\n /**\n * Returns all the parameters on this stack.\n *\n * @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html\n */\n get parameters(): Record<string, CfnParameter> {\n return this.node\n .findAll()\n .filter((construct) => construct instanceof CfnParameter)\n .reduce((acc, param) => ({ ...acc, [param.node.id]: param as CfnParameter }), {});\n }\n\n // eslint-disable-next-line custom-rules/valid-constructors -- GuStack is the exception as it must take an App\n constructor(scope: App, id: string, props: GuStackProps) {\n const {\n cloudFormationStackName = process.env.GU_CFN_STACK_NAME,\n stack,\n stage,\n app,\n riffRaffProjectName,\n withoutTags,\n } = props;\n\n super(scope, id, {\n ...props,\n stackName: cloudFormationStackName,\n\n // TODO Use `DefaultStackSynthesizer` or create own synthesizer?\n // see https://docs.aws.amazon.com/cdk/v2/guide/bootstrapping.html#bootstrapping-custom-synth\n synthesizer: new LegacyStackSynthesizer(),\n });\n\n this.stack = stack;\n this.stage = stage.toUpperCase();\n this.app = app;\n this.riffRaffProjectName = riffRaffProjectName;\n this.repositoryName = this.tryGetRepositoryTag();\n\n if (!withoutTags) {\n this.addTag(TrackingTag.Key, TrackingTag.Value);\n\n this.addTag(\"Stack\", this.stack);\n this.addTag(\"Stage\", this.stage);\n if (this.app) {\n this.addTag(\"App\", this.app);\n }\n\n if (this.riffRaffProjectName) {\n this.addTag(\"gu:riff-raff-project\", this.riffRaffProjectName);\n }\n\n if (this.repositoryName) {\n this.addTag(MetadataKeys.REPOSITORY_NAME, this.repositoryName);\n }\n }\n\n if (!props.withoutMetadata) {\n Aspects.of(this).add(new Metadata(this));\n }\n\n Aspects.of(this).add(new CfnIncludeReporter());\n Aspects.of(this).add(new CfnParameterReporter());\n }\n\n /**\n * Returns the repository name.\n * The value is retrieved in the following order:\n * 1. From the context\n * 2. From git config\n *\n * @private\n */\n private tryGetRepositoryTag(): string | undefined {\n try {\n const urlFromContext = this.node.tryGetContext(ContextKeys.REPOSITORY_URL) as string | undefined;\n const repositoryUrl: string = urlFromContext ?? gitRemoteOriginUrl();\n return gitUrlParse(repositoryUrl).full_name;\n } catch {\n console.info(\n `Unable to find git repository name. Set the ${ContextKeys.REPOSITORY_URL} context value or configure a git remote`,\n );\n return undefined;\n }\n }\n\n /**\n * Override the auto-generated logical ID for a resource, in the generated CloudFormation template, with a static one.\n *\n * Of particular use when migrating a JSON/YAML CloudFormation template into GuCDK.\n * It's generally advised to retain the logical ID for stateful resources, such as databases or buckets.\n *\n * Let's say we have a YAML template:\n *\n * ```yaml\n * AWSTemplateFormatVersion: '2010-09-09'\n * Resources:\n * UsesTable:\n * Type: AWS::DynamoDB::Table\n * Properties:\n * TableName: !Sub 'users-${stage}'\n * ```\n *\n * When moving to GuCDK we'll have this:\n *\n * class MyStack extends GuStack {\n * constructor(app: App, id: string, props: GuStackProps) {\n * super(app, id, props);\n *\n * const { stage } = this;\n *\n * new Table(this, \"UsersTable\", {\n * name: `users-${stage}`\n * });\n * }\n * }\n *\n * During synthesis, CDK auto-generates logical IDs, so we'll have a stack with a DynamoDB table named 'UsersTable<SOME GUID>', NOT `UsersTable`.\n * That is, the `UsersTable` table will be deleted.\n *\n * In order to retain the original ID from the YAML template, we will do:\n *\n * class MyStack extends GuStack {\n * constructor(app: App, id: string, props: GuStackProps) {\n * super(app, id, props);\n *\n * const { stage } = this;\n *\n * const table = new Table(this, \"UsersTable\", {\n * name: `users-${stage}`\n * });\n *\n * this.overrideLogicalId(table, { logicalId: \"UsersTable\", reason: \"Retaining a stateful resource from the YAML template\" });\n * }\n * }\n *\n * @param construct The (stateful) resource to retain the logical ID of.\n * @param logicalId The logical ID of the resource (as defined in the JSON/YAML template.\n * @param reason A small explanation to keep the logical ID. Mainly used to help future developers.\n */\n public overrideLogicalId(construct: IConstruct, { logicalId, reason }: GuStaticLogicalId): void {\n const {\n node: { id, defaultChild },\n } = construct;\n\n (defaultChild as CfnElement).overrideLogicalId(logicalId);\n Annotations.of(construct).addInfo(`Setting logical ID for ${id} to ${logicalId}. Reason: ${reason}`);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"stack.js","sourceRoot":"","sources":["../../../src/constructs/core/stack.ts"],"names":[],"mappings":";;;;;;AACA,6CAAsG;AAEtG,kEAAwC;AACxC,6EAAwE;AACxE,iFAA4E;AAC5E,qDAAkD;AAClD,+CAAyE;AACzE,yCAAqD;AAkDrD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAa,OAAQ,SAAQ,mBAAK;IAYhC;;;;;;;;;OASG;IACO,MAAM,CAAC,GAAW,EAAE,KAAa,EAAE,2BAAoC,IAAI;QACnF,4CAA4C;QAC5C,wGAAwG;QACxG,kBAAI,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,wBAAwB,EAAE,CAAC,CAAC;IAC9D,CAAC;IAED;;;;OAIG;IACH,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,IAAI;aACb,OAAO,EAAE;aACT,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,YAAY,0BAAY,CAAC;aACxD,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,GA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AC,0BAA0B,EAAE,OAAO,SAAS,aAAa,MAAM,EAAE,CAAC,CAAC;IACvG,CAAC;CACF;AA/KD,0BA+KC","sourcesContent":["import type { App, CfnElement, StackProps } from \"aws-cdk-lib\";\nimport { Annotations, Aspects, CfnParameter, LegacyStackSynthesizer, Stack, Tags } from \"aws-cdk-lib\";\nimport type { IConstruct } from \"constructs\";\nimport gitUrlParse from \"git-url-parse\";\nimport { CfnIncludeReporter } from \"../../aspects/cfn-include-reporter\";\nimport { CfnParameterReporter } from \"../../aspects/cfn-parameter-reporter\";\nimport { Metadata } from \"../../aspects/metadata\";\nimport { ContextKeys, MetadataKeys, TrackingTag } from \"../../constants\";\nimport { gitRemoteOriginUrl } from \"../../utils/git\";\nimport type { StackStageIdentity } from \"./identity\";\nimport type { GuStaticLogicalId } from \"./migrating\";\n\nexport interface GuStackProps extends Omit<StackProps, \"stackName\"> {\n /**\n * The Guardian stack being used (as defined in your riff-raff.yaml).\n * This will be applied as a tag to all of your resources.\n */\n stack: string;\n\n /**\n * The stage being used (as defined in your riff-raff.yaml).\n * This will be applied as a tag to all of your resources.\n */\n stage: string;\n\n /**\n * Optional name of the app. If defined, all resources will have an App tag.\n */\n app?: string;\n\n /**\n * The name of the Riff-Raff project used to deploy these resources.\n * Used as the value of the `gu:riff-raff-project` tag on all resources.\n * If using {@link GuRoot} or {@link RiffRaffYamlFile}, this value is also used in the location of the generated `riff-raff.yaml`.\n *\n * @see https://github.com/guardian/riffraff-platform\n */\n riffRaffProjectName?: string;\n\n /**\n * The AWS CloudFormation stack name (as shown in the AWS CloudFormation UI).\n * @defaultValue the `GU_CFN_STACK_NAME` environment variable\n */\n cloudFormationStackName?: string;\n /**\n * Set this to true to stop the GuStack from tagging all of your AWS resources.\n * This should only be turned on as part of an initial migration from CloudFormation.\n */\n withoutTags?: boolean;\n\n /**\n * Set to disable CDK metadata. Only for internal use (for disabling for some\n * snapshot tests). We rely on tracking data to prioritise future work so\n * please do not override this.\n */\n withoutMetadata?: boolean;\n}\n\n/**\n * GuStack provides the `stack` and `stage` parameters to a template.\n * It also takes the `app` in the constructor.\n *\n * GuStack will add the Stack, Stage and App tags to all resources.\n *\n * GuStack also adds the tag `X-Gu-CDK-Version`.\n * This tag allows us to measure adoption of this library.\n * It's value is the version of guardian/cdk being used, as defined in `package.json`.\n * As a result, the change sets between version numbers will be fairly noisy,\n * as all resources receive a tag update.\n * It is recommended to upgrade the version of @guardian/cdk being used in two steps:\n * 1. Bump the library, apply the tag updates\n * 2. Make any other stack changes\n *\n * Typical usage is to extend GuStack:\n *\n * ```typescript\n * class MyStack extends GuStack {\n * constructor(scope: App, id: string, props: GuStackProps) {\n * super(scope, id, props)\n * }\n *\n * // add resources here\n * }\n * ```\n */\nexport class GuStack extends Stack implements StackStageIdentity {\n public readonly stack: string;\n public readonly stage: string;\n public readonly app: string | undefined;\n public readonly riffRaffProjectName: string | undefined;\n\n /**\n * The repository name, if it can be determined from the context or the git remote origin url.\n * If it cannot be determined from either of these sources, it will be `undefined`.\n */\n public readonly repositoryName: string | undefined;\n\n /**\n * A helper function to add a tag to all resources in a stack.\n *\n * Note: tags will be listed in alphabetical order during synthesis.\n *\n * @param key the tag name\n * @param value the value of the tag\n * @param applyToLaunchedInstances whether or not to apply the tag to instances launched in an ASG.\n * @protected\n */\n protected addTag(key: string, value: string, applyToLaunchedInstances: boolean = true): void {\n // TODO add validation for `key` and `value`\n // see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-resource-tags.html\n Tags.of(this).add(key, value, { applyToLaunchedInstances });\n }\n\n /**\n * Returns all the parameters on this stack.\n *\n * @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html\n */\n get parameters(): Record<string, CfnParameter> {\n return this.node\n .findAll()\n .filter((construct) => construct instanceof CfnParameter)\n .reduce((acc, param) => ({ ...acc, [param.node.id]: param as CfnParameter }), {});\n }\n\n // eslint-disable-next-line custom-rules/valid-constructors -- GuStack is the exception as it must take an App\n constructor(scope: App, id: string, props: GuStackProps) {\n const {\n cloudFormationStackName = process.env.GU_CFN_STACK_NAME,\n stack,\n stage,\n app,\n riffRaffProjectName,\n withoutTags,\n } = props;\n\n super(scope, id, {\n ...props,\n stackName: cloudFormationStackName,\n\n // TODO Use `DefaultStackSynthesizer` or create own synthesizer?\n // see https://docs.aws.amazon.com/cdk/v2/guide/bootstrapping.html#bootstrapping-custom-synth\n synthesizer: new LegacyStackSynthesizer(),\n });\n\n this.stack = stack;\n this.stage = stage.toUpperCase();\n this.app = app;\n this.riffRaffProjectName = riffRaffProjectName;\n this.repositoryName = this.tryGetRepositoryTag();\n\n if (!withoutTags) {\n this.addTag(TrackingTag.Key, TrackingTag.Value);\n\n this.addTag(\"Stack\", this.stack);\n this.addTag(\"Stage\", this.stage);\n if (this.app) {\n this.addTag(\"App\", this.app);\n }\n\n if (this.riffRaffProjectName) {\n this.addTag(\"gu:riff-raff:project\", this.riffRaffProjectName);\n }\n\n if (this.repositoryName) {\n this.addTag(MetadataKeys.REPOSITORY_NAME, this.repositoryName);\n }\n }\n\n if (!props.withoutMetadata) {\n Aspects.of(this).add(new Metadata(this));\n }\n\n Aspects.of(this).add(new CfnIncludeReporter());\n Aspects.of(this).add(new CfnParameterReporter());\n }\n\n /**\n * Returns the repository name.\n * The value is retrieved in the following order:\n * 1. From the context\n * 2. From git config\n *\n * @private\n */\n private tryGetRepositoryTag(): string | undefined {\n try {\n const urlFromContext = this.node.tryGetContext(ContextKeys.REPOSITORY_URL) as string | undefined;\n const repositoryUrl: string = urlFromContext ?? gitRemoteOriginUrl();\n return gitUrlParse(repositoryUrl).full_name;\n } catch {\n console.info(\n `Unable to find git repository name. Set the ${ContextKeys.REPOSITORY_URL} context value or configure a git remote`,\n );\n return undefined;\n }\n }\n\n /**\n * Override the auto-generated logical ID for a resource, in the generated CloudFormation template, with a static one.\n *\n * Of particular use when migrating a JSON/YAML CloudFormation template into GuCDK.\n * It's generally advised to retain the logical ID for stateful resources, such as databases or buckets.\n *\n * Let's say we have a YAML template:\n *\n * ```yaml\n * AWSTemplateFormatVersion: '2010-09-09'\n * Resources:\n * UsesTable:\n * Type: AWS::DynamoDB::Table\n * Properties:\n * TableName: !Sub 'users-${stage}'\n * ```\n *\n * When moving to GuCDK we'll have this:\n *\n * class MyStack extends GuStack {\n * constructor(app: App, id: string, props: GuStackProps) {\n * super(app, id, props);\n *\n * const { stage } = this;\n *\n * new Table(this, \"UsersTable\", {\n * name: `users-${stage}`\n * });\n * }\n * }\n *\n * During synthesis, CDK auto-generates logical IDs, so we'll have a stack with a DynamoDB table named 'UsersTable<SOME GUID>', NOT `UsersTable`.\n * That is, the `UsersTable` table will be deleted.\n *\n * In order to retain the original ID from the YAML template, we will do:\n *\n * class MyStack extends GuStack {\n * constructor(app: App, id: string, props: GuStackProps) {\n * super(app, id, props);\n *\n * const { stage } = this;\n *\n * const table = new Table(this, \"UsersTable\", {\n * name: `users-${stage}`\n * });\n *\n * this.overrideLogicalId(table, { logicalId: \"UsersTable\", reason: \"Retaining a stateful resource from the YAML template\" });\n * }\n * }\n *\n * @param construct The (stateful) resource to retain the logical ID of.\n * @param logicalId The logical ID of the resource (as defined in the JSON/YAML template.\n * @param reason A small explanation to keep the logical ID. Mainly used to help future developers.\n */\n public overrideLogicalId(construct: IConstruct, { logicalId, reason }: GuStaticLogicalId): void {\n const {\n node: { id, defaultChild },\n } = construct;\n\n (defaultChild as CfnElement).overrideLogicalId(logicalId);\n Annotations.of(construct).addInfo(`Setting logical ID for ${id} to ${logicalId}. Reason: ${reason}`);\n }\n}\n"]}
|
|
@@ -26,8 +26,8 @@ declare const GuApplicationListener_base: {
|
|
|
26
26
|
export declare class GuApplicationListener extends GuApplicationListener_base {
|
|
27
27
|
constructor(scope: GuStack, id: string, props: GuApplicationListenerProps);
|
|
28
28
|
}
|
|
29
|
-
export interface GuHttpsApplicationListenerProps extends Omit<GuApplicationListenerProps, "
|
|
30
|
-
targetGroup
|
|
29
|
+
export interface GuHttpsApplicationListenerProps extends Omit<GuApplicationListenerProps, "certificates">, AppIdentity {
|
|
30
|
+
targetGroup?: GuApplicationTargetGroup;
|
|
31
31
|
certificate?: GuCertificate;
|
|
32
32
|
}
|
|
33
33
|
declare const GuHttpsApplicationListener_base: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"application-listener.d.ts","sourceRoot":"","sources":["../../../../src/constructs/loadbalancing/alb/application-listener.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EAIpB,MAAM,wCAAwC,CAAC;AAChD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAEvF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAE3E,MAAM,WAAW,0BAA2B,SAAQ,wBAAwB,EAAE,WAAW;CAAG;;;;;;AAE5F;;;;;;;;;;;;GAYG;AACH,qBAAa,qBAAsB,SAAQ,0BAAwC;gBACrE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,0BAA0B;CAG1E;AAED,MAAM,WAAW,+
|
|
1
|
+
{"version":3,"file":"application-listener.d.ts","sourceRoot":"","sources":["../../../../src/constructs/loadbalancing/alb/application-listener.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EAIpB,MAAM,wCAAwC,CAAC;AAChD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAEvF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAE3E,MAAM,WAAW,0BAA2B,SAAQ,wBAAwB,EAAE,WAAW;CAAG;;;;;;AAE5F;;;;;;;;;;;;GAYG;AACH,qBAAa,qBAAsB,SAAQ,0BAAwC;gBACrE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,0BAA0B;CAG1E;AAED,MAAM,WAAW,+BAAgC,SAAQ,IAAI,CAAC,0BAA0B,EAAE,cAAc,CAAC,EAAE,WAAW;IACpH,WAAW,CAAC,EAAE,wBAAwB,CAAC;IACvC,WAAW,CAAC,EAAE,aAAa,CAAC;CAC7B;;;;;;AAED;;;;;;GAMG;AACH,qBAAa,0BAA2B,SAAQ,+BAAwC;gBAC1E,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,+BAA+B;CAoB/E"}
|
|
@@ -44,7 +44,7 @@ class GuHttpsApplicationListener extends (0, app_aware_construct_1.GuAppAwareCon
|
|
|
44
44
|
},
|
|
45
45
|
]
|
|
46
46
|
: [],
|
|
47
|
-
defaultAction: aws_elasticloadbalancingv2_1.ListenerAction.forward([targetGroup]),
|
|
47
|
+
defaultAction: targetGroup ? aws_elasticloadbalancingv2_1.ListenerAction.forward([targetGroup]) : props.defaultAction,
|
|
48
48
|
};
|
|
49
49
|
super(scope, id, mergedProps);
|
|
50
50
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"application-listener.js","sourceRoot":"","sources":["../../../../src/constructs/loadbalancing/alb/application-listener.ts"],"names":[],"mappings":";;;AAAA,uFAKgD;AAEhD,kFAA+E;AAO/E;;;;;;;;;;;;GAYG;AACH,MAAa,qBAAsB,SAAQ,IAAA,yCAAmB,EAAC,gDAAmB,CAAC;IACjF,YAAY,KAAc,EAAE,EAAU,EAAE,KAAiC;QACvE,KAAK,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,gDAAmB,CAAC,KAAK,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;IACjF,CAAC;CACF;AAJD,sDAIC;
|
|
1
|
+
{"version":3,"file":"application-listener.js","sourceRoot":"","sources":["../../../../src/constructs/loadbalancing/alb/application-listener.ts"],"names":[],"mappings":";;;AAAA,uFAKgD;AAEhD,kFAA+E;AAO/E;;;;;;;;;;;;GAYG;AACH,MAAa,qBAAsB,SAAQ,IAAA,yCAAmB,EAAC,gDAAmB,CAAC;IACjF,YAAY,KAAc,EAAE,EAAU,EAAE,KAAiC;QACvE,KAAK,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,gDAAmB,CAAC,KAAK,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;IACjF,CAAC;CACF;AAJD,sDAIC;AAOD;;;;;;GAMG;AACH,MAAa,0BAA2B,SAAQ,IAAA,yCAAmB,EAAC,gDAAmB,CAAC;IACtF,YAAY,KAAc,EAAE,EAAU,EAAE,KAAsC;QAC5E,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC;QAE3C,MAAM,WAAW,GAA+B;YAC9C,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI;YAC9B,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC,gDAAmB,CAAC,KAAK,CAAC,CAAC,CAAC,gDAAmB,CAAC,IAAI;YAC5E,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC,sCAAS,CAAC,eAAe,CAAC,CAAC,CAAC,SAAS;YAC9D,GAAG,KAAK;YACR,YAAY,EAAE,WAAW;gBACvB,CAAC,CAAC;oBACE;wBACE,cAAc,EAAE,WAAW,CAAC,cAAc;qBAC3C;iBACF;gBACH,CAAC,CAAC,EAAE;YACN,aAAa,EAAE,WAAW,CAAC,CAAC,CAAC,2CAAc,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,aAAa;SACzF,CAAC;QAEF,KAAK,CAAC,KAAK,EAAE,EAAE,EAAE,WAAW,CAAC,CAAC;IAChC,CAAC;CACF;AArBD,gEAqBC","sourcesContent":["import {\n ApplicationListener,\n ApplicationProtocol,\n ListenerAction,\n SslPolicy,\n} from \"aws-cdk-lib/aws-elasticloadbalancingv2\";\nimport type { ApplicationListenerProps } from \"aws-cdk-lib/aws-elasticloadbalancingv2\";\nimport { GuAppAwareConstruct } from \"../../../utils/mixin/app-aware-construct\";\nimport type { GuCertificate } from \"../../acm\";\nimport type { AppIdentity, GuStack } from \"../../core\";\nimport type { GuApplicationTargetGroup } from \"./application-target-group\";\n\nexport interface GuApplicationListenerProps extends ApplicationListenerProps, AppIdentity {}\n\n/**\n * Construct which creates a Listener.\n *\n * This construct should be used in conjunction with [[`GuApplicationLoadBalancer`]] and [[`GuApplicationTargetGroup`]]\n * to route traffic to your application. For more details on these three components, see the\n * [AWS documentation](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html#application-load-balancer-components).\n *\n * If you are running an application which only accepts traffic over HTTPS, consider using [[`GuHttpsApplicationListener`]]\n * to reduce the amount of boilerplate needed when configuring your Listener.\n *\n * This resource is stateful.\n * @see https://github.com/guardian/cdk/blob/main/docs/stateful-resources.md\n */\nexport class GuApplicationListener extends GuAppAwareConstruct(ApplicationListener) {\n constructor(scope: GuStack, id: string, props: GuApplicationListenerProps) {\n super(scope, id, { port: 443, protocol: ApplicationProtocol.HTTPS, ...props });\n }\n}\n\nexport interface GuHttpsApplicationListenerProps extends Omit<GuApplicationListenerProps, \"certificates\">, AppIdentity {\n targetGroup?: GuApplicationTargetGroup;\n certificate?: GuCertificate;\n}\n\n/**\n * Construct which creates a Listener which accepts HTTPS traffic.\n *\n * You must pass a [[`GuCertificate`]] to this Listener via the `certificate` prop.\n *\n * For general details about Listeners, see [[`GuApplicationListener`]].\n */\nexport class GuHttpsApplicationListener extends GuAppAwareConstruct(ApplicationListener) {\n constructor(scope: GuStack, id: string, props: GuHttpsApplicationListenerProps) {\n const { certificate, targetGroup } = props;\n\n const mergedProps: GuApplicationListenerProps = {\n port: certificate ? 443 : 8080,\n protocol: certificate ? ApplicationProtocol.HTTPS : ApplicationProtocol.HTTP,\n sslPolicy: certificate ? SslPolicy.RECOMMENDED_TLS : undefined,\n ...props,\n certificates: certificate\n ? [\n {\n certificateArn: certificate.certificateArn,\n },\n ]\n : [],\n defaultAction: targetGroup ? ListenerAction.forward([targetGroup]) : props.defaultAction,\n };\n\n super(scope, id, mergedProps);\n }\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CfnParameter } from "aws-cdk-lib";
|
|
2
|
+
import type { GuStack } from "../../constructs/core";
|
|
3
|
+
export declare class GuRiffRaffDeploymentIdParameterExperimental extends CfnParameter {
|
|
4
|
+
private static instance;
|
|
5
|
+
private constructor();
|
|
6
|
+
static getInstance(stack: GuStack): GuRiffRaffDeploymentIdParameterExperimental;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=riff-raff-deployment-id.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"riff-raff-deployment-id.d.ts","sourceRoot":"","sources":["../../../src/experimental/constructs/riff-raff-deployment-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAGrD,qBAAa,2CAA4C,SAAQ,YAAY;IAC3E,OAAO,CAAC,MAAM,CAAC,QAAQ,CAA0D;IAEjF,OAAO;WAOO,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,2CAA2C;CAOvF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GuRiffRaffDeploymentIdParameterExperimental = void 0;
|
|
4
|
+
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
|
5
|
+
const singleton_1 = require("../../utils/singleton");
|
|
6
|
+
class GuRiffRaffDeploymentIdParameterExperimental extends aws_cdk_lib_1.CfnParameter {
|
|
7
|
+
constructor(scope) {
|
|
8
|
+
super(scope, "RiffRaffDeploymentId", {
|
|
9
|
+
type: "String",
|
|
10
|
+
description: "Used by Riff-Raff to inject the deployment ID.",
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
static getInstance(stack) {
|
|
14
|
+
if (!this.instance || !(0, singleton_1.isSingletonPresentInStack)(stack, this.instance)) {
|
|
15
|
+
this.instance = new GuRiffRaffDeploymentIdParameterExperimental(stack);
|
|
16
|
+
}
|
|
17
|
+
return this.instance;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.GuRiffRaffDeploymentIdParameterExperimental = GuRiffRaffDeploymentIdParameterExperimental;
|
|
21
|
+
//# sourceMappingURL=riff-raff-deployment-id.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"riff-raff-deployment-id.js","sourceRoot":"","sources":["../../../src/experimental/constructs/riff-raff-deployment-id.ts"],"names":[],"mappings":";;;AAAA,6CAA2C;AAE3C,qDAAkE;AAElE,MAAa,2CAA4C,SAAQ,0BAAY;IAG3E,YAAoB,KAAc;QAChC,KAAK,CAAC,KAAK,EAAE,sBAAsB,EAAE;YACnC,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,gDAAgD;SAC9D,CAAC,CAAC;IACL,CAAC;IAEM,MAAM,CAAC,WAAW,CAAC,KAAc;QACtC,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAA,qCAAyB,EAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE;YACtE,IAAI,CAAC,QAAQ,GAAG,IAAI,2CAA2C,CAAC,KAAK,CAAC,CAAC;SACxE;QAED,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;CACF;AAjBD,kGAiBC","sourcesContent":["import { CfnParameter } from \"aws-cdk-lib\";\nimport type { GuStack } from \"../../constructs/core\";\nimport { isSingletonPresentInStack } from \"../../utils/singleton\";\n\nexport class GuRiffRaffDeploymentIdParameterExperimental extends CfnParameter {\n private static instance: GuRiffRaffDeploymentIdParameterExperimental | undefined;\n\n private constructor(scope: GuStack) {\n super(scope, \"RiffRaffDeploymentId\", {\n type: \"String\",\n description: \"Used by Riff-Raff to inject the deployment ID.\",\n });\n }\n\n public static getInstance(stack: GuStack): GuRiffRaffDeploymentIdParameterExperimental {\n if (!this.instance || !isSingletonPresentInStack(stack, this.instance)) {\n this.instance = new GuRiffRaffDeploymentIdParameterExperimental(stack);\n }\n\n return this.instance;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ec2-app.d.ts","sourceRoot":"","sources":["../../../src/experimental/patterns/ec2-app.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAW,YAAY,EAAE,QAAQ,EAAQ,MAAM,aAAa,CAAC;AACpE,OAAO,EAAyD,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAGlH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC/E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"ec2-app.d.ts","sourceRoot":"","sources":["../../../src/experimental/patterns/ec2-app.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAW,YAAY,EAAE,QAAQ,EAAQ,MAAM,aAAa,CAAC;AACpE,OA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B,GAAE,QAA8B;CAmCpD;AAED,MAAM,WAAW,uCAAuC;IACtD,gBAAgB,EAAE,kBAAkB,CAAC;CACtC;AAED;;;;;;;;GAQG;AACH,qBAAa,kCAAkC;gBACjC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,uCAAuC;CAU3E;AAED,MAAM,WAAW,2CAA2C;IAC1D,gBAAgB,EAAE,kBAAkB,CAAC;IACrC,WAAW,EAAE,wBAAwB,CAAC;IACtC,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,CAAC,EAAE,QAAQ,CAAC;CAC9B;AAED;;;;;;;;GAQG;AACH,qBAAa,sCAAsC;gBACrC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,2CAA2C;CAoF/E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,qBAAa,oBAAqB,SAAQ,QAAQ;gBACpC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,yBAAyB;CAuD7D"}
|
|
@@ -9,6 +9,7 @@ const autoscaling_1 = require("../../constructs/autoscaling");
|
|
|
9
9
|
const core_1 = require("../../constructs/core");
|
|
10
10
|
const patterns_1 = require("../../patterns");
|
|
11
11
|
const singleton_1 = require("../../utils/singleton");
|
|
12
|
+
const riff_raff_deployment_id_1 = require("../constructs/riff-raff-deployment-id");
|
|
12
13
|
exports.RollingUpdateDurations = {
|
|
13
14
|
sleep: aws_cdk_lib_1.Duration.seconds(5),
|
|
14
15
|
buffer: aws_cdk_lib_1.Duration.minutes(1),
|
|
@@ -248,20 +249,6 @@ class GuRoleForRollingUpdateExperimental {
|
|
|
248
249
|
}
|
|
249
250
|
}
|
|
250
251
|
exports.GuRoleForRollingUpdateExperimental = GuRoleForRollingUpdateExperimental;
|
|
251
|
-
class GuRiffRaffDeploymentIdParameter extends aws_cdk_lib_1.CfnParameter {
|
|
252
|
-
constructor(scope) {
|
|
253
|
-
super(scope, "RiffRaffDeploymentId", {
|
|
254
|
-
type: "String",
|
|
255
|
-
description: "Used by Riff-Raff to inject the deployment ID.",
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
static getInstance(stack) {
|
|
259
|
-
if (!this.instance || !(0, singleton_1.isSingletonPresentInStack)(stack, this.instance)) {
|
|
260
|
-
this.instance = new GuRiffRaffDeploymentIdParameter(stack);
|
|
261
|
-
}
|
|
262
|
-
return this.instance;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
252
|
/**
|
|
266
253
|
* Modifies the user-data script (which runs whenever an instance is launched) to make it compatible with the new
|
|
267
254
|
* rolling update deployment mechanism.
|
|
@@ -276,7 +263,7 @@ class GuUserDataForRollingUpdateExperimental {
|
|
|
276
263
|
const { region, stackId } = scope;
|
|
277
264
|
const { autoScalingGroup, targetGroup, applicationPort, buildIdentifier, slowStartDuration } = props;
|
|
278
265
|
const cfnAutoScalingGroup = autoScalingGroup.node.defaultChild;
|
|
279
|
-
const deploymentId =
|
|
266
|
+
const deploymentId = riff_raff_deployment_id_1.GuRiffRaffDeploymentIdParameterExperimental.getInstance(scope);
|
|
280
267
|
// This allows redeployment of the same build to cycle instances
|
|
281
268
|
autoScalingGroup.userData.addCommands(`echo "Launch template last updated by Riff-Raff deployment ID: ${deploymentId.valueAsString}"`);
|
|
282
269
|
/*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ec2-app.js","sourceRoot":"","sources":["../../../src/experimental/patterns/ec2-app.ts"],"names":[],"mappings":";;;AACA,6CAAoE;AACpE,iEAAkH;AAElH,iDAAsE;AAEtE,+CAA+C;AAC/C,8DAAkE;AAClE,gDAAgD;AAGhD,6CAA0C;AAC1C,qDAAkE;AAcrD,QAAA,sBAAsB,GAAsC;IACvE,KAAK,EAAE,sBAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;IAC1B,MAAM,EAAE,sBAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;CAC5B,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;A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AE,CAAC,CAAC;IACrF,CAAC;CACF;AAxDD,oDAwDC","sourcesContent":["import type { IAspect } from \"aws-cdk-lib\";\nimport { Aspects, CfnParameter, Duration, Tags } from \"aws-cdk-lib\";\nimport { CfnAutoScalingGroup, CfnScalingPolicy, ScalingProcess, UpdatePolicy } from \"aws-cdk-lib/aws-autoscaling\";\nimport type { CfnPolicy } from \"aws-cdk-lib/aws-iam\";\nimport { Effect, Policy, PolicyStatement } from \"aws-cdk-lib/aws-iam\";\nimport type { IConstruct } from \"constructs\";\nimport { MetadataKeys } from \"../../constants\";\nimport { GuAutoScalingGroup } from \"../../constructs/autoscaling\";\nimport { GuStack } from \"../../constructs/core\";\nimport type { GuApplicationTargetGroup } from \"../../constructs/loadbalancing\";\nimport type { GuEc2AppProps } from \"../../patterns\";\nimport { GuEc2App } from \"../../patterns\";\nimport { isSingletonPresentInStack } from \"../../utils/singleton\";\n\ninterface AutoScalingRollingUpdateDurations {\n /**\n * The time between each check of an instance's health within the target group.\n */\n sleep: Duration;\n\n /**\n * Additional time to cover the time spent polling an instance's health within the target group before sending the CloudFormation signal.\n */\n buffer: Duration;\n}\n\nexport const RollingUpdateDurations: AutoScalingRollingUpdateDurations = {\n sleep: Duration.seconds(5),\n buffer: Duration.minutes(1),\n};\n\n/**\n * Ensures the `AutoScalingRollingUpdate` of an AutoScaling Group has a `PauseTime` matching the healthcheck grace period.\n * It also ensures the `CreationPolicy` resource signal `Timeout` matches the healthcheck grace period.\n *\n * @note\n * Be sure to instantiate this only once for an entire {@link GuStack}, else the properties of the ASG will be incorrectly updated multiple times.\n *\n * @internal\n *\n * @privateRemarks\n * The ASG healthcheck grace period is hard-coded by {@link GuEc2App}.\n * Customisation of this value is performed via an escape hatch.\n * An `Aspect` is the only way to observe any customisation.\n *\n * TODO Expose the healthcheck grace period as a property on {@link GuEc2App} and remove this `Aspect`.\n */\nexport class GuAutoScalingRollingUpdateTimeoutExperimental implements IAspect {\n public visit(construct: IConstruct) {\n if (construct instanceof CfnAutoScalingGroup) {\n const currentRollingUpdate = construct.cfnOptions.updatePolicy?.autoScalingRollingUpdate;\n const currentCreationPolicy = construct.cfnOptions.creationPolicy;\n\n if (!construct.healthCheckGracePeriod) {\n throw new Error(`The healthcheck grace period not set for autoscaling group ${construct.node.id}.`);\n }\n\n const signalTimeoutSeconds = construct.healthCheckGracePeriod + RollingUpdateDurations.buffer.toSeconds();\n\n if (currentRollingUpdate) {\n construct.cfnOptions.updatePolicy = {\n autoScalingRollingUpdate: {\n ...currentRollingUpdate,\n pauseTime: Duration.seconds(\n Duration.parse(currentRollingUpdate.pauseTime ?? \"0\").toSeconds() + signalTimeoutSeconds,\n ).toIsoString(),\n },\n };\n }\n\n if (currentCreationPolicy) {\n construct.cfnOptions.creationPolicy = {\n ...currentCreationPolicy,\n resourceSignal: {\n ...currentCreationPolicy.resourceSignal,\n timeout: Duration.seconds(signalTimeoutSeconds).toIsoString(),\n },\n };\n }\n }\n }\n}\n\n/**\n * An `Aspect` that adjusts the properties of an AutoScaling Group using an `AutoScalingRollingUpdate` update policy.\n *\n * It'll unset the `DesiredCapacity` of the ASG as a rolling update sets `Desired` back to the template version,\n * undoing any changes that a scale-out event may have done.\n * Having `DesiredCapacity` unset ensures the service remains at-capacity at all times.\n *\n * It'll also make the `MinInstancesInService` property dynamic via a CFN Parameter that Riff-Raff will set.\n * The value depends on the current capacity of the ASG:\n * - If the service is running normally, it'll be set to the `MinSize` capacity\n * - If the service is partially scaled, it'll be set to the current `DesiredCapacity`\n * - If the service is fully scaled, it'll be set to (at least) `MaxSize` - 1\n *\n * @privateRemarks\n * - Once out of experimental, instantiate this `Aspect` directly in {@link GuStack}.\n *\n * @see https://github.com/guardian/testing-asg-rolling-update\n */\nexport class GuHorizontallyScalingDeploymentPropertiesExperimental implements IAspect {\n public visit(construct: IConstruct) {\n if (CfnScalingPolicy.isCfnScalingPolicy(construct)) {\n const { node } = construct;\n const { scopes, path } = node;\n\n /*\n Requiring a `CfnScalingPolicy` to be created in the scope of a `GuAutoScalingGroup`\n is the most reliable way to associate the two together.\n\n Though the `autoScalingGroupName` property is passed to a `CfnScalingPolicy` when instantiating,\n this does not create a concrete link as AWS CDK sets the value to be the ASG's `Ref`.\n That is, it is a `Token` until it is synthesised.\n This is even if the ASG has an explicit name set.\n\n See also:\n - https://docs.aws.amazon.com/cdk/v2/guide/tokens.html\n - https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-autoscaling-autoscalinggroup.html#aws-resource-autoscaling-autoscalinggroup-return-values\n - https://github.com/aws/aws-cdk/blob/f6b649d47f8bc30ca741fbb7a4852d51e8275002/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts#L1560\n */\n const autoScalingGroup = scopes.find((_): _ is GuAutoScalingGroup => _ instanceof GuAutoScalingGroup);\n\n if (!autoScalingGroup) {\n throw new Error(\n `Failed to detect the autoscaling group relating to the scaling policy on path ${path}. Was it created in the scope of a GuAutoScalingGroup?`,\n );\n }\n\n const cfnAutoScalingGroup = autoScalingGroup.node.defaultChild as CfnAutoScalingGroup;\n const currentRollingUpdate = cfnAutoScalingGroup.cfnOptions.updatePolicy?.autoScalingRollingUpdate;\n\n if (currentRollingUpdate) {\n /*\n An autoscaling group that horizontally scales should not explicitly set `Desired`,\n as a rolling update will set the current `Desired` back to the template version,\n undoing any changes that a scale-out event may have done.\n */\n cfnAutoScalingGroup.desiredCapacity = undefined;\n\n const minInstancesInService = GuAsgMinInstancesInServiceParameterExperimental.getInstance(autoScalingGroup);\n\n cfnAutoScalingGroup.cfnOptions.updatePolicy = {\n autoScalingRollingUpdate: {\n ...currentRollingUpdate,\n minInstancesInService: minInstancesInService.valueAsNumber,\n },\n };\n }\n }\n }\n}\n\n/**\n * A CloudFormation parameter used to make the `MinInstancesInService` property of an ASG dynamic during deployment with Riff-Raff.\n * This shouldn't be instantiated directly, but via {@link GuHorizontallyScalingDeploymentPropertiesExperimental}.\n */\nexport class GuAsgMinInstancesInServiceParameterExperimental extends CfnParameter {\n public readonly asg: GuAutoScalingGroup;\n\n private constructor(scope: GuStack, id: string, autoScalingGroup: GuAutoScalingGroup) {\n super(scope, id, { type: \"Number\" });\n this.asg = autoScalingGroup;\n }\n\n public static getInstance(autoScalingGroup: GuAutoScalingGroup): GuAsgMinInstancesInServiceParameterExperimental {\n const stack = GuStack.of(autoScalingGroup) as GuStack;\n const { app } = autoScalingGroup;\n const id = `MinInstancesInServiceFor${app.replaceAll(\"-\", \"\")}`;\n\n const maybeParameter = stack.parameters[id];\n\n if (!maybeParameter) {\n return new GuAsgMinInstancesInServiceParameterExperimental(stack, id, autoScalingGroup);\n }\n\n // This shouldn't happen\n if (!(maybeParameter instanceof GuAsgMinInstancesInServiceParameterExperimental)) {\n throw new Error(\n `CFN parameter ${id} exists but is of type ${maybeParameter.constructor.name} instead of ${GuAsgMinInstancesInServiceParameterExperimental.name}.`,\n );\n }\n\n return maybeParameter;\n }\n}\n\n/**\n * An IAM Policy allowing the sending of a CloudFormation signal.\n *\n * @privateRemarks\n * Implemented as a singleton as the resources can only be tightened at most to the CloudFormation stack.\n */\nclass AsgRollingUpdatePolicy extends Policy {\n private static instance: AsgRollingUpdatePolicy | undefined;\n\n private constructor(scope: GuStack) {\n const { stackId } = scope;\n\n super(scope, \"AsgRollingUpdatePolicy\", {\n statements: [\n // Allow usage of command `cfn-signal`.\n new PolicyStatement({\n actions: [\"cloudformation:SignalResource\"],\n effect: Effect.ALLOW,\n resources: [stackId],\n }),\n\n /*\n Allow usage of command `aws elbv2 describe-target-health`.\n AWS Elastic Load Balancing does not support resource based policies, so the resource has to be `*` (any) here.\n See https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_aws-services-that-work-with-iam.html\n */\n new PolicyStatement({\n actions: [\"elasticloadbalancing:DescribeTargetHealth\"],\n effect: Effect.ALLOW,\n resources: [\"*\"],\n }),\n ],\n });\n }\n\n public static getInstance(stack: GuStack): AsgRollingUpdatePolicy {\n if (!this.instance || !isSingletonPresentInStack(stack, this.instance)) {\n this.instance = new AsgRollingUpdatePolicy(stack);\n }\n\n return this.instance;\n }\n}\n\nexport interface GuEc2AppExperimentalProps extends Omit<GuEc2AppProps, \"updatePolicy\"> {\n /**\n * Which application build to run.\n * This will typically match the build number provided by CI.\n *\n * @example\n * process.env.GITHUB_RUN_NUMBER\n */\n buildIdentifier: string;\n /**\n * The amount of time that newly launched instances will spend warming-up / serving fewer requests than other instances.\n * The range is 30-900 seconds (15 minutes). The default is 0 seconds (disabled).\n *\n * See https://docs.aws.amazon.com/elasticloadbalancing/latest/application/edit-target-group-attributes.html#slow-start-mode\n * for more details.\n *\n * We recommend enabling this setting if you run a high-traffic service, particularly if it is JVM-based.\n *\n * Note that there is a trade-off between reliability and speed here; a longer duration will give new instances\n * more time to warm-up, but it will also slow down deployments and scale-up events.\n */\n slowStartDuration?: Duration;\n}\n\n/**\n * Configures the rolling update policy for the autoscaling group.\n *\n * Most applications should not need to instantiate this class directly as this policy is set by GuEc2AppExperimental.\n *\n * If you need to use this class for a service other than MAPI, please speak to DevX about your use-case first.\n */\nexport class GuRollingUpdatePolicyExperimental {\n static getPolicy(\n maximumInstances: number,\n minimumInstances?: number,\n slowStartDuration: Duration = Duration.seconds(0),\n ) {\n return UpdatePolicy.rollingUpdate({\n maxBatchSize: maximumInstances,\n minInstancesInService: minimumInstances,\n minSuccessPercentage: 100,\n waitOnResourceSignals: true,\n /*\n All of these processes can launch and/or terminate instances and if this happens during a deployment it might\n cause the rolling update to fail: https://repost.aws/knowledge-center/auto-scaling-group-rolling-updates\n The full list of processes can be found here: https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-suspend-resume-processes.html#process-types\n */\n suspendProcesses: [\n ScalingProcess.ALARM_NOTIFICATION,\n ScalingProcess.AZ_REBALANCE,\n ScalingProcess.HEALTH_CHECK,\n ScalingProcess.INSTANCE_REFRESH,\n ScalingProcess.REPLACE_UNHEALTHY,\n ScalingProcess.SCHEDULED_ACTIONS,\n ],\n /*\n Note: this is increased via an Aspect which also takes healthcheck grace period into account.\n\n It was easier to pass the slow start duration through here rather than trying to do this via the\n GuAutoScalingRollingUpdateTimeoutExperimental aspect.\n\n If we do this via the aspect then we need to find all mappings between ASGs and target groups and then\n get the relevant slow start duration for each. This is probably possible but would be reasonably complex.\n However, it's worth mentioning that by taking this approach we open up a small risk that things will not work\n as expected if users enable slow start via a different mechanism (e.g. by modifying the target group outside\n the pattern).\n */\n pauseTime: slowStartDuration,\n });\n }\n}\n\nexport interface GuRoleForRollingUpdateExperimentalProps {\n autoScalingGroup: GuAutoScalingGroup;\n}\n\n/**\n * Grants the role associated with your autoscaling group the necessary permissions for the rolling update deployment\n * mechanism.\n *\n * Most applications should not need to instantiate this class directly as these permission changes are granted\n * by GuEc2AppExperimental.\n *\n * If you need to use this class for a service other than MAPI, please speak to DevX about your use-case first.\n */\nexport class GuRoleForRollingUpdateExperimental {\n constructor(scope: GuStack, props: GuRoleForRollingUpdateExperimentalProps) {\n const policy = AsgRollingUpdatePolicy.getInstance(scope);\n policy.attachToRole(props.autoScalingGroup.role);\n\n // Create the Policy with necessary permissions first.\n // Then create the ASG that requires the permissions.\n const cfnPolicy = policy.node.defaultChild as CfnPolicy;\n const cfnAutoScalingGroup = props.autoScalingGroup.node.defaultChild as CfnAutoScalingGroup;\n cfnAutoScalingGroup.addDependency(cfnPolicy);\n }\n}\n\nexport interface GuUserDataForRollingUpdateExperimentalProps {\n autoScalingGroup: GuAutoScalingGroup;\n targetGroup: GuApplicationTargetGroup;\n applicationPort: number;\n buildIdentifier: string;\n slowStartDuration?: Duration;\n}\n\nclass GuRiffRaffDeploymentIdParameter extends CfnParameter {\n private static instance: GuRiffRaffDeploymentIdParameter | undefined;\n\n private constructor(scope: GuStack) {\n super(scope, \"RiffRaffDeploymentId\", {\n type: \"String\",\n description: \"Used by Riff-Raff to inject the deployment ID.\",\n });\n }\n\n public static getInstance(stack: GuStack): GuRiffRaffDeploymentIdParameter {\n if (!this.instance || !isSingletonPresentInStack(stack, this.instance)) {\n this.instance = new GuRiffRaffDeploymentIdParameter(stack);\n }\n\n return this.instance;\n }\n}\n\n/**\n * Modifies the user-data script (which runs whenever an instance is launched) to make it compatible with the new\n * rolling update deployment mechanism.\n *\n * Most applications should not need to instantiate this class directly as these user-data changes are already made\n * by GuEc2AppExperimental.\n *\n * If you need to use this class for a service other than MAPI, please speak to DevX about your use-case first.\n */\nexport class GuUserDataForRollingUpdateExperimental {\n constructor(scope: GuStack, props: GuUserDataForRollingUpdateExperimentalProps) {\n const { region, stackId } = scope;\n const { autoScalingGroup, targetGroup, applicationPort, buildIdentifier, slowStartDuration } = props;\n const cfnAutoScalingGroup = autoScalingGroup.node.defaultChild as CfnAutoScalingGroup;\n\n const deploymentId = GuRiffRaffDeploymentIdParameter.getInstance(scope);\n\n // This allows redeployment of the same build to cycle instances\n autoScalingGroup.userData.addCommands(\n `echo \"Launch template last updated by Riff-Raff deployment ID: ${deploymentId.valueAsString}\"`,\n );\n\n /*\n `aws` is available via AMIgo baked AMIs.\n See https://github.com/guardian/amigo/tree/main/roles/aws-tools.\n */\n autoScalingGroup.userData.addCommands(\n `# ${GuEc2AppExperimental.name} Instance Health Check Start`,\n `\n TOKEN=$(curl -X PUT \"http://169.254.169.254/latest/api/token\" -H \"X-aws-ec2-metadata-token-ttl-seconds: 21600\")\n INSTANCE_ID=$(curl -H \"X-aws-ec2-metadata-token: $TOKEN\" \"http://169.254.169.254/latest/meta-data/instance-id\")\n\n STATE=$(aws elbv2 describe-target-health \\\n --target-group-arn ${targetGroup.targetGroupArn} \\\n --region ${region} \\\n --targets Id=$INSTANCE_ID,Port=${applicationPort} \\\n --query \"TargetHealthDescriptions[0].TargetHealth.State\")\n\n until [ \"$STATE\" == \"\\\\\"healthy\\\\\"\" ]; do\n echo \"Instance running build ${buildIdentifier} not yet healthy within target group. Current state $STATE. Sleeping...\"\n sleep ${RollingUpdateDurations.sleep.toSeconds()}\n STATE=$(aws elbv2 describe-target-health \\\n --target-group-arn ${targetGroup.targetGroupArn} \\\n --region ${region} \\\n --targets Id=$INSTANCE_ID,Port=${applicationPort} \\\n --query \"TargetHealthDescriptions[0].TargetHealth.State\")\n done\n\n echo \"Instance running build ${buildIdentifier} is healthy in target group.\"\n `,\n `# ${GuEc2AppExperimental.name} Instance Health Check End`,\n );\n\n if (slowStartDuration) {\n const slowStartInSeconds = slowStartDuration.toSeconds().toString();\n targetGroup.setAttribute(\"slow_start.duration_seconds\", slowStartInSeconds);\n autoScalingGroup.userData.addCommands(\n `# ${GuEc2AppExperimental.name} SlowStart Wait Period Start`,\n `\n echo \"Sleeping for ${slowStartInSeconds} seconds while instance running build ${buildIdentifier} warms up...\"\n sleep ${slowStartInSeconds}s\n echo \"Instance running build ${buildIdentifier} should have warmed up by now...\"\n\n STATE=$(aws elbv2 describe-target-health \\\n --target-group-arn ${targetGroup.targetGroupArn} \\\n --region ${region} \\\n --targets Id=$INSTANCE_ID,Port=${applicationPort} \\\n --query \"TargetHealthDescriptions[0].TargetHealth.State\")\n\n if [ \"$STATE\" == \"\\\\\"healthy\\\\\"\" ]; then\n echo \"Instance running build ${buildIdentifier} is ready to start serving a normal percentage of requests\"\n else\n echo \"Instance running build ${buildIdentifier} was not healthy after warm-up period; a failure signal will be sent\"\n exit 1\n fi\n `,\n `# ${GuEc2AppExperimental.name} SlowStart Wait Period End`,\n );\n }\n\n autoScalingGroup.userData.addOnExitCommands(\n `\n cfn-signal --stack ${stackId} \\\n --resource ${cfnAutoScalingGroup.logicalId} \\\n --region ${region} \\\n --exit-code $exitCode || echo 'Failed to send Cloudformation Signal'\n `,\n );\n\n // If https://github.com/guardian/devx-logs is used, this tag will be added as a marker to logs in Central ELK.\n Tags.of(autoScalingGroup.instanceLaunchTemplate).add(MetadataKeys.BUILD_IDENTIFIER, buildIdentifier, {\n applyToLaunchedInstances: true,\n });\n }\n}\n\n/**\n * An experimental pattern to instantiate an EC2 application that is updated entirely via CloudFormation.\n * It sets the update policy of the `AWS::AutoScaling::AutoScalingGroup` to `AutoScalingRollingUpdate`.\n * When a CloudFormation update is applied, the current instances in the ASG will be replaced.\n *\n * This pattern also updates the User Data, running some commands AFTER yours.\n * These changes are wrapped in start and end marking comments.\n *\n * This pattern does not enable for scaling events to trigger _during_ a deployment\n * as during testing it was found that scale-in events during deployment led to unpredictable service availability.\n *\n * If a deployment fails, for example when the healthcheck fails, CloudFormation will automatically rollback the changes.\n * This improves on the behaviour of Riff-Raff's `autoscaling` deployment which requires manual intervention on deployment failure.\n *\n * To update the application's code, a CloudFormation update must be triggered.\n * The best way to do this is to include the build number in the application artifact.\n * TODO test User Data includes a build number.\n *\n * @remarks\n * - The rate at which instances are replaced are conditional based on how scaled up the service is.\n * The more an application is scaled, the longer it'll take to deploy.\n * - It is not necessary to use the `autoscaling` Riff-Raff deployment type in conjunction with this.\n * Doing so won't break anything, however it'll lengthen the deployment time as instances will be rotated twice.\n * Please remove it from any manually created `riff-raff.yaml` file.\n * - Your application should include a build number in its filename.\n * This value will change across builds, and therefore create a CloudFormation template difference to be deployed.\n * - Requires the AWS CLI and `cfn-signal` binaries to be available on the instance, and on the `PATH`.\n * AMIgo adds these via the `aws-tools` role.\n *\n * @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-updatepolicy.html#cfn-attributes-updatepolicy-rollingupdate\n * @see https://github.com/guardian/testing-asg-rolling-update\n *\n * @experimental\n */\nexport class GuEc2AppExperimental extends GuEc2App {\n constructor(scope: GuStack, props: GuEc2AppExperimentalProps) {\n const { minimumInstances, maximumInstances = minimumInstances * 2 } = props.scaling;\n const { applicationPort, buildIdentifier, slowStartDuration } = props;\n\n const slowStartDurationInSeconds = slowStartDuration?.toSeconds();\n if (slowStartDurationInSeconds && (slowStartDurationInSeconds < 30 || slowStartDurationInSeconds > 900)) {\n throw new Error(\"Slow start duration must be between 30 and 900 seconds\");\n }\n\n super(scope, {\n ...props,\n // Note: if the service uses horizontal scaling, minimumInstances is overridden by an Aspect (to prevent accidental scale downs!)\n updatePolicy: GuRollingUpdatePolicyExperimental.getPolicy(maximumInstances, minimumInstances, slowStartDuration),\n });\n\n const { autoScalingGroup, targetGroup } = this;\n const cfnAutoScalingGroup = autoScalingGroup.node.defaultChild as CfnAutoScalingGroup;\n\n // Note: if the service uses horizontal scaling, this property is unset by an Aspect (to prevent accidental scale downs!)\n cfnAutoScalingGroup.desiredCapacity = minimumInstances.toString();\n\n // This is used when an ASG is first created; it is not needed to support the new deployment mechanism\n cfnAutoScalingGroup.cfnOptions.creationPolicy = {\n autoScalingCreationPolicy: {\n minSuccessfulInstancesPercent: 100,\n },\n resourceSignal: {\n count: minimumInstances,\n },\n };\n\n new GuRoleForRollingUpdateExperimental(scope, { autoScalingGroup });\n new GuUserDataForRollingUpdateExperimental(scope, {\n autoScalingGroup,\n targetGroup,\n applicationPort,\n buildIdentifier,\n slowStartDuration,\n });\n\n /*\n Instantiate the `GuAutoScalingRollingUpdateTimeoutExperimental` exactly once for a GuStack.\n Whilst multiple instances are syntactically valid, it will cause ASG nodes to be incorrectly evaluated/mutated multiple times.\n TODO Once out of experimental, instantiate these `Aspect`s directly in `GuStack`.\n */\n const allAspects = Aspects.of(scope).all;\n const maybeRollingUpdateTimeoutAspect = allAspects.find(\n (_) => _ instanceof GuAutoScalingRollingUpdateTimeoutExperimental,\n );\n if (!maybeRollingUpdateTimeoutAspect) {\n Aspects.of(scope).add(new GuAutoScalingRollingUpdateTimeoutExperimental());\n }\n\n Aspects.of(scope).add(new GuHorizontallyScalingDeploymentPropertiesExperimental());\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ec2-app.js","sourceRoot":"","sources":["../../../src/experimental/patterns/ec2-app.ts"],"names":[],"mappings":";;;AACA,6CAAoE;AACpE,iEAAkH;AAElH,iDAAsE;AAEtE,+CAA+C;AAC/C,8DAAkE;AAClE,gDAAgD;AAGhD,6CAA0C;AAC1C,qDAAkE;AAClE,mFAAoG;AAcvF,QAAA,sBAAsB,GAAsC;IACvE,KAAK,EAAE,sBAAQ,CAAC,OAAO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B,CAAC,IAAI,CAAC,YAAmC,CAAC;QAEtF,yHAAyH;QACzH,mBAAmB,CAAC,eAAe,GAAG,gBAAgB,CAAC,QAAQ,EAAE,CAAC;QAElE,sGAAsG;QACtG,mBAAmB,CAAC,UAAU,CAAC,cAAc,GAAG;YAC9C,yBAAyB,EAAE;gBACzB,6BAA6B,EAAE,GAAG;aACnC;YACD,cAAc,EAAE;gBACd,KAAK,EAAE,gBAAgB;aACxB;SACF,CAAC;QAEF,IAAI,kCAAkC,CAAC,KAAK,EAAE,EAAE,gBAAgB,EAAE,CAAC,CAAC;QACpE,IAAI,sCAAsC,CAAC,KAAK,EAAE;YAChD,gBAAgB;YAChB,WAAW;YACX,eAAe;YACf,eAAe;YACf,iBAAiB;SAClB,CAAC,CAAC;QAEH;;;;WAIG;QACH,MAAM,UAAU,GAAG,qBAAO,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC;QACzC,MAAM,+BAA+B,GAAG,UAAU,CAAC,IAAI,CACrD,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,YAAY,6CAA6C,CAClE,CAAC;QACF,IAAI,CAAC,+BAA+B,EAAE;YACpC,qBAAO,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,6CAA6C,EAAE,CAAC,CAAC;SAC5E;QAED,qBAAO,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,qDAAqD,EAAE,CAAC,CAAC;IACrF,CAAC;CACF;AAxDD,oDAwDC","sourcesContent":["import type { IAspect } from \"aws-cdk-lib\";\nimport { Aspects, CfnParameter, Duration, Tags } from \"aws-cdk-lib\";\nimport { CfnAutoScalingGroup, CfnScalingPolicy, ScalingProcess, UpdatePolicy } from \"aws-cdk-lib/aws-autoscaling\";\nimport type { CfnPolicy } from \"aws-cdk-lib/aws-iam\";\nimport { Effect, Policy, PolicyStatement } from \"aws-cdk-lib/aws-iam\";\nimport type { IConstruct } from \"constructs\";\nimport { MetadataKeys } from \"../../constants\";\nimport { GuAutoScalingGroup } from \"../../constructs/autoscaling\";\nimport { GuStack } from \"../../constructs/core\";\nimport type { GuApplicationTargetGroup } from \"../../constructs/loadbalancing\";\nimport type { GuEc2AppProps } from \"../../patterns\";\nimport { GuEc2App } from \"../../patterns\";\nimport { isSingletonPresentInStack } from \"../../utils/singleton\";\nimport { GuRiffRaffDeploymentIdParameterExperimental } from \"../constructs/riff-raff-deployment-id\";\n\ninterface AutoScalingRollingUpdateDurations {\n /**\n * The time between each check of an instance's health within the target group.\n */\n sleep: Duration;\n\n /**\n * Additional time to cover the time spent polling an instance's health within the target group before sending the CloudFormation signal.\n */\n buffer: Duration;\n}\n\nexport const RollingUpdateDurations: AutoScalingRollingUpdateDurations = {\n sleep: Duration.seconds(5),\n buffer: Duration.minutes(1),\n};\n\n/**\n * Ensures the `AutoScalingRollingUpdate` of an AutoScaling Group has a `PauseTime` matching the healthcheck grace period.\n * It also ensures the `CreationPolicy` resource signal `Timeout` matches the healthcheck grace period.\n *\n * @note\n * Be sure to instantiate this only once for an entire {@link GuStack}, else the properties of the ASG will be incorrectly updated multiple times.\n *\n * @internal\n *\n * @privateRemarks\n * The ASG healthcheck grace period is hard-coded by {@link GuEc2App}.\n * Customisation of this value is performed via an escape hatch.\n * An `Aspect` is the only way to observe any customisation.\n *\n * TODO Expose the healthcheck grace period as a property on {@link GuEc2App} and remove this `Aspect`.\n */\nexport class GuAutoScalingRollingUpdateTimeoutExperimental implements IAspect {\n public visit(construct: IConstruct) {\n if (construct instanceof CfnAutoScalingGroup) {\n const currentRollingUpdate = construct.cfnOptions.updatePolicy?.autoScalingRollingUpdate;\n const currentCreationPolicy = construct.cfnOptions.creationPolicy;\n\n if (!construct.healthCheckGracePeriod) {\n throw new Error(`The healthcheck grace period not set for autoscaling group ${construct.node.id}.`);\n }\n\n const signalTimeoutSeconds = construct.healthCheckGracePeriod + RollingUpdateDurations.buffer.toSeconds();\n\n if (currentRollingUpdate) {\n construct.cfnOptions.updatePolicy = {\n autoScalingRollingUpdate: {\n ...currentRollingUpdate,\n pauseTime: Duration.seconds(\n Duration.parse(currentRollingUpdate.pauseTime ?? \"0\").toSeconds() + signalTimeoutSeconds,\n ).toIsoString(),\n },\n };\n }\n\n if (currentCreationPolicy) {\n construct.cfnOptions.creationPolicy = {\n ...currentCreationPolicy,\n resourceSignal: {\n ...currentCreationPolicy.resourceSignal,\n timeout: Duration.seconds(signalTimeoutSeconds).toIsoString(),\n },\n };\n }\n }\n }\n}\n\n/**\n * An `Aspect` that adjusts the properties of an AutoScaling Group using an `AutoScalingRollingUpdate` update policy.\n *\n * It'll unset the `DesiredCapacity` of the ASG as a rolling update sets `Desired` back to the template version,\n * undoing any changes that a scale-out event may have done.\n * Having `DesiredCapacity` unset ensures the service remains at-capacity at all times.\n *\n * It'll also make the `MinInstancesInService` property dynamic via a CFN Parameter that Riff-Raff will set.\n * The value depends on the current capacity of the ASG:\n * - If the service is running normally, it'll be set to the `MinSize` capacity\n * - If the service is partially scaled, it'll be set to the current `DesiredCapacity`\n * - If the service is fully scaled, it'll be set to (at least) `MaxSize` - 1\n *\n * @privateRemarks\n * - Once out of experimental, instantiate this `Aspect` directly in {@link GuStack}.\n *\n * @see https://github.com/guardian/testing-asg-rolling-update\n */\nexport class GuHorizontallyScalingDeploymentPropertiesExperimental implements IAspect {\n public visit(construct: IConstruct) {\n if (CfnScalingPolicy.isCfnScalingPolicy(construct)) {\n const { node } = construct;\n const { scopes, path } = node;\n\n /*\n Requiring a `CfnScalingPolicy` to be created in the scope of a `GuAutoScalingGroup`\n is the most reliable way to associate the two together.\n\n Though the `autoScalingGroupName` property is passed to a `CfnScalingPolicy` when instantiating,\n this does not create a concrete link as AWS CDK sets the value to be the ASG's `Ref`.\n That is, it is a `Token` until it is synthesised.\n This is even if the ASG has an explicit name set.\n\n See also:\n - https://docs.aws.amazon.com/cdk/v2/guide/tokens.html\n - https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-autoscaling-autoscalinggroup.html#aws-resource-autoscaling-autoscalinggroup-return-values\n - https://github.com/aws/aws-cdk/blob/f6b649d47f8bc30ca741fbb7a4852d51e8275002/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts#L1560\n */\n const autoScalingGroup = scopes.find((_): _ is GuAutoScalingGroup => _ instanceof GuAutoScalingGroup);\n\n if (!autoScalingGroup) {\n throw new Error(\n `Failed to detect the autoscaling group relating to the scaling policy on path ${path}. Was it created in the scope of a GuAutoScalingGroup?`,\n );\n }\n\n const cfnAutoScalingGroup = autoScalingGroup.node.defaultChild as CfnAutoScalingGroup;\n const currentRollingUpdate = cfnAutoScalingGroup.cfnOptions.updatePolicy?.autoScalingRollingUpdate;\n\n if (currentRollingUpdate) {\n /*\n An autoscaling group that horizontally scales should not explicitly set `Desired`,\n as a rolling update will set the current `Desired` back to the template version,\n undoing any changes that a scale-out event may have done.\n */\n cfnAutoScalingGroup.desiredCapacity = undefined;\n\n const minInstancesInService = GuAsgMinInstancesInServiceParameterExperimental.getInstance(autoScalingGroup);\n\n cfnAutoScalingGroup.cfnOptions.updatePolicy = {\n autoScalingRollingUpdate: {\n ...currentRollingUpdate,\n minInstancesInService: minInstancesInService.valueAsNumber,\n },\n };\n }\n }\n }\n}\n\n/**\n * A CloudFormation parameter used to make the `MinInstancesInService` property of an ASG dynamic during deployment with Riff-Raff.\n * This shouldn't be instantiated directly, but via {@link GuHorizontallyScalingDeploymentPropertiesExperimental}.\n */\nexport class GuAsgMinInstancesInServiceParameterExperimental extends CfnParameter {\n public readonly asg: GuAutoScalingGroup;\n\n private constructor(scope: GuStack, id: string, autoScalingGroup: GuAutoScalingGroup) {\n super(scope, id, { type: \"Number\" });\n this.asg = autoScalingGroup;\n }\n\n public static getInstance(autoScalingGroup: GuAutoScalingGroup): GuAsgMinInstancesInServiceParameterExperimental {\n const stack = GuStack.of(autoScalingGroup) as GuStack;\n const { app } = autoScalingGroup;\n const id = `MinInstancesInServiceFor${app.replaceAll(\"-\", \"\")}`;\n\n const maybeParameter = stack.parameters[id];\n\n if (!maybeParameter) {\n return new GuAsgMinInstancesInServiceParameterExperimental(stack, id, autoScalingGroup);\n }\n\n // This shouldn't happen\n if (!(maybeParameter instanceof GuAsgMinInstancesInServiceParameterExperimental)) {\n throw new Error(\n `CFN parameter ${id} exists but is of type ${maybeParameter.constructor.name} instead of ${GuAsgMinInstancesInServiceParameterExperimental.name}.`,\n );\n }\n\n return maybeParameter;\n }\n}\n\n/**\n * An IAM Policy allowing the sending of a CloudFormation signal.\n *\n * @privateRemarks\n * Implemented as a singleton as the resources can only be tightened at most to the CloudFormation stack.\n */\nclass AsgRollingUpdatePolicy extends Policy {\n private static instance: AsgRollingUpdatePolicy | undefined;\n\n private constructor(scope: GuStack) {\n const { stackId } = scope;\n\n super(scope, \"AsgRollingUpdatePolicy\", {\n statements: [\n // Allow usage of command `cfn-signal`.\n new PolicyStatement({\n actions: [\"cloudformation:SignalResource\"],\n effect: Effect.ALLOW,\n resources: [stackId],\n }),\n\n /*\n Allow usage of command `aws elbv2 describe-target-health`.\n AWS Elastic Load Balancing does not support resource based policies, so the resource has to be `*` (any) here.\n See https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_aws-services-that-work-with-iam.html\n */\n new PolicyStatement({\n actions: [\"elasticloadbalancing:DescribeTargetHealth\"],\n effect: Effect.ALLOW,\n resources: [\"*\"],\n }),\n ],\n });\n }\n\n public static getInstance(stack: GuStack): AsgRollingUpdatePolicy {\n if (!this.instance || !isSingletonPresentInStack(stack, this.instance)) {\n this.instance = new AsgRollingUpdatePolicy(stack);\n }\n\n return this.instance;\n }\n}\n\nexport interface GuEc2AppExperimentalProps extends Omit<GuEc2AppProps, \"updatePolicy\"> {\n /**\n * Which application build to run.\n * This will typically match the build number provided by CI.\n *\n * @example\n * process.env.GITHUB_RUN_NUMBER\n */\n buildIdentifier: string;\n /**\n * The amount of time that newly launched instances will spend warming-up / serving fewer requests than other instances.\n * The range is 30-900 seconds (15 minutes). The default is 0 seconds (disabled).\n *\n * See https://docs.aws.amazon.com/elasticloadbalancing/latest/application/edit-target-group-attributes.html#slow-start-mode\n * for more details.\n *\n * We recommend enabling this setting if you run a high-traffic service, particularly if it is JVM-based.\n *\n * Note that there is a trade-off between reliability and speed here; a longer duration will give new instances\n * more time to warm-up, but it will also slow down deployments and scale-up events.\n */\n slowStartDuration?: Duration;\n}\n\n/**\n * Configures the rolling update policy for the autoscaling group.\n *\n * Most applications should not need to instantiate this class directly as this policy is set by GuEc2AppExperimental.\n *\n * If you need to use this class for a service other than MAPI, please speak to DevX about your use-case first.\n */\nexport class GuRollingUpdatePolicyExperimental {\n static getPolicy(\n maximumInstances: number,\n minimumInstances?: number,\n slowStartDuration: Duration = Duration.seconds(0),\n ) {\n return UpdatePolicy.rollingUpdate({\n maxBatchSize: maximumInstances,\n minInstancesInService: minimumInstances,\n minSuccessPercentage: 100,\n waitOnResourceSignals: true,\n /*\n All of these processes can launch and/or terminate instances and if this happens during a deployment it might\n cause the rolling update to fail: https://repost.aws/knowledge-center/auto-scaling-group-rolling-updates\n The full list of processes can be found here: https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-suspend-resume-processes.html#process-types\n */\n suspendProcesses: [\n ScalingProcess.ALARM_NOTIFICATION,\n ScalingProcess.AZ_REBALANCE,\n ScalingProcess.HEALTH_CHECK,\n ScalingProcess.INSTANCE_REFRESH,\n ScalingProcess.REPLACE_UNHEALTHY,\n ScalingProcess.SCHEDULED_ACTIONS,\n ],\n /*\n Note: this is increased via an Aspect which also takes healthcheck grace period into account.\n\n It was easier to pass the slow start duration through here rather than trying to do this via the\n GuAutoScalingRollingUpdateTimeoutExperimental aspect.\n\n If we do this via the aspect then we need to find all mappings between ASGs and target groups and then\n get the relevant slow start duration for each. This is probably possible but would be reasonably complex.\n However, it's worth mentioning that by taking this approach we open up a small risk that things will not work\n as expected if users enable slow start via a different mechanism (e.g. by modifying the target group outside\n the pattern).\n */\n pauseTime: slowStartDuration,\n });\n }\n}\n\nexport interface GuRoleForRollingUpdateExperimentalProps {\n autoScalingGroup: GuAutoScalingGroup;\n}\n\n/**\n * Grants the role associated with your autoscaling group the necessary permissions for the rolling update deployment\n * mechanism.\n *\n * Most applications should not need to instantiate this class directly as these permission changes are granted\n * by GuEc2AppExperimental.\n *\n * If you need to use this class for a service other than MAPI, please speak to DevX about your use-case first.\n */\nexport class GuRoleForRollingUpdateExperimental {\n constructor(scope: GuStack, props: GuRoleForRollingUpdateExperimentalProps) {\n const policy = AsgRollingUpdatePolicy.getInstance(scope);\n policy.attachToRole(props.autoScalingGroup.role);\n\n // Create the Policy with necessary permissions first.\n // Then create the ASG that requires the permissions.\n const cfnPolicy = policy.node.defaultChild as CfnPolicy;\n const cfnAutoScalingGroup = props.autoScalingGroup.node.defaultChild as CfnAutoScalingGroup;\n cfnAutoScalingGroup.addDependency(cfnPolicy);\n }\n}\n\nexport interface GuUserDataForRollingUpdateExperimentalProps {\n autoScalingGroup: GuAutoScalingGroup;\n targetGroup: GuApplicationTargetGroup;\n applicationPort: number;\n buildIdentifier: string;\n slowStartDuration?: Duration;\n}\n\n/**\n * Modifies the user-data script (which runs whenever an instance is launched) to make it compatible with the new\n * rolling update deployment mechanism.\n *\n * Most applications should not need to instantiate this class directly as these user-data changes are already made\n * by GuEc2AppExperimental.\n *\n * If you need to use this class for a service other than MAPI, please speak to DevX about your use-case first.\n */\nexport class GuUserDataForRollingUpdateExperimental {\n constructor(scope: GuStack, props: GuUserDataForRollingUpdateExperimentalProps) {\n const { region, stackId } = scope;\n const { autoScalingGroup, targetGroup, applicationPort, buildIdentifier, slowStartDuration } = props;\n const cfnAutoScalingGroup = autoScalingGroup.node.defaultChild as CfnAutoScalingGroup;\n\n const deploymentId = GuRiffRaffDeploymentIdParameterExperimental.getInstance(scope);\n\n // This allows redeployment of the same build to cycle instances\n autoScalingGroup.userData.addCommands(\n `echo \"Launch template last updated by Riff-Raff deployment ID: ${deploymentId.valueAsString}\"`,\n );\n\n /*\n `aws` is available via AMIgo baked AMIs.\n See https://github.com/guardian/amigo/tree/main/roles/aws-tools.\n */\n autoScalingGroup.userData.addCommands(\n `# ${GuEc2AppExperimental.name} Instance Health Check Start`,\n `\n TOKEN=$(curl -X PUT \"http://169.254.169.254/latest/api/token\" -H \"X-aws-ec2-metadata-token-ttl-seconds: 21600\")\n INSTANCE_ID=$(curl -H \"X-aws-ec2-metadata-token: $TOKEN\" \"http://169.254.169.254/latest/meta-data/instance-id\")\n\n STATE=$(aws elbv2 describe-target-health \\\n --target-group-arn ${targetGroup.targetGroupArn} \\\n --region ${region} \\\n --targets Id=$INSTANCE_ID,Port=${applicationPort} \\\n --query \"TargetHealthDescriptions[0].TargetHealth.State\")\n\n until [ \"$STATE\" == \"\\\\\"healthy\\\\\"\" ]; do\n echo \"Instance running build ${buildIdentifier} not yet healthy within target group. Current state $STATE. Sleeping...\"\n sleep ${RollingUpdateDurations.sleep.toSeconds()}\n STATE=$(aws elbv2 describe-target-health \\\n --target-group-arn ${targetGroup.targetGroupArn} \\\n --region ${region} \\\n --targets Id=$INSTANCE_ID,Port=${applicationPort} \\\n --query \"TargetHealthDescriptions[0].TargetHealth.State\")\n done\n\n echo \"Instance running build ${buildIdentifier} is healthy in target group.\"\n `,\n `# ${GuEc2AppExperimental.name} Instance Health Check End`,\n );\n\n if (slowStartDuration) {\n const slowStartInSeconds = slowStartDuration.toSeconds().toString();\n targetGroup.setAttribute(\"slow_start.duration_seconds\", slowStartInSeconds);\n autoScalingGroup.userData.addCommands(\n `# ${GuEc2AppExperimental.name} SlowStart Wait Period Start`,\n `\n echo \"Sleeping for ${slowStartInSeconds} seconds while instance running build ${buildIdentifier} warms up...\"\n sleep ${slowStartInSeconds}s\n echo \"Instance running build ${buildIdentifier} should have warmed up by now...\"\n\n STATE=$(aws elbv2 describe-target-health \\\n --target-group-arn ${targetGroup.targetGroupArn} \\\n --region ${region} \\\n --targets Id=$INSTANCE_ID,Port=${applicationPort} \\\n --query \"TargetHealthDescriptions[0].TargetHealth.State\")\n\n if [ \"$STATE\" == \"\\\\\"healthy\\\\\"\" ]; then\n echo \"Instance running build ${buildIdentifier} is ready to start serving a normal percentage of requests\"\n else\n echo \"Instance running build ${buildIdentifier} was not healthy after warm-up period; a failure signal will be sent\"\n exit 1\n fi\n `,\n `# ${GuEc2AppExperimental.name} SlowStart Wait Period End`,\n );\n }\n\n autoScalingGroup.userData.addOnExitCommands(\n `\n cfn-signal --stack ${stackId} \\\n --resource ${cfnAutoScalingGroup.logicalId} \\\n --region ${region} \\\n --exit-code $exitCode || echo 'Failed to send Cloudformation Signal'\n `,\n );\n\n // If https://github.com/guardian/devx-logs is used, this tag will be added as a marker to logs in Central ELK.\n Tags.of(autoScalingGroup.instanceLaunchTemplate).add(MetadataKeys.BUILD_IDENTIFIER, buildIdentifier, {\n applyToLaunchedInstances: true,\n });\n }\n}\n\n/**\n * An experimental pattern to instantiate an EC2 application that is updated entirely via CloudFormation.\n * It sets the update policy of the `AWS::AutoScaling::AutoScalingGroup` to `AutoScalingRollingUpdate`.\n * When a CloudFormation update is applied, the current instances in the ASG will be replaced.\n *\n * This pattern also updates the User Data, running some commands AFTER yours.\n * These changes are wrapped in start and end marking comments.\n *\n * This pattern does not enable for scaling events to trigger _during_ a deployment\n * as during testing it was found that scale-in events during deployment led to unpredictable service availability.\n *\n * If a deployment fails, for example when the healthcheck fails, CloudFormation will automatically rollback the changes.\n * This improves on the behaviour of Riff-Raff's `autoscaling` deployment which requires manual intervention on deployment failure.\n *\n * To update the application's code, a CloudFormation update must be triggered.\n * The best way to do this is to include the build number in the application artifact.\n * TODO test User Data includes a build number.\n *\n * @remarks\n * - The rate at which instances are replaced are conditional based on how scaled up the service is.\n * The more an application is scaled, the longer it'll take to deploy.\n * - It is not necessary to use the `autoscaling` Riff-Raff deployment type in conjunction with this.\n * Doing so won't break anything, however it'll lengthen the deployment time as instances will be rotated twice.\n * Please remove it from any manually created `riff-raff.yaml` file.\n * - Your application should include a build number in its filename.\n * This value will change across builds, and therefore create a CloudFormation template difference to be deployed.\n * - Requires the AWS CLI and `cfn-signal` binaries to be available on the instance, and on the `PATH`.\n * AMIgo adds these via the `aws-tools` role.\n *\n * @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-updatepolicy.html#cfn-attributes-updatepolicy-rollingupdate\n * @see https://github.com/guardian/testing-asg-rolling-update\n *\n * @experimental\n */\nexport class GuEc2AppExperimental extends GuEc2App {\n constructor(scope: GuStack, props: GuEc2AppExperimentalProps) {\n const { minimumInstances, maximumInstances = minimumInstances * 2 } = props.scaling;\n const { applicationPort, buildIdentifier, slowStartDuration } = props;\n\n const slowStartDurationInSeconds = slowStartDuration?.toSeconds();\n if (slowStartDurationInSeconds && (slowStartDurationInSeconds < 30 || slowStartDurationInSeconds > 900)) {\n throw new Error(\"Slow start duration must be between 30 and 900 seconds\");\n }\n\n super(scope, {\n ...props,\n // Note: if the service uses horizontal scaling, minimumInstances is overridden by an Aspect (to prevent accidental scale downs!)\n updatePolicy: GuRollingUpdatePolicyExperimental.getPolicy(maximumInstances, minimumInstances, slowStartDuration),\n });\n\n const { autoScalingGroup, targetGroup } = this;\n const cfnAutoScalingGroup = autoScalingGroup.node.defaultChild as CfnAutoScalingGroup;\n\n // Note: if the service uses horizontal scaling, this property is unset by an Aspect (to prevent accidental scale downs!)\n cfnAutoScalingGroup.desiredCapacity = minimumInstances.toString();\n\n // This is used when an ASG is first created; it is not needed to support the new deployment mechanism\n cfnAutoScalingGroup.cfnOptions.creationPolicy = {\n autoScalingCreationPolicy: {\n minSuccessfulInstancesPercent: 100,\n },\n resourceSignal: {\n count: minimumInstances,\n },\n };\n\n new GuRoleForRollingUpdateExperimental(scope, { autoScalingGroup });\n new GuUserDataForRollingUpdateExperimental(scope, {\n autoScalingGroup,\n targetGroup,\n applicationPort,\n buildIdentifier,\n slowStartDuration,\n });\n\n /*\n Instantiate the `GuAutoScalingRollingUpdateTimeoutExperimental` exactly once for a GuStack.\n Whilst multiple instances are syntactically valid, it will cause ASG nodes to be incorrectly evaluated/mutated multiple times.\n TODO Once out of experimental, instantiate these `Aspect`s directly in `GuStack`.\n */\n const allAspects = Aspects.of(scope).all;\n const maybeRollingUpdateTimeoutAspect = allAspects.find(\n (_) => _ instanceof GuAutoScalingRollingUpdateTimeoutExperimental,\n );\n if (!maybeRollingUpdateTimeoutAspect) {\n Aspects.of(scope).add(new GuAutoScalingRollingUpdateTimeoutExperimental());\n }\n\n Aspects.of(scope).add(new GuHorizontallyScalingDeploymentPropertiesExperimental());\n }\n}\n"]}
|