From ec846d25b81a5223af639c6498226217826d8ccd Mon Sep 17 00:00:00 2001 From: Jonathan Romano Date: Sat, 2 Sep 2023 03:36:21 +0000 Subject: [PATCH 01/22] feat(core): Support linking cdk context values to scope --- packages/aws-cdk-lib/aws-ec2/README.md | 35 +++++++++++++++- .../aws-ec2/lib/machine-image/common.ts | 7 ++++ .../lib/machine-image/machine-image.ts | 29 +++++++++++-- .../aws-ec2/lib/machine-image/utils.ts | 4 +- .../aws-cdk-lib/aws-ec2/lib/security-group.ts | 23 ++++++---- packages/aws-cdk-lib/aws-ec2/lib/vpc.ts | 5 ++- .../aws-ec2/test/machine-image.test.ts | 21 ++++++++++ packages/aws-cdk-lib/aws-ecs/README.md | 13 ++++++ packages/aws-cdk-lib/aws-ecs/lib/amis.ts | 42 ++++++++++++++++--- .../aws-elasticloadbalancingv2/README.md | 9 ++++ .../lib/alb/application-listener.ts | 11 ++++- .../lib/alb/application-load-balancer.ts | 11 ++++- .../lib/nlb/network-listener.ts | 6 ++- .../lib/nlb/network-load-balancer.ts | 11 ++++- .../lib/shared/base-listener.ts | 3 +- .../lib/shared/base-load-balancer.ts | 7 +++- packages/aws-cdk-lib/aws-kms/README.md | 4 ++ packages/aws-cdk-lib/aws-kms/lib/key.ts | 5 ++- packages/aws-cdk-lib/aws-route53/README.md | 9 ++++ .../aws-route53/lib/hosted-zone.ts | 5 ++- .../test/hosted-zone-provider.test.ts | 40 +++++++++++++++++- packages/aws-cdk-lib/aws-ssm/README.md | 10 +++++ packages/aws-cdk-lib/aws-ssm/lib/parameter.ts | 11 +++-- .../aws-ssm/test/parameter.test.ts | 24 +++++++++++ .../aws-cdk-lib/core/lib/context-provider.ts | 15 +++++-- .../aws-cdk-lib/core/test/context.test.ts | 28 +++++++++++++ 26 files changed, 349 insertions(+), 39 deletions(-) diff --git a/packages/aws-cdk-lib/aws-ec2/README.md b/packages/aws-cdk-lib/aws-ec2/README.md index e0e2e75804b34..676916a648fb6 100644 --- a/packages/aws-cdk-lib/aws-ec2/README.md +++ b/packages/aws-cdk-lib/aws-ec2/README.md @@ -504,6 +504,10 @@ The result of the `Vpc.fromLookup()` operation will be written to a file called `cdk.context.json`. You must commit this file to source control so that the lookup values are available in non-privileged environments such as CI build steps, and to ensure your template builds are repeatable. +If you want the key of the context variable to be tied to the scope +passed to `fromLookup` instead of being global (usinwhich would use the same +value any time you call `fromLookup` across your entire app), +you can set the `linkContextToScope` argument to `true` Here's how `Vpc.fromLookup()` can be used: @@ -744,7 +748,7 @@ If the security group ID is known and configuration details are unknown, use met const sg = ec2.SecurityGroup.fromLookupById(this, 'SecurityGroupLookup', 'sg-1234'); ``` -The result of `SecurityGroup.fromLookupByName` and `SecurityGroup.fromLookupById` operations will be written to a file called `cdk.context.json`. You must commit this file to source control so that the lookup values are available in non-privileged environments such as CI build steps, and to ensure your template builds are repeatable. +The result of `SecurityGroup.fromLookupByName` and `SecurityGroup.fromLookupById` operations will be written to a file called `cdk.context.json`. You must commit this file to source control so that the lookup values are available in non-privileged environments such as CI build steps, and to ensure your template builds are repeatable. If you want the key of the context variable to be tied to the scope passed to `fromLookupByName`/`fromLookupById` instead of being global (which would use the same value any time you call `fromLookup` across your entire app), you can set the `linkContextToScope` argument to `true` ### Cross Stack Connections @@ -831,6 +835,10 @@ examples of images you might want to use: > `cdk.context.json`, or use the `cdk context` command. For more information, see > [Runtime Context](https://docs.aws.amazon.com/cdk/latest/guide/context.html) in the CDK > developer guide. +> +> If you want the key of the context variable to be tied to the scope +> passed to `lookup` instead of being global (which would use the same value any +> time you call `lookup` across your entire app), you can set the `linkContextToScope` argument to `true` > > `MachineImage.genericLinux()`, `MachineImage.genericWindows()` will use `CfnMapping` in > an agnostic stack. @@ -1151,6 +1159,31 @@ new ec2.Instance(this, 'LatestAl2023', { // context cache is turned on by default machineImage: new ec2.AmazonLinux2023ImageSsmParameter(), }); + +// or +new ec2.Instance(this, 'LatestAl2023', { + vpc, + instanceType: ec2.InstanceType.of(ec2.InstanceClass.C7G, ec2.InstanceSize.LARGE), + machineImage: ec2.MachineImage.latestAmazonLinux2023({ + cachedInContext: true, + // creates a distinct context variable for this image, instead of resolving to the same + // value anywhere this lookup is done in your app + linkContextToScope: true, + }), +}); + +// or +new ec2.Instance(this, 'LatestAl2023', { + vpc, + instanceType: ec2.InstanceType.of(ec2.InstanceClass.C7G, ec2.InstanceSize.LARGE), + // context cache is turned on by default + machineImage: new ec2.AmazonLinux2023ImageSsmParameter({ + // creates a distinct context variable for this image, instead of resolving to the same + // value anywhere this lookup is done in your app + linkContextToScope: true, + }), +}); + ``` #### Kernel Versions diff --git a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/common.ts b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/common.ts index a598c2c3a6d5b..681bcb54fe8a3 100644 --- a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/common.ts +++ b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/common.ts @@ -46,6 +46,13 @@ export interface AmazonLinuxImageSsmParameterBaseOptions { */ readonly cachedInContext?: boolean; + /** + * If true and cachedInContext is true, the context key will be tied to the passed scope rather than global + * + * @default false + */ + readonly linkContextToScope?: boolean + /** * Initial user data * diff --git a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/machine-image.ts b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/machine-image.ts index fbd22863fa60d..397dd3eede5b7 100644 --- a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/machine-image.ts +++ b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/machine-image.ts @@ -302,6 +302,13 @@ export interface SsmParameterImageOptions { */ readonly cachedInContext?: boolean; + /** + * If true and cachedInContext is true, the context key will be tied to the passed scope rather than global + * + * @default false + */ + readonly linkContextToScope?: boolean + /** * The version of the SSM parameter. * @@ -328,7 +335,7 @@ class GenericSsmParameterImage implements IMachineImage { * Return the image to use in the given context */ public getImage(scope: Construct): MachineImageConfig { - const imageId = lookupImage(scope, this.props.cachedInContext, this.parameterName); + const imageId = lookupImage(scope, this.props.cachedInContext && this.props.linkContextToScope ? 'scope' : this.props.cachedInContext, this.parameterName); const osType = this.props.os ?? OperatingSystemType.LINUX; return { @@ -459,6 +466,13 @@ export interface AmazonLinuxImageProps { * @default false */ readonly cachedInContext?: boolean; + + /** + * If true and cachedInContext is true, the context key will be tied to the passed scope rather than global + * + * @default false + */ + readonly linkContextToScope?: boolean } /** @@ -511,17 +525,20 @@ export class AmazonLinuxImage extends GenericSSMParameterImage { private readonly cachedInContext: boolean; + private readonly linkContextToScope: boolean; + constructor(private readonly props: AmazonLinuxImageProps = {}) { super(AmazonLinuxImage.ssmParameterName(props), OperatingSystemType.LINUX, props.userData); this.cachedInContext = props.cachedInContext ?? false; + this.linkContextToScope = props.linkContextToScope ?? false; } /** * Return the image to use in the given context */ public getImage(scope: Construct): MachineImageConfig { - const imageId = lookupImage(scope, this.cachedInContext, this.parameterName); + const imageId = lookupImage(scope, this.cachedInContext && this.linkContextToScope ? 'scope' : this.cachedInContext, this.parameterName); const osType = OperatingSystemType.LINUX; return { @@ -657,7 +674,12 @@ export class LookupMachineImage implements IMachineImage { constructor(private readonly props: LookupMachineImageProps) { } - public getImage(scope: Construct): MachineImageConfig { + /** + * Return the correct image + * + * If linkContextToScope is true, the context key will be tied to the passed scope rather than global + */ + public getImage(scope: Construct, linkContextToScope?: boolean): MachineImageConfig { // Need to know 'windows' or not before doing the query to return the right // osType for the dummy value, so might as well add it to the filter. const filters: Record = { @@ -675,6 +697,7 @@ export class LookupMachineImage implements IMachineImage { filters, } as cxschema.AmiContextQuery, dummyValue: 'ami-1234', + includeScope: linkContextToScope, }).value as cxapi.AmiContextResponse; if (typeof value !== 'string') { diff --git a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/utils.ts b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/utils.ts index a2da997c80e63..0423c4550de05 100644 --- a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/utils.ts +++ b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/utils.ts @@ -1,9 +1,9 @@ import { Construct } from 'constructs'; import * as ssm from '../../../aws-ssm'; -export function lookupImage(scope: Construct, cachedInContext: boolean | undefined, parameterName: string) { +export function lookupImage(scope: Construct, cachedInContext: boolean | undefined | 'scope', parameterName: string) { return cachedInContext - ? ssm.StringParameter.valueFromLookup(scope, parameterName) + ? ssm.StringParameter.valueFromLookup(scope, parameterName, cachedInContext === 'scope') : ssm.StringParameter.valueForTypedStringParameterV2(scope, parameterName, ssm.ParameterValueType.AWS_EC2_IMAGE_ID); } diff --git a/packages/aws-cdk-lib/aws-ec2/lib/security-group.ts b/packages/aws-cdk-lib/aws-ec2/lib/security-group.ts index 125ce5c0e18ba..bb8141ccbd761 100644 --- a/packages/aws-cdk-lib/aws-ec2/lib/security-group.ts +++ b/packages/aws-cdk-lib/aws-ec2/lib/security-group.ts @@ -367,24 +367,30 @@ export class SecurityGroup extends SecurityGroupBase { /** * Look up a security group by id. * + * If linkContextToScope is true, the context key will be tied to the passed scope rather than global + * * @deprecated Use `fromLookupById()` instead */ - public static fromLookup(scope: Construct, id: string, securityGroupId: string) { - return this.fromLookupAttributes(scope, id, { securityGroupId }); + public static fromLookup(scope: Construct, id: string, securityGroupId: string, linkContextToScope?: boolean) { + return this.fromLookupAttributes(scope, id, { securityGroupId }, linkContextToScope); } /** * Look up a security group by id. + * + * If linkContextToScope is true, the context key will be tied to the passed scope rather than global */ - public static fromLookupById(scope: Construct, id: string, securityGroupId: string) { - return this.fromLookupAttributes(scope, id, { securityGroupId }); + public static fromLookupById(scope: Construct, id: string, securityGroupId: string, linkContextToScope?: boolean) { + return this.fromLookupAttributes(scope, id, { securityGroupId }, linkContextToScope); } /** * Look up a security group by name. + * + * If linkContextToScope is true, the context key will be tied to the passed scope rather than global */ - public static fromLookupByName(scope: Construct, id: string, securityGroupName: string, vpc: IVpc) { - return this.fromLookupAttributes(scope, id, { securityGroupName, vpc }); + public static fromLookupByName(scope: Construct, id: string, securityGroupName: string, vpc: IVpc, linkContextToScope?: boolean) { + return this.fromLookupAttributes(scope, id, { securityGroupName, vpc }, linkContextToScope); } /** @@ -432,8 +438,10 @@ export class SecurityGroup extends SecurityGroupBase { /** * Look up a security group. + * + * If linkContextToScope is true, the context key will be tied to the passed scope rather than global */ - private static fromLookupAttributes(scope: Construct, id: string, options: SecurityGroupLookupOptions) { + private static fromLookupAttributes(scope: Construct, id: string, options: SecurityGroupLookupOptions, linkContextToScope?: boolean) { if (Token.isUnresolved(options.securityGroupId) || Token.isUnresolved(options.securityGroupName) || Token.isUnresolved(options.vpc?.vpcId)) { throw new Error('All arguments to look up a security group must be concrete (no Tokens)'); } @@ -449,6 +457,7 @@ export class SecurityGroup extends SecurityGroupBase { securityGroupId: 'sg-12345678', allowAllOutbound: true, } as cxapi.SecurityGroupContextResponse, + includeScope: linkContextToScope, }).value; return SecurityGroup.fromSecurityGroupId(scope, id, attributes.securityGroupId, { diff --git a/packages/aws-cdk-lib/aws-ec2/lib/vpc.ts b/packages/aws-cdk-lib/aws-ec2/lib/vpc.ts index a02ac3f726363..030759bb03392 100644 --- a/packages/aws-cdk-lib/aws-ec2/lib/vpc.ts +++ b/packages/aws-cdk-lib/aws-ec2/lib/vpc.ts @@ -1260,8 +1260,10 @@ export class Vpc extends VpcBase { * will be used on future runs. To refresh the lookup, you will have to * evict the value from the cache using the `cdk context` command. See * https://docs.aws.amazon.com/cdk/latest/guide/context.html for more information. + * + * If linkContextToScope is true, the context key will be tied to the passed scope rather than global */ - public static fromLookup(scope: Construct, id: string, options: VpcLookupOptions): IVpc { + public static fromLookup(scope: Construct, id: string, options: VpcLookupOptions, linkContextToScope?: boolean): IVpc { if (Token.isUnresolved(options.vpcId) || Token.isUnresolved(options.vpcName) || Object.values(options.tags || {}).some(Token.isUnresolved) @@ -1294,6 +1296,7 @@ export class Vpc extends VpcBase { subnetGroupNameTag: options.subnetGroupNameTag, } as cxschema.VpcContextQuery, dummyValue: undefined, + includeScope: linkContextToScope, }).value; return new LookedUpVpc(scope, id, attributes ?? DUMMY_VPC_PROPS, attributes === undefined); diff --git a/packages/aws-cdk-lib/aws-ec2/test/machine-image.test.ts b/packages/aws-cdk-lib/aws-ec2/test/machine-image.test.ts index c52129d095e49..4f011557919fd 100644 --- a/packages/aws-cdk-lib/aws-ec2/test/machine-image.test.ts +++ b/packages/aws-cdk-lib/aws-ec2/test/machine-image.test.ts @@ -207,6 +207,27 @@ test('cached lookups of Amazon Linux', () => { ]); }); +test('cached lookups of Amazon Linux linked to scope', () => { + // WHEN + const ami = ec2.MachineImage.latestAmazonLinux({ cachedInContext: true, linkContextToScope: true }).getImage(stack).imageId; + + // THEN + expect(ami).toEqual('dummy-value-for-Stack-/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2'); + expect(app.synth().manifest.missing).toEqual([ + { + key: 'ssm:account=1234:parameterName=/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2:region=testregion:scope=Stack', + props: { + account: '1234', + lookupRoleArn: 'arn:${AWS::Partition}:iam::1234:role/cdk-hnb659fds-lookup-role-1234-testregion', + region: 'testregion', + parameterName: '/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2', + scope: 'Stack', + }, + provider: 'ssm', + }, + ]); +}); + test('cached lookups of Amazon Linux 2', () => { // WHEN const ami = ec2.MachineImage.latestAmazonLinux({ diff --git a/packages/aws-cdk-lib/aws-ecs/README.md b/packages/aws-cdk-lib/aws-ecs/README.md index 2e3f4fab8f761..36f513185861f 100644 --- a/packages/aws-cdk-lib/aws-ecs/README.md +++ b/packages/aws-cdk-lib/aws-ecs/README.md @@ -156,6 +156,19 @@ const autoScalingGroup = new autoscaling.AutoScalingGroup(this, 'ASG', { }); ``` +If you want to create a distinct context variable for the AutoScalingGroup instead of +using a global variable that will resolve to the same variable across your entire app, +you can pass `linkContextToScope: true`: + +```ts +declare const vpc: ec2.Vpc; +const autoScalingGroup = new autoscaling.AutoScalingGroup(this, 'ASG', { + machineImage: ecs.EcsOptimizedImage.amazonLinux({ cachedInContext: true, linkContextToScope: true }), + vpc, + instanceType: new ec2.InstanceType('t2.micro'), +}); +``` + To use `LaunchTemplate` with `AsgCapacityProvider`, make sure to specify the `userData` in the `LaunchTemplate`: ```ts diff --git a/packages/aws-cdk-lib/aws-ecs/lib/amis.ts b/packages/aws-cdk-lib/aws-ecs/lib/amis.ts index 9d68b2dc7fce9..23331df9f675b 100644 --- a/packages/aws-cdk-lib/aws-ecs/lib/amis.ts +++ b/packages/aws-cdk-lib/aws-ecs/lib/amis.ts @@ -92,6 +92,13 @@ export interface EcsOptimizedAmiProps { * @default false */ readonly cachedInContext?: boolean; + + /** + * If true and cachedInContext is true, the context key will be tied to the passed scope rather than global + * + * @default false + */ + readonly linkContextToScope?: boolean } /* @@ -109,6 +116,7 @@ export class EcsOptimizedAmi implements ec2.IMachineImage { private readonly amiParameterName: string; private readonly cachedInContext: boolean; + private readonly linkContextToScope: boolean; /** * Constructs a new instance of the EcsOptimizedAmi class. @@ -145,13 +153,14 @@ export class EcsOptimizedAmi implements ec2.IMachineImage { + (this.windowsVersion ? 'image_id' : 'recommended/image_id'); this.cachedInContext = props?.cachedInContext ?? false; + this.linkContextToScope = props?.linkContextToScope ?? false; } /** * Return the correct image */ public getImage(scope: Construct): ec2.MachineImageConfig { - const ami = lookupImage(scope, this.cachedInContext, this.amiParameterName); + const ami = lookupImage(scope, this.cachedInContext && this.linkContextToScope ? 'scope' : this.cachedInContext, this.amiParameterName); const osType = this.windowsVersion ? ec2.OperatingSystemType.WINDOWS : ec2.OperatingSystemType.LINUX; return { @@ -186,6 +195,13 @@ export interface EcsOptimizedImageOptions { * @default false */ readonly cachedInContext?: boolean; + + /** + * If true and cachedInContext is true, the context key will be tied to the passed scope rather than global + * + * @default false + */ + readonly linkContextToScope?: boolean } /** @@ -233,6 +249,7 @@ export class EcsOptimizedImage implements ec2.IMachineImage { private readonly amiParameterName: string; private readonly cachedInContext: boolean; + private readonly linkContextToScope: boolean; /** * Constructs a new instance of the EcsOptimizedAmi class. @@ -258,14 +275,15 @@ export class EcsOptimizedImage implements ec2.IMachineImage { + (this.hwType === AmiHardwareType.ARM ? 'arm64/' : '') + (this.windowsVersion ? 'image_id' : 'recommended/image_id'); - this.cachedInContext = props?.cachedInContext ?? false; + this.cachedInContext = props.cachedInContext ?? false; + this.linkContextToScope = props.linkContextToScope ?? false; } /** * Return the correct image */ public getImage(scope: Construct): ec2.MachineImageConfig { - const ami = lookupImage(scope, this.cachedInContext, this.amiParameterName); + const ami = lookupImage(scope, this.cachedInContext && this.linkContextToScope ? 'scope' : this.cachedInContext, this.amiParameterName); const osType = this.windowsVersion ? ec2.OperatingSystemType.WINDOWS : ec2.OperatingSystemType.LINUX; return { @@ -326,6 +344,13 @@ export interface BottleRocketImageProps { * @default false */ readonly cachedInContext?: boolean; + + /** + * If true and cachedInContext is true, the context key will be tied to the passed scope rather than global + * + * @default false + */ + readonly linkContextToScope?: boolean } /** @@ -352,6 +377,8 @@ export class BottleRocketImage implements ec2.IMachineImage { private readonly cachedInContext: boolean; + private readonly linkContextToScope: boolean; + /** * Constructs a new instance of the BottleRocketImage class. */ @@ -363,13 +390,16 @@ export class BottleRocketImage implements ec2.IMachineImage { this.amiParameterName = `/aws/service/bottlerocket/${this.variant}/${this.architecture}/latest/image_id`; this.cachedInContext = props.cachedInContext ?? false; + this.linkContextToScope = props.linkContextToScope ?? false; } /** * Return the correct image + * + * If linkContextToScope is true, the context key will be tied to the passed scope rather than global */ public getImage(scope: Construct): ec2.MachineImageConfig { - const ami = lookupImage(scope, this.cachedInContext, this.amiParameterName); + const ami = lookupImage(scope, this.cachedInContext && this.linkContextToScope ? 'scope' : this.cachedInContext, this.amiParameterName); return { imageId: ami, @@ -385,8 +415,8 @@ Object.defineProperty(BottleRocketImage.prototype, BR_IMAGE_SYMBOL, { writable: false, }); -function lookupImage(scope: Construct, cachedInContext: boolean | undefined, parameterName: string) { +function lookupImage(scope: Construct, cachedInContext: boolean | undefined | 'scope', parameterName: string) { return cachedInContext - ? ssm.StringParameter.valueFromLookup(scope, parameterName) + ? ssm.StringParameter.valueFromLookup(scope, parameterName, cachedInContext === 'scope') : ssm.StringParameter.valueForTypedStringParameterV2(scope, parameterName, ssm.ParameterValueType.AWS_EC2_IMAGE_ID); } diff --git a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/README.md b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/README.md index fa8d644b26501..db0c84fc3d4a3 100644 --- a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/README.md +++ b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/README.md @@ -519,6 +519,15 @@ following lookup methods: - `NetworkListener.fromLookup(options)` - Look up a network load balancer listener. +The result of a `fromLookup()` operation will be written to a file +called `cdk.context.json`. You must commit this file to source control so +that the lookup values are available in non-privileged environments such +as CI build steps, and to ensure your template builds are repeatable. +If you want the key of the context variable to be tied to the scope +passed to `fromLookup` instead of being global (usinwhich would use the same +value any time you call `fromLookup` across your entire app), +you can set the `linkContextToScope` argument to `true` + ### Load Balancer lookup options You may look up a load balancer by ARN or by associated tags. When you look a diff --git a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-listener.ts b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-listener.ts index bbb7d02f34214..c56c1014518f5 100644 --- a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-listener.ts +++ b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-listener.ts @@ -133,8 +133,15 @@ export interface ApplicationListenerLookupOptions extends BaseListenerLookupOpti export class ApplicationListener extends BaseListener implements IApplicationListener { /** * Look up an ApplicationListener. + * + * If linkContextToScope is true, the cached context key will be tied to the passed scope rather than global */ - public static fromLookup(scope: Construct, id: string, options: ApplicationListenerLookupOptions): IApplicationListener { + public static fromLookup( + scope: Construct, + id: string, + options: ApplicationListenerLookupOptions, + linkContextToScope?: boolean, + ): IApplicationListener { if (Token.isUnresolved(options.listenerArn)) { throw new Error('All arguments to look up a load balancer listener must be concrete (no Tokens)'); } @@ -150,7 +157,7 @@ export class ApplicationListener extends BaseListener implements IApplicationLis loadBalancerType: cxschema.LoadBalancerType.APPLICATION, listenerArn: options.listenerArn, listenerProtocol, - }); + }, linkContextToScope); return new LookedUpApplicationListener(scope, id, props); } diff --git a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-load-balancer.ts b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-load-balancer.ts index fef38ff28be08..64480b14b2574 100644 --- a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-load-balancer.ts +++ b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-load-balancer.ts @@ -76,12 +76,19 @@ export interface ApplicationLoadBalancerLookupOptions extends BaseLoadBalancerLo export class ApplicationLoadBalancer extends BaseLoadBalancer implements IApplicationLoadBalancer { /** * Look up an application load balancer. + * + * If linkContextToScope is true, the context key will be tied to the passed scope rather than global */ - public static fromLookup(scope: Construct, id: string, options: ApplicationLoadBalancerLookupOptions): IApplicationLoadBalancer { + public static fromLookup( + scope: Construct, + id: string, + options: ApplicationLoadBalancerLookupOptions, + linkContextToScope?: boolean, + ): IApplicationLoadBalancer { const props = BaseLoadBalancer._queryContextProvider(scope, { userOptions: options, loadBalancerType: cxschema.LoadBalancerType.APPLICATION, - }); + }, linkContextToScope); return new LookedUpApplicationLoadBalancer(scope, id, props); } diff --git a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/nlb/network-listener.ts b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/nlb/network-listener.ts index 191a9251d4ff9..8645c3afdb52e 100644 --- a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/nlb/network-listener.ts +++ b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/nlb/network-listener.ts @@ -117,8 +117,10 @@ export interface NetworkListenerLookupOptions extends BaseListenerLookupOptions export class NetworkListener extends BaseListener implements INetworkListener { /** * Looks up a network listener + * + * If linkContextToScope is true, the cached context key will be tied to the passed scope rather than global */ - public static fromLookup(scope: Construct, id: string, options: NetworkListenerLookupOptions): INetworkListener { + public static fromLookup(scope: Construct, id: string, options: NetworkListenerLookupOptions, linkContextToScope?: boolean): INetworkListener { let listenerProtocol: cxschema.LoadBalancerListenerProtocol | undefined; if (options.listenerProtocol) { validateNetworkProtocol(options.listenerProtocol); @@ -135,7 +137,7 @@ export class NetworkListener extends BaseListener implements INetworkListener { userOptions: options, listenerProtocol: listenerProtocol, loadBalancerType: cxschema.LoadBalancerType.NETWORK, - }); + }, linkContextToScope); class LookedUp extends Resource implements INetworkListener { public listenerArn = props.listenerArn; diff --git a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/nlb/network-load-balancer.ts b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/nlb/network-load-balancer.ts index ff512bc0e1613..d36f450fd8a22 100644 --- a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/nlb/network-load-balancer.ts +++ b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/nlb/network-load-balancer.ts @@ -128,12 +128,19 @@ class NetworkLoadBalancerMetrics implements INetworkLoadBalancerMetrics { export class NetworkLoadBalancer extends BaseLoadBalancer implements INetworkLoadBalancer { /** * Looks up the network load balancer. + * + * If linkContextToScope is true, the cached context key will be tied to the passed scope rather than global */ - public static fromLookup(scope: Construct, id: string, options: NetworkLoadBalancerLookupOptions): INetworkLoadBalancer { + public static fromLookup( + scope: Construct, + id: string, + options: NetworkLoadBalancerLookupOptions, + linkContextToScope?: boolean, + ): INetworkLoadBalancer { const props = BaseLoadBalancer._queryContextProvider(scope, { userOptions: options, loadBalancerType: cxschema.LoadBalancerType.NETWORK, - }); + }, linkContextToScope); return new LookedUpNetworkLoadBalancer(scope, id, props); } diff --git a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-listener.ts b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-listener.ts index 72dad641eb2d7..56a0a59912c9f 100644 --- a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-listener.ts +++ b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-listener.ts @@ -76,7 +76,7 @@ export abstract class BaseListener extends Resource implements IListener { * listener info. * @internal */ - protected static _queryContextProvider(scope: Construct, options: ListenerQueryContextProviderOptions) { + protected static _queryContextProvider(scope: Construct, options: ListenerQueryContextProviderOptions, linkContextToScope?: boolean) { if (Token.isUnresolved(options.userOptions.loadBalancerArn) || Object.values(options.userOptions.loadBalancerTags ?? {}).some(Token.isUnresolved) || Token.isUnresolved(options.userOptions.listenerPort)) { @@ -104,6 +104,7 @@ export abstract class BaseListener extends Resource implements IListener { listenerPort: 80, securityGroupIds: ['sg-123456789012'], } as cxapi.LoadBalancerListenerContextResponse, + includeScope: linkContextToScope, }).value; return props; diff --git a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts index 436dbf54254ae..bf3033d397e90 100644 --- a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts +++ b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts @@ -110,7 +110,11 @@ export abstract class BaseLoadBalancer extends Resource { * Queries the load balancer context provider for load balancer info. * @internal */ - protected static _queryContextProvider(scope: Construct, options: LoadBalancerQueryContextProviderOptions) { + protected static _queryContextProvider( + scope: Construct, + options: LoadBalancerQueryContextProviderOptions, + contextCachelinkContextToScope?: boolean, + ) { if (Token.isUnresolved(options.userOptions.loadBalancerArn) || Object.values(options.userOptions.loadBalancerTags ?? {}).some(Token.isUnresolved)) { throw new Error('All arguments to look up a load balancer must be concrete (no Tokens)'); @@ -137,6 +141,7 @@ export abstract class BaseLoadBalancer extends Resource { securityGroupIds: ['sg-1234'], vpcId: 'vpc-12345', } as cxapi.LoadBalancerContextResponse, + includeScope: contextCachelinkContextToScope, }).value; return props; diff --git a/packages/aws-cdk-lib/aws-kms/README.md b/packages/aws-cdk-lib/aws-kms/README.md index b5a5786cc7225..7e263ec23f309 100644 --- a/packages/aws-cdk-lib/aws-kms/README.md +++ b/packages/aws-cdk-lib/aws-kms/README.md @@ -95,6 +95,10 @@ The result of the `Key.fromLookup()` operation will be written to a file called `cdk.context.json`. You must commit this file to source control so that the lookup values are available in non-privileged environments such as CI build steps, and to ensure your template builds are repeatable. +If you want the key of the context variable to be tied to the scope +passed to `fromLookup` instead of being global (usinwhich would use the same +value any time you call `fromLookup` across your entire app), +you can set the `linkContextToScope` argument to `true` Here's how `Key.fromLookup()` can be used: diff --git a/packages/aws-cdk-lib/aws-kms/lib/key.ts b/packages/aws-cdk-lib/aws-kms/lib/key.ts index 3b267d79d0c14..2105667afd879 100644 --- a/packages/aws-cdk-lib/aws-kms/lib/key.ts +++ b/packages/aws-cdk-lib/aws-kms/lib/key.ts @@ -622,8 +622,10 @@ export class Key extends KeyBase { * will be used on future runs. To refresh the lookup, you will have to * evict the value from the cache using the `cdk context` command. See * https://docs.aws.amazon.com/cdk/latest/guide/context.html for more information. + * + * If linkContextToScope is true, the context key will be tied to the passed scope rather than global */ - public static fromLookup(scope: Construct, id: string, options: KeyLookupOptions): IKey { + public static fromLookup(scope: Construct, id: string, options: KeyLookupOptions, linkContextToScope?: boolean): IKey { class Import extends KeyBase { public readonly keyArn: string; public readonly keyId: string; @@ -652,6 +654,7 @@ export class Key extends KeyBase { dummyValue: { keyId: '1234abcd-12ab-34cd-56ef-1234567890ab', }, + includeScope: linkContextToScope, }).value; return new Import(attributes.keyId, diff --git a/packages/aws-cdk-lib/aws-route53/README.md b/packages/aws-cdk-lib/aws-route53/README.md index 91dc7baeee353..06aa42f6681bd 100644 --- a/packages/aws-cdk-lib/aws-route53/README.md +++ b/packages/aws-cdk-lib/aws-route53/README.md @@ -247,6 +247,15 @@ route53.HostedZone.fromLookup(this, 'MyZone', { }); ``` +The result of the `HostedZone.fromLookup()` operation will be written to a file +called `cdk.context.json`. You must commit this file to source control so +that the lookup values are available in non-privileged environments such +as CI build steps, and to ensure your template builds are repeatable. +If you want the key of the context variable to be tied to the scope +passed to `fromLookup` instead of being global (usinwhich would use the same +value any time you call `fromLookup` across your entire app), +you can set the `linkContextToScope` argument to `true` + `HostedZone.fromLookup` requires an environment to be configured. Check out the [documentation](https://docs.aws.amazon.com/cdk/latest/guide/environments.html) for more documentation and examples. CDK automatically looks into your `~/.aws/config` file for the `[default]` profile. diff --git a/packages/aws-cdk-lib/aws-route53/lib/hosted-zone.ts b/packages/aws-cdk-lib/aws-route53/lib/hosted-zone.ts index d9361ee2b2d08..317cb06079820 100644 --- a/packages/aws-cdk-lib/aws-route53/lib/hosted-zone.ts +++ b/packages/aws-cdk-lib/aws-route53/lib/hosted-zone.ts @@ -122,9 +122,11 @@ export class HostedZone extends Resource implements IHostedZone { * * Use to easily query hosted zones. * + * If linkContextToScope is true, the context key will be tied to the passed scope rather than global + * * @see https://docs.aws.amazon.com/cdk/latest/guide/environments.html */ - public static fromLookup(scope: Construct, id: string, query: HostedZoneProviderProps): IHostedZone { + public static fromLookup(scope: Construct, id: string, query: HostedZoneProviderProps, linkContextToScope?: boolean): IHostedZone { if (!query.domainName) { throw new Error('Cannot use undefined value for attribute `domainName`'); } @@ -143,6 +145,7 @@ export class HostedZone extends Resource implements IHostedZone { provider: cxschema.ContextProvider.HOSTED_ZONE_PROVIDER, dummyValue: DEFAULT_HOSTED_ZONE, props: query, + includeScope: linkContextToScope, }).value; // CDK handles the '.' at the end, so remove it here diff --git a/packages/aws-cdk-lib/aws-route53/test/hosted-zone-provider.test.ts b/packages/aws-cdk-lib/aws-route53/test/hosted-zone-provider.test.ts index 94a42bdf85920..085204e50b872 100644 --- a/packages/aws-cdk-lib/aws-route53/test/hosted-zone-provider.test.ts +++ b/packages/aws-cdk-lib/aws-route53/test/hosted-zone-provider.test.ts @@ -41,7 +41,7 @@ describe('hosted zone provider', () => { expect(zoneRef.hostedZoneId).toEqual(fakeZoneId); }); - test('HostedZoneProvider will return context values if available when using plain hosted zone id', () => { + test('HostedZoneProvider will return context values if available when linked to scope', () => { // GIVEN const app = new cdk.App(); const stack = new cdk.Stack(app, 'TestStack', { @@ -81,5 +81,43 @@ describe('hosted zone provider', () => { expect(fakeZoneId).toEqual(zoneId); }); + + test('HostedZoneProvider will return context values if available', () => { + // GIVEN + const app = new cdk.App(); + const stack = new cdk.Stack(app, 'TestStack', { + env: { account: '12345', region: 'us-east-1' }, + }); + const filter = { domainName: 'test.com' }; + + HostedZone.fromLookup(stack, 'Ref', filter, true); + + const assembly = app.synth().getStackArtifact(stack.artifactId); + const missing = assembly.assembly.manifest.missing!; + expect(missing && missing.length === 1).toEqual(true); + + const fakeZoneId = '11111111111111'; + const fakeZone = { + Id: `/hostedzone/${fakeZoneId}`, + Name: 'example.com.', + CallerReference: 'TestLates-PublicZo-OESZPDFV7G6A', + Config: { + Comment: 'CDK created', + PrivateZone: false, + }, + ResourceRecordSetCount: 3, + }; + + const stack2 = new cdk.Stack(undefined, 'TestStack', { + env: { account: '12345', region: 'us-east-1' }, + }); + stack2.node.setContext(missing[0].key, fakeZone); + + // WHEN + const zoneRef = HostedZone.fromLookup(stack2, 'MyZoneProvider', filter, true); + + // THEN + expect(zoneRef.hostedZoneId).toEqual(fakeZoneId); + }); }); }); diff --git a/packages/aws-cdk-lib/aws-ssm/README.md b/packages/aws-cdk-lib/aws-ssm/README.md index e70e424f0573b..32e964b215702 100644 --- a/packages/aws-cdk-lib/aws-ssm/README.md +++ b/packages/aws-cdk-lib/aws-ssm/README.md @@ -58,6 +58,16 @@ This method uses AWS API calls to lookup the value from SSM during synthesis. const stringValue = ssm.StringParameter.valueFromLookup(this, '/My/Public/Parameter'); ``` +The result of the `StringParameter.valueFromLookup()` operation will be written to a file +called `cdk.context.json`. You must commit this file to source control so +that the lookup values are available in non-privileged environments such +as CI build steps, and to ensure your template builds are repeatable. +If you want the key of the context variable to be tied to the scope +passed to `fromLookup` instead of being global (usinwhich would use the same +value any time you call `fromLookup` across your entire app), +you can set the `linkContextToScope` argument to `true` + + When using `valueFromLookup` an initial value of 'dummy-value-for-${parameterName}' (`dummy-value-for-/My/Public/Parameter` in the above example) is returned prior to the lookup being performed. This can lead to errors if you are using this diff --git a/packages/aws-cdk-lib/aws-ssm/lib/parameter.ts b/packages/aws-cdk-lib/aws-ssm/lib/parameter.ts index a5e8726127cd6..205a526be5bf0 100644 --- a/packages/aws-cdk-lib/aws-ssm/lib/parameter.ts +++ b/packages/aws-cdk-lib/aws-ssm/lib/parameter.ts @@ -531,12 +531,17 @@ export class StringParameter extends ParameterBase implements IStringParameter { * * Requires that the stack this scope is defined in will have explicit * account/region information. Otherwise, it will fail during synthesis. + * + * If linkContextToScope is true, the context key will be tied to the passed scope rather than global */ - public static valueFromLookup(scope: Construct, parameterName: string): string { + public static valueFromLookup(scope: Construct, parameterName: string, linkContextToScope?: boolean): string { const value = ContextProvider.getValue(scope, { provider: cxschema.ContextProvider.SSM_PARAMETER_PROVIDER, - props: { parameterName }, - dummyValue: `dummy-value-for-${parameterName}`, + props: { + parameterName, + }, + dummyValue: linkContextToScope ? `dummy-value-for-${scope.node.path}-${parameterName}` : `dummy-value-for-${parameterName}`, + includeScope: linkContextToScope, }).value; return value; diff --git a/packages/aws-cdk-lib/aws-ssm/test/parameter.test.ts b/packages/aws-cdk-lib/aws-ssm/test/parameter.test.ts index 8e0c20abd426d..8297a38828241 100644 --- a/packages/aws-cdk-lib/aws-ssm/test/parameter.test.ts +++ b/packages/aws-cdk-lib/aws-ssm/test/parameter.test.ts @@ -652,6 +652,30 @@ test('fromLookup will use the SSM context provider to read value during synthesi ]); }); +test('fromLookup will use the SSM context provider to read value during synthesis when linked to scope', () => { + // GIVEN + const app = new cdk.App({ context: { [cxapi.NEW_STYLE_STACK_SYNTHESIS_CONTEXT]: false } }); + const stack = new cdk.Stack(app, 'my-staq', { env: { region: 'us-east-1', account: '12344' } }); + + // WHEN + const value = ssm.StringParameter.valueFromLookup(stack, 'my-param-name', true); + + // THEN + expect(value).toEqual('dummy-value-for-my-staq-my-param-name'); + expect(app.synth().manifest.missing).toEqual([ + { + key: 'ssm:account=12344:parameterName=my-param-name:region=us-east-1:scope=my-staq', + props: { + account: '12344', + region: 'us-east-1', + parameterName: 'my-param-name', + scope: 'my-staq', + }, + provider: 'ssm', + }, + ]); +}); + describe('from string list parameter', () => { testDeprecated('valueForTypedStringParameter list type throws error', () => { // GIVEN diff --git a/packages/aws-cdk-lib/core/lib/context-provider.ts b/packages/aws-cdk-lib/core/lib/context-provider.ts index d0e79fc02c7fb..3a0cd5bd6249c 100644 --- a/packages/aws-cdk-lib/core/lib/context-provider.ts +++ b/packages/aws-cdk-lib/core/lib/context-provider.ts @@ -24,6 +24,13 @@ export interface GetContextKeyOptions { * @default true */ readonly includeEnvironment?: boolean; + + /** + * Whether to include the scope automatically + * + * @default false + */ + readonly includeScope?: boolean; } /** @@ -67,9 +74,11 @@ export class ContextProvider { public static getKey(scope: Construct, options: GetContextKeyOptions): GetContextKeyResult { const stack = Stack.of(scope); - const props = options.includeEnvironment ?? true - ? { account: stack.account, region: stack.region, ...options.props } - : (options.props ?? {}); + const props = { + ...((options.includeEnvironment ?? true) ? { account: stack.account, region: stack.region } : {}), + ...(options.includeScope ? { scope: scope.node.path } : {}), + ...options.props, + }; if (Object.values(props).find(x => Token.isUnresolved(x))) { throw new Error( diff --git a/packages/aws-cdk-lib/core/test/context.test.ts b/packages/aws-cdk-lib/core/test/context.test.ts index e7d8c638ed5de..0ea7aab2efac7 100644 --- a/packages/aws-cdk-lib/core/test/context.test.ts +++ b/packages/aws-cdk-lib/core/test/context.test.ts @@ -134,6 +134,34 @@ describe('context', () => { }); }); + test('Key generation includes the scope when requested', () => { + // GIVEN + const stack = new Stack(undefined, 'TestStack', { env: { account: '12345', region: 'us-east-1' } }); + const resource = new Construct(stack, 'resource'); + + // WHEN + const result = ContextProvider.getKey(resource, { + provider: 'provider', + props: { + p1: 42, + p2: undefined, + }, + includeScope: true, + }); + + // THEN + expect(result).toEqual({ + key: 'provider:account=12345:p1=42:region=us-east-1:scope=TestStack/resource', + props: { + account: '12345', + region: 'us-east-1', + p1: 42, + p2: undefined, + scope: 'TestStack/resource', + }, + }); + }); + test('context provider errors are attached to tree', () => { const contextProps = { provider: 'availability-zones' }; const contextKey = 'availability-zones:account=12345:region=us-east-1'; // Depends on the mangling algo From 00cc494501e83d9c1f761771481a951a93e092fd Mon Sep 17 00:00:00 2001 From: Jonathan Romano Date: Sat, 2 Sep 2023 01:32:18 -0400 Subject: [PATCH 02/22] linkContextToScope should be passed to LookupMachineImage props not getImage --- .../aws-ec2/lib/machine-image/machine-image.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/machine-image.ts b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/machine-image.ts index 397dd3eede5b7..57164c64b9a1d 100644 --- a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/machine-image.ts +++ b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/machine-image.ts @@ -669,6 +669,7 @@ export class GenericWindowsImage implements IMachineImage { * will be used on future runs. To refresh the AMI lookup, you will have to * evict the value from the cache using the `cdk context` command. See * https://docs.aws.amazon.com/cdk/latest/guide/context.html for more information. + * If `props.linkContextToScope` is true, the context key will be tied to the passed scope rather than global */ export class LookupMachineImage implements IMachineImage { constructor(private readonly props: LookupMachineImageProps) { @@ -676,10 +677,8 @@ export class LookupMachineImage implements IMachineImage { /** * Return the correct image - * - * If linkContextToScope is true, the context key will be tied to the passed scope rather than global */ - public getImage(scope: Construct, linkContextToScope?: boolean): MachineImageConfig { + public getImage(scope: Construct): MachineImageConfig { // Need to know 'windows' or not before doing the query to return the right // osType for the dummy value, so might as well add it to the filter. const filters: Record = { @@ -697,7 +696,7 @@ export class LookupMachineImage implements IMachineImage { filters, } as cxschema.AmiContextQuery, dummyValue: 'ami-1234', - includeScope: linkContextToScope, + includeScope: this.props.linkContextToScope, }).value as cxapi.AmiContextResponse; if (typeof value !== 'string') { @@ -751,5 +750,12 @@ export interface LookupMachineImageProps { * @default - Empty user data appropriate for the platform type */ readonly userData?: UserData; + + /** + * If true, the context key will be tied to the passed scope rather than global + * + * @default false + */ + readonly linkContextToScope?: boolean } From 015bad159170791bac04bbf268a3f749fe923d60 Mon Sep 17 00:00:00 2001 From: Jonathan Romano Date: Sat, 2 Sep 2023 01:32:42 -0400 Subject: [PATCH 03/22] Fix missing passthroughs of linkContextToScope --- .../aws-ec2/lib/machine-image/amazon-linux-2022.ts | 1 + .../aws-ec2/lib/machine-image/amazon-linux-2023.ts | 1 + .../aws-cdk-lib/aws-ec2/lib/machine-image/amazon-linux2.ts | 1 + packages/aws-cdk-lib/aws-ec2/lib/machine-image/common.ts | 4 +++- 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/amazon-linux-2022.ts b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/amazon-linux-2022.ts index 06f40de63bae0..123dc925f6c7a 100644 --- a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/amazon-linux-2022.ts +++ b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/amazon-linux-2022.ts @@ -84,6 +84,7 @@ export class AmazonLinux2022ImageSsmParameter extends AmazonLinuxImageSsmParamet super({ parameterName: AmazonLinux2022ImageSsmParameter.ssmParameterName(props), cachedInContext: props.cachedInContext, + linkContextToScope: props.linkContextToScope, userData: props.userData, }); } diff --git a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/amazon-linux-2023.ts b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/amazon-linux-2023.ts index d00bad8d84c96..62da6e959509a 100644 --- a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/amazon-linux-2023.ts +++ b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/amazon-linux-2023.ts @@ -83,6 +83,7 @@ export class AmazonLinux2023ImageSsmParameter extends AmazonLinuxImageSsmParamet super({ parameterName: AmazonLinux2023ImageSsmParameter.ssmParameterName(props), cachedInContext: props.cachedInContext, + linkContextToScope: props.linkContextToScope, userData: props.userData, }); } diff --git a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/amazon-linux2.ts b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/amazon-linux2.ts index a037a61a80851..310d425e10ec6 100644 --- a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/amazon-linux2.ts +++ b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/amazon-linux2.ts @@ -103,6 +103,7 @@ export class AmazonLinux2ImageSsmParameter extends AmazonLinuxImageSsmParameterB super({ parameterName: AmazonLinux2ImageSsmParameter.ssmParameterName(props), cachedInContext: props.cachedInContext, + linkContextToScope: props.linkContextToScope, userData: props.userData, }); } diff --git a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/common.ts b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/common.ts index 681bcb54fe8a3..55e3c7cc051af 100644 --- a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/common.ts +++ b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/common.ts @@ -73,12 +73,14 @@ export interface AmazonLinuxImageSsmParameterBaseProps extends AmazonLinuxImageS export abstract class AmazonLinuxImageSsmParameterBase implements IMachineImage { private readonly cachedInContext: boolean; + private readonly linkContextToScope: boolean; constructor(private readonly props: AmazonLinuxImageSsmParameterBaseProps) { this.cachedInContext = this.props.cachedInContext ?? true; + this.linkContextToScope = this.props.linkContextToScope ?? true; } getImage(scope: Construct): MachineImageConfig { - const imageId = lookupImage(scope, this.cachedInContext, this.props.parameterName); + const imageId = lookupImage(scope, this.cachedInContext && this.linkContextToScope ? 'scope' : this.cachedInContext, this.props.parameterName); const osType = OperatingSystemType.LINUX; return { From d8d27f935790719d1ef5a022e34aae24c14a8de4 Mon Sep 17 00:00:00 2001 From: Jonathan Romano Date: Sat, 2 Sep 2023 01:33:09 -0400 Subject: [PATCH 04/22] Add integration test for cached machine image lookup --- .../cdk.out | 1 + ...-ec2-machine-image-cached-test.assets.json | 20 + ...c2-machine-image-cached-test.template.json | 742 ++++++++++ .../integ.json | 13 + ...efaultTestDeployAssert24D5C536.assets.json | 19 + ...aultTestDeployAssert24D5C536.template.json | 36 + .../manifest.json | 375 +++++ .../tree.json | 1300 +++++++++++++++++ .../test/integ.machine-image-cached.ts | 53 + 9 files changed, 2559 insertions(+) create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/cdk.out create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ-ec2-machine-image-cached-test.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ-ec2-machine-image-cached-test.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integtestDefaultTestDeployAssert24D5C536.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integtestDefaultTestDeployAssert24D5C536.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/manifest.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/tree.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.ts diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/cdk.out new file mode 100644 index 0000000000000..2313ab5436501 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"34.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ-ec2-machine-image-cached-test.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ-ec2-machine-image-cached-test.assets.json new file mode 100644 index 0000000000000..72a63a5679816 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ-ec2-machine-image-cached-test.assets.json @@ -0,0 +1,20 @@ +{ + "version": "34.0.0", + "files": { + "6110c57085f3942fd06f447c35d36d8649b434ca69763c6e7c0adce298dfeef1": { + "source": { + "path": "integ-ec2-machine-image-cached-test.template.json", + "packaging": "file" + }, + "destinations": { + "12345678-test-region": { + "bucketName": "cdk-hnb659fds-assets-12345678-test-region", + "objectKey": "6110c57085f3942fd06f447c35d36d8649b434ca69763c6e7c0adce298dfeef1.json", + "region": "test-region", + "assumeRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-file-publishing-role-12345678-test-region" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ-ec2-machine-image-cached-test.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ-ec2-machine-image-cached-test.template.json new file mode 100644 index 0000000000000..08bb9c6db64d4 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ-ec2-machine-image-cached-test.template.json @@ -0,0 +1,742 @@ +{ + "Resources": { + "Vpc8378EB38": { + "Type": "AWS::EC2::VPC", + "Properties": { + "CidrBlock": "10.0.0.0/16", + "EnableDnsHostnames": true, + "EnableDnsSupport": true, + "InstanceTenancy": "default", + "Tags": [ + { + "Key": "Name", + "Value": "integ-ec2-machine-image-cached-test/Vpc" + } + ] + } + }, + "VpcPublicSubnet1Subnet5C2D37C4": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "AvailabilityZone": "test-region-1a", + "CidrBlock": "10.0.0.0/19", + "MapPublicIpOnLaunch": true, + "Tags": [ + { + "Key": "aws-cdk:subnet-name", + "Value": "Public" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Public" + }, + { + "Key": "Name", + "Value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1" + } + ], + "VpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "VpcPublicSubnet1RouteTable6C95E38E": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1" + } + ], + "VpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "VpcPublicSubnet1RouteTableAssociation97140677": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "VpcPublicSubnet1RouteTable6C95E38E" + }, + "SubnetId": { + "Ref": "VpcPublicSubnet1Subnet5C2D37C4" + } + } + }, + "VpcPublicSubnet1DefaultRoute3DA9E72A": { + "Type": "AWS::EC2::Route", + "Properties": { + "DestinationCidrBlock": "0.0.0.0/0", + "GatewayId": { + "Ref": "VpcIGWD7BA715C" + }, + "RouteTableId": { + "Ref": "VpcPublicSubnet1RouteTable6C95E38E" + } + }, + "DependsOn": [ + "VpcVPCGWBF912B6E" + ] + }, + "VpcPublicSubnet1EIPD7E02669": { + "Type": "AWS::EC2::EIP", + "Properties": { + "Domain": "vpc", + "Tags": [ + { + "Key": "Name", + "Value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1" + } + ] + } + }, + "VpcPublicSubnet1NATGateway4D7517AA": { + "Type": "AWS::EC2::NatGateway", + "Properties": { + "AllocationId": { + "Fn::GetAtt": [ + "VpcPublicSubnet1EIPD7E02669", + "AllocationId" + ] + }, + "SubnetId": { + "Ref": "VpcPublicSubnet1Subnet5C2D37C4" + }, + "Tags": [ + { + "Key": "Name", + "Value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1" + } + ] + }, + "DependsOn": [ + "VpcPublicSubnet1DefaultRoute3DA9E72A", + "VpcPublicSubnet1RouteTableAssociation97140677" + ] + }, + "VpcPublicSubnet2Subnet691E08A3": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "AvailabilityZone": "test-region-1b", + "CidrBlock": "10.0.32.0/19", + "MapPublicIpOnLaunch": true, + "Tags": [ + { + "Key": "aws-cdk:subnet-name", + "Value": "Public" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Public" + }, + { + "Key": "Name", + "Value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2" + } + ], + "VpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "VpcPublicSubnet2RouteTable94F7E489": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2" + } + ], + "VpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "VpcPublicSubnet2RouteTableAssociationDD5762D8": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "VpcPublicSubnet2RouteTable94F7E489" + }, + "SubnetId": { + "Ref": "VpcPublicSubnet2Subnet691E08A3" + } + } + }, + "VpcPublicSubnet2DefaultRoute97F91067": { + "Type": "AWS::EC2::Route", + "Properties": { + "DestinationCidrBlock": "0.0.0.0/0", + "GatewayId": { + "Ref": "VpcIGWD7BA715C" + }, + "RouteTableId": { + "Ref": "VpcPublicSubnet2RouteTable94F7E489" + } + }, + "DependsOn": [ + "VpcVPCGWBF912B6E" + ] + }, + "VpcPublicSubnet2EIP3C605A87": { + "Type": "AWS::EC2::EIP", + "Properties": { + "Domain": "vpc", + "Tags": [ + { + "Key": "Name", + "Value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2" + } + ] + } + }, + "VpcPublicSubnet2NATGateway9182C01D": { + "Type": "AWS::EC2::NatGateway", + "Properties": { + "AllocationId": { + "Fn::GetAtt": [ + "VpcPublicSubnet2EIP3C605A87", + "AllocationId" + ] + }, + "SubnetId": { + "Ref": "VpcPublicSubnet2Subnet691E08A3" + }, + "Tags": [ + { + "Key": "Name", + "Value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2" + } + ] + }, + "DependsOn": [ + "VpcPublicSubnet2DefaultRoute97F91067", + "VpcPublicSubnet2RouteTableAssociationDD5762D8" + ] + }, + "VpcPublicSubnet3SubnetBE12F0B6": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "AvailabilityZone": "test-region-1c", + "CidrBlock": "10.0.64.0/19", + "MapPublicIpOnLaunch": true, + "Tags": [ + { + "Key": "aws-cdk:subnet-name", + "Value": "Public" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Public" + }, + { + "Key": "Name", + "Value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3" + } + ], + "VpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "VpcPublicSubnet3RouteTable93458DBB": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3" + } + ], + "VpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "VpcPublicSubnet3RouteTableAssociation1F1EDF02": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "VpcPublicSubnet3RouteTable93458DBB" + }, + "SubnetId": { + "Ref": "VpcPublicSubnet3SubnetBE12F0B6" + } + } + }, + "VpcPublicSubnet3DefaultRoute4697774F": { + "Type": "AWS::EC2::Route", + "Properties": { + "DestinationCidrBlock": "0.0.0.0/0", + "GatewayId": { + "Ref": "VpcIGWD7BA715C" + }, + "RouteTableId": { + "Ref": "VpcPublicSubnet3RouteTable93458DBB" + } + }, + "DependsOn": [ + "VpcVPCGWBF912B6E" + ] + }, + "VpcPublicSubnet3EIP3A666A23": { + "Type": "AWS::EC2::EIP", + "Properties": { + "Domain": "vpc", + "Tags": [ + { + "Key": "Name", + "Value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3" + } + ] + } + }, + "VpcPublicSubnet3NATGateway7640CD1D": { + "Type": "AWS::EC2::NatGateway", + "Properties": { + "AllocationId": { + "Fn::GetAtt": [ + "VpcPublicSubnet3EIP3A666A23", + "AllocationId" + ] + }, + "SubnetId": { + "Ref": "VpcPublicSubnet3SubnetBE12F0B6" + }, + "Tags": [ + { + "Key": "Name", + "Value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3" + } + ] + }, + "DependsOn": [ + "VpcPublicSubnet3DefaultRoute4697774F", + "VpcPublicSubnet3RouteTableAssociation1F1EDF02" + ] + }, + "VpcPrivateSubnet1Subnet536B997A": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "AvailabilityZone": "test-region-1a", + "CidrBlock": "10.0.96.0/19", + "MapPublicIpOnLaunch": false, + "Tags": [ + { + "Key": "aws-cdk:subnet-name", + "Value": "Private" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Private" + }, + { + "Key": "Name", + "Value": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet1" + } + ], + "VpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "VpcPrivateSubnet1RouteTableB2C5B500": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet1" + } + ], + "VpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "VpcPrivateSubnet1RouteTableAssociation70C59FA6": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "VpcPrivateSubnet1RouteTableB2C5B500" + }, + "SubnetId": { + "Ref": "VpcPrivateSubnet1Subnet536B997A" + } + } + }, + "VpcPrivateSubnet1DefaultRouteBE02A9ED": { + "Type": "AWS::EC2::Route", + "Properties": { + "DestinationCidrBlock": "0.0.0.0/0", + "NatGatewayId": { + "Ref": "VpcPublicSubnet1NATGateway4D7517AA" + }, + "RouteTableId": { + "Ref": "VpcPrivateSubnet1RouteTableB2C5B500" + } + } + }, + "VpcPrivateSubnet2Subnet3788AAA1": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "AvailabilityZone": "test-region-1b", + "CidrBlock": "10.0.128.0/19", + "MapPublicIpOnLaunch": false, + "Tags": [ + { + "Key": "aws-cdk:subnet-name", + "Value": "Private" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Private" + }, + { + "Key": "Name", + "Value": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet2" + } + ], + "VpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "VpcPrivateSubnet2RouteTableA678073B": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet2" + } + ], + "VpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "VpcPrivateSubnet2RouteTableAssociationA89CAD56": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "VpcPrivateSubnet2RouteTableA678073B" + }, + "SubnetId": { + "Ref": "VpcPrivateSubnet2Subnet3788AAA1" + } + } + }, + "VpcPrivateSubnet2DefaultRoute060D2087": { + "Type": "AWS::EC2::Route", + "Properties": { + "DestinationCidrBlock": "0.0.0.0/0", + "NatGatewayId": { + "Ref": "VpcPublicSubnet2NATGateway9182C01D" + }, + "RouteTableId": { + "Ref": "VpcPrivateSubnet2RouteTableA678073B" + } + } + }, + "VpcPrivateSubnet3SubnetF258B56E": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "AvailabilityZone": "test-region-1c", + "CidrBlock": "10.0.160.0/19", + "MapPublicIpOnLaunch": false, + "Tags": [ + { + "Key": "aws-cdk:subnet-name", + "Value": "Private" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Private" + }, + { + "Key": "Name", + "Value": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet3" + } + ], + "VpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "VpcPrivateSubnet3RouteTableD98824C7": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet3" + } + ], + "VpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "VpcPrivateSubnet3RouteTableAssociation16BDDC43": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "VpcPrivateSubnet3RouteTableD98824C7" + }, + "SubnetId": { + "Ref": "VpcPrivateSubnet3SubnetF258B56E" + } + } + }, + "VpcPrivateSubnet3DefaultRoute94B74F0D": { + "Type": "AWS::EC2::Route", + "Properties": { + "DestinationCidrBlock": "0.0.0.0/0", + "NatGatewayId": { + "Ref": "VpcPublicSubnet3NATGateway7640CD1D" + }, + "RouteTableId": { + "Ref": "VpcPrivateSubnet3RouteTableD98824C7" + } + } + }, + "VpcIGWD7BA715C": { + "Type": "AWS::EC2::InternetGateway", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "integ-ec2-machine-image-cached-test/Vpc" + } + ] + } + }, + "VpcVPCGWBF912B6E": { + "Type": "AWS::EC2::VPCGatewayAttachment", + "Properties": { + "InternetGatewayId": { + "Ref": "VpcIGWD7BA715C" + }, + "VpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "al2023CachedInstanceSecurityGroup2719C9BA": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "integ-ec2-machine-image-cached-test/al2023Cached/InstanceSecurityGroup", + "SecurityGroupEgress": [ + { + "CidrIp": "0.0.0.0/0", + "Description": "Allow all outbound traffic by default", + "IpProtocol": "-1" + } + ], + "Tags": [ + { + "Key": "Name", + "Value": "integ-ec2-machine-image-cached-test/al2023Cached" + } + ], + "VpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "al2023CachedInstanceRoleD76E1DF5": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "ec2.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "Tags": [ + { + "Key": "Name", + "Value": "integ-ec2-machine-image-cached-test/al2023Cached" + } + ] + } + }, + "al2023CachedInstanceProfileD264357E": { + "Type": "AWS::IAM::InstanceProfile", + "Properties": { + "Roles": [ + { + "Ref": "al2023CachedInstanceRoleD76E1DF5" + } + ] + } + }, + "al2023Cached1FFF710B": { + "Type": "AWS::EC2::Instance", + "Properties": { + "AvailabilityZone": "test-region-1a", + "IamInstanceProfile": { + "Ref": "al2023CachedInstanceProfileD264357E" + }, + "ImageId": "dummy-value-for-integ-ec2-machine-image-cached-test/al2023Cached-/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64", + "InstanceType": "t2.nano", + "SecurityGroupIds": [ + { + "Fn::GetAtt": [ + "al2023CachedInstanceSecurityGroup2719C9BA", + "GroupId" + ] + } + ], + "SubnetId": { + "Ref": "VpcPrivateSubnet1Subnet536B997A" + }, + "Tags": [ + { + "Key": "Name", + "Value": "integ-ec2-machine-image-cached-test/al2023Cached" + } + ], + "UserData": { + "Fn::Base64": "#!/bin/bash" + } + }, + "DependsOn": [ + "al2023CachedInstanceRoleD76E1DF5" + ] + }, + "al2023CachedScopeInstanceSecurityGroupADC3C195": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "integ-ec2-machine-image-cached-test/al2023CachedScope/InstanceSecurityGroup", + "SecurityGroupEgress": [ + { + "CidrIp": "0.0.0.0/0", + "Description": "Allow all outbound traffic by default", + "IpProtocol": "-1" + } + ], + "Tags": [ + { + "Key": "Name", + "Value": "integ-ec2-machine-image-cached-test/al2023CachedScope" + } + ], + "VpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "al2023CachedScopeInstanceRoleB7C63F12": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "ec2.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "Tags": [ + { + "Key": "Name", + "Value": "integ-ec2-machine-image-cached-test/al2023CachedScope" + } + ] + } + }, + "al2023CachedScopeInstanceProfileD8064966": { + "Type": "AWS::IAM::InstanceProfile", + "Properties": { + "Roles": [ + { + "Ref": "al2023CachedScopeInstanceRoleB7C63F12" + } + ] + } + }, + "al2023CachedScopeF8E30E37": { + "Type": "AWS::EC2::Instance", + "Properties": { + "AvailabilityZone": "test-region-1a", + "IamInstanceProfile": { + "Ref": "al2023CachedScopeInstanceProfileD8064966" + }, + "ImageId": "dummy-value-for-integ-ec2-machine-image-cached-test/al2023CachedScope-/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64", + "InstanceType": "t2.nano", + "SecurityGroupIds": [ + { + "Fn::GetAtt": [ + "al2023CachedScopeInstanceSecurityGroupADC3C195", + "GroupId" + ] + } + ], + "SubnetId": { + "Ref": "VpcPrivateSubnet1Subnet536B997A" + }, + "Tags": [ + { + "Key": "Name", + "Value": "integ-ec2-machine-image-cached-test/al2023CachedScope" + } + ], + "UserData": { + "Fn::Base64": "#!/bin/bash" + } + }, + "DependsOn": [ + "al2023CachedScopeInstanceRoleB7C63F12" + ] + } + }, + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ.json new file mode 100644 index 0000000000000..ca879e60af22b --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ.json @@ -0,0 +1,13 @@ +{ + "enableLookups": true, + "version": "34.0.0", + "testCases": { + "integ-test/DefaultTest": { + "stacks": [ + "integ-ec2-machine-image-cached-test" + ], + "assertionStack": "integ-test/DefaultTest/DeployAssert", + "assertionStackName": "integtestDefaultTestDeployAssert24D5C536" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integtestDefaultTestDeployAssert24D5C536.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integtestDefaultTestDeployAssert24D5C536.assets.json new file mode 100644 index 0000000000000..2b470996152e4 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integtestDefaultTestDeployAssert24D5C536.assets.json @@ -0,0 +1,19 @@ +{ + "version": "34.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "integtestDefaultTestDeployAssert24D5C536.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integtestDefaultTestDeployAssert24D5C536.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integtestDefaultTestDeployAssert24D5C536.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integtestDefaultTestDeployAssert24D5C536.template.json @@ -0,0 +1,36 @@ +{ + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/manifest.json new file mode 100644 index 0000000000000..1b167678e5497 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/manifest.json @@ -0,0 +1,375 @@ +{ + "version": "34.0.0", + "artifacts": { + "integ-ec2-machine-image-cached-test.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "integ-ec2-machine-image-cached-test.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "integ-ec2-machine-image-cached-test": { + "type": "aws:cloudformation:stack", + "environment": "aws://12345678/test-region", + "properties": { + "templateFile": "integ-ec2-machine-image-cached-test.template.json", + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-deploy-role-12345678-test-region", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-cfn-exec-role-12345678-test-region", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-12345678-test-region/6110c57085f3942fd06f447c35d36d8649b434ca69763c6e7c0adce298dfeef1.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "integ-ec2-machine-image-cached-test.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-lookup-role-12345678-test-region", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "integ-ec2-machine-image-cached-test.assets" + ], + "metadata": { + "/integ-ec2-machine-image-cached-test/Vpc/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "Vpc8378EB38" + } + ], + "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1/Subnet": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet1Subnet5C2D37C4" + } + ], + "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1/RouteTable": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet1RouteTable6C95E38E" + } + ], + "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1/RouteTableAssociation": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet1RouteTableAssociation97140677" + } + ], + "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1/DefaultRoute": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet1DefaultRoute3DA9E72A" + } + ], + "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1/EIP": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet1EIPD7E02669" + } + ], + "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1/NATGateway": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet1NATGateway4D7517AA" + } + ], + "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2/Subnet": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet2Subnet691E08A3" + } + ], + "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2/RouteTable": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet2RouteTable94F7E489" + } + ], + "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2/RouteTableAssociation": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet2RouteTableAssociationDD5762D8" + } + ], + "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2/DefaultRoute": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet2DefaultRoute97F91067" + } + ], + "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2/EIP": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet2EIP3C605A87" + } + ], + "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2/NATGateway": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet2NATGateway9182C01D" + } + ], + "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3/Subnet": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet3SubnetBE12F0B6" + } + ], + "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3/RouteTable": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet3RouteTable93458DBB" + } + ], + "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3/RouteTableAssociation": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet3RouteTableAssociation1F1EDF02" + } + ], + "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3/DefaultRoute": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet3DefaultRoute4697774F" + } + ], + "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3/EIP": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet3EIP3A666A23" + } + ], + "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3/NATGateway": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet3NATGateway7640CD1D" + } + ], + "/integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet1/Subnet": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPrivateSubnet1Subnet536B997A" + } + ], + "/integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet1/RouteTable": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPrivateSubnet1RouteTableB2C5B500" + } + ], + "/integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet1/RouteTableAssociation": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPrivateSubnet1RouteTableAssociation70C59FA6" + } + ], + "/integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet1/DefaultRoute": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPrivateSubnet1DefaultRouteBE02A9ED" + } + ], + "/integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet2/Subnet": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPrivateSubnet2Subnet3788AAA1" + } + ], + "/integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet2/RouteTable": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPrivateSubnet2RouteTableA678073B" + } + ], + "/integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet2/RouteTableAssociation": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPrivateSubnet2RouteTableAssociationA89CAD56" + } + ], + "/integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet2/DefaultRoute": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPrivateSubnet2DefaultRoute060D2087" + } + ], + "/integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet3/Subnet": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPrivateSubnet3SubnetF258B56E" + } + ], + "/integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet3/RouteTable": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPrivateSubnet3RouteTableD98824C7" + } + ], + "/integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet3/RouteTableAssociation": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPrivateSubnet3RouteTableAssociation16BDDC43" + } + ], + "/integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet3/DefaultRoute": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPrivateSubnet3DefaultRoute94B74F0D" + } + ], + "/integ-ec2-machine-image-cached-test/Vpc/IGW": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcIGWD7BA715C" + } + ], + "/integ-ec2-machine-image-cached-test/Vpc/VPCGW": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcVPCGWBF912B6E" + } + ], + "/integ-ec2-machine-image-cached-test/al2023Cached/InstanceSecurityGroup/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "al2023CachedInstanceSecurityGroup2719C9BA" + } + ], + "/integ-ec2-machine-image-cached-test/al2023Cached/InstanceRole/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "al2023CachedInstanceRoleD76E1DF5" + } + ], + "/integ-ec2-machine-image-cached-test/al2023Cached/InstanceProfile": [ + { + "type": "aws:cdk:logicalId", + "data": "al2023CachedInstanceProfileD264357E" + } + ], + "/integ-ec2-machine-image-cached-test/al2023Cached/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "al2023Cached1FFF710B" + } + ], + "/integ-ec2-machine-image-cached-test/al2023CachedScope/InstanceSecurityGroup/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "al2023CachedScopeInstanceSecurityGroupADC3C195" + } + ], + "/integ-ec2-machine-image-cached-test/al2023CachedScope/InstanceRole/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "al2023CachedScopeInstanceRoleB7C63F12" + } + ], + "/integ-ec2-machine-image-cached-test/al2023CachedScope/InstanceProfile": [ + { + "type": "aws:cdk:logicalId", + "data": "al2023CachedScopeInstanceProfileD8064966" + } + ], + "/integ-ec2-machine-image-cached-test/al2023CachedScope/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "al2023CachedScopeF8E30E37" + } + ], + "/integ-ec2-machine-image-cached-test/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/integ-ec2-machine-image-cached-test/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "integ-ec2-machine-image-cached-test" + }, + "integtestDefaultTestDeployAssert24D5C536.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "integtestDefaultTestDeployAssert24D5C536.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "integtestDefaultTestDeployAssert24D5C536": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "integtestDefaultTestDeployAssert24D5C536.template.json", + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "integtestDefaultTestDeployAssert24D5C536.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "integtestDefaultTestDeployAssert24D5C536.assets" + ], + "metadata": { + "/integ-test/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/integ-test/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "integ-test/DefaultTest/DeployAssert" + }, + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } + } + }, + "missing": [ + { + "key": "ssm:account=12345678:parameterName=/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64:region=test-region:scope=integ-ec2-machine-image-cached-test/al2023Cached", + "provider": "ssm", + "props": { + "account": "12345678", + "region": "test-region", + "scope": "integ-ec2-machine-image-cached-test/al2023Cached", + "parameterName": "/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64", + "lookupRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-lookup-role-12345678-test-region" + } + }, + { + "key": "ssm:account=12345678:parameterName=/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64:region=test-region:scope=integ-ec2-machine-image-cached-test/al2023CachedScope", + "provider": "ssm", + "props": { + "account": "12345678", + "region": "test-region", + "scope": "integ-ec2-machine-image-cached-test/al2023CachedScope", + "parameterName": "/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64", + "lookupRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-lookup-role-12345678-test-region" + } + } + ] +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/tree.json new file mode 100644 index 0000000000000..c56bff81ff346 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/tree.json @@ -0,0 +1,1300 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "integ-ec2-machine-image-cached-test": { + "id": "integ-ec2-machine-image-cached-test", + "path": "integ-ec2-machine-image-cached-test", + "children": { + "Vpc": { + "id": "Vpc", + "path": "integ-ec2-machine-image-cached-test/Vpc", + "children": { + "Resource": { + "id": "Resource", + "path": "integ-ec2-machine-image-cached-test/Vpc/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::VPC", + "aws:cdk:cloudformation:props": { + "cidrBlock": "10.0.0.0/16", + "enableDnsHostnames": true, + "enableDnsSupport": true, + "instanceTenancy": "default", + "tags": [ + { + "key": "Name", + "value": "integ-ec2-machine-image-cached-test/Vpc" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnVPC", + "version": "0.0.0" + } + }, + "PublicSubnet1": { + "id": "PublicSubnet1", + "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1", + "children": { + "Subnet": { + "id": "Subnet", + "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1/Subnet", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", + "aws:cdk:cloudformation:props": { + "availabilityZone": "test-region-1a", + "cidrBlock": "10.0.0.0/19", + "mapPublicIpOnLaunch": true, + "tags": [ + { + "key": "aws-cdk:subnet-name", + "value": "Public" + }, + { + "key": "aws-cdk:subnet-type", + "value": "Public" + }, + { + "key": "Name", + "value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1" + } + ], + "vpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnet", + "version": "0.0.0" + } + }, + "Acl": { + "id": "Acl", + "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1/Acl", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "RouteTable": { + "id": "RouteTable", + "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1/RouteTable", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", + "aws:cdk:cloudformation:props": { + "tags": [ + { + "key": "Name", + "value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1" + } + ], + "vpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnRouteTable", + "version": "0.0.0" + } + }, + "RouteTableAssociation": { + "id": "RouteTableAssociation", + "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1/RouteTableAssociation", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "VpcPublicSubnet1RouteTable6C95E38E" + }, + "subnetId": { + "Ref": "VpcPublicSubnet1Subnet5C2D37C4" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnetRouteTableAssociation", + "version": "0.0.0" + } + }, + "DefaultRoute": { + "id": "DefaultRoute", + "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1/DefaultRoute", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Route", + "aws:cdk:cloudformation:props": { + "destinationCidrBlock": "0.0.0.0/0", + "gatewayId": { + "Ref": "VpcIGWD7BA715C" + }, + "routeTableId": { + "Ref": "VpcPublicSubnet1RouteTable6C95E38E" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnRoute", + "version": "0.0.0" + } + }, + "EIP": { + "id": "EIP", + "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1/EIP", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::EIP", + "aws:cdk:cloudformation:props": { + "domain": "vpc", + "tags": [ + { + "key": "Name", + "value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnEIP", + "version": "0.0.0" + } + }, + "NATGateway": { + "id": "NATGateway", + "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1/NATGateway", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::NatGateway", + "aws:cdk:cloudformation:props": { + "allocationId": { + "Fn::GetAtt": [ + "VpcPublicSubnet1EIPD7E02669", + "AllocationId" + ] + }, + "subnetId": { + "Ref": "VpcPublicSubnet1Subnet5C2D37C4" + }, + "tags": [ + { + "key": "Name", + "value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnNatGateway", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.PublicSubnet", + "version": "0.0.0" + } + }, + "PublicSubnet2": { + "id": "PublicSubnet2", + "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2", + "children": { + "Subnet": { + "id": "Subnet", + "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2/Subnet", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", + "aws:cdk:cloudformation:props": { + "availabilityZone": "test-region-1b", + "cidrBlock": "10.0.32.0/19", + "mapPublicIpOnLaunch": true, + "tags": [ + { + "key": "aws-cdk:subnet-name", + "value": "Public" + }, + { + "key": "aws-cdk:subnet-type", + "value": "Public" + }, + { + "key": "Name", + "value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2" + } + ], + "vpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnet", + "version": "0.0.0" + } + }, + "Acl": { + "id": "Acl", + "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2/Acl", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "RouteTable": { + "id": "RouteTable", + "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2/RouteTable", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", + "aws:cdk:cloudformation:props": { + "tags": [ + { + "key": "Name", + "value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2" + } + ], + "vpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnRouteTable", + "version": "0.0.0" + } + }, + "RouteTableAssociation": { + "id": "RouteTableAssociation", + "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2/RouteTableAssociation", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "VpcPublicSubnet2RouteTable94F7E489" + }, + "subnetId": { + "Ref": "VpcPublicSubnet2Subnet691E08A3" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnetRouteTableAssociation", + "version": "0.0.0" + } + }, + "DefaultRoute": { + "id": "DefaultRoute", + "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2/DefaultRoute", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Route", + "aws:cdk:cloudformation:props": { + "destinationCidrBlock": "0.0.0.0/0", + "gatewayId": { + "Ref": "VpcIGWD7BA715C" + }, + "routeTableId": { + "Ref": "VpcPublicSubnet2RouteTable94F7E489" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnRoute", + "version": "0.0.0" + } + }, + "EIP": { + "id": "EIP", + "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2/EIP", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::EIP", + "aws:cdk:cloudformation:props": { + "domain": "vpc", + "tags": [ + { + "key": "Name", + "value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnEIP", + "version": "0.0.0" + } + }, + "NATGateway": { + "id": "NATGateway", + "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2/NATGateway", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::NatGateway", + "aws:cdk:cloudformation:props": { + "allocationId": { + "Fn::GetAtt": [ + "VpcPublicSubnet2EIP3C605A87", + "AllocationId" + ] + }, + "subnetId": { + "Ref": "VpcPublicSubnet2Subnet691E08A3" + }, + "tags": [ + { + "key": "Name", + "value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnNatGateway", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.PublicSubnet", + "version": "0.0.0" + } + }, + "PublicSubnet3": { + "id": "PublicSubnet3", + "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3", + "children": { + "Subnet": { + "id": "Subnet", + "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3/Subnet", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", + "aws:cdk:cloudformation:props": { + "availabilityZone": "test-region-1c", + "cidrBlock": "10.0.64.0/19", + "mapPublicIpOnLaunch": true, + "tags": [ + { + "key": "aws-cdk:subnet-name", + "value": "Public" + }, + { + "key": "aws-cdk:subnet-type", + "value": "Public" + }, + { + "key": "Name", + "value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3" + } + ], + "vpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnet", + "version": "0.0.0" + } + }, + "Acl": { + "id": "Acl", + "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3/Acl", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "RouteTable": { + "id": "RouteTable", + "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3/RouteTable", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", + "aws:cdk:cloudformation:props": { + "tags": [ + { + "key": "Name", + "value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3" + } + ], + "vpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnRouteTable", + "version": "0.0.0" + } + }, + "RouteTableAssociation": { + "id": "RouteTableAssociation", + "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3/RouteTableAssociation", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "VpcPublicSubnet3RouteTable93458DBB" + }, + "subnetId": { + "Ref": "VpcPublicSubnet3SubnetBE12F0B6" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnetRouteTableAssociation", + "version": "0.0.0" + } + }, + "DefaultRoute": { + "id": "DefaultRoute", + "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3/DefaultRoute", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Route", + "aws:cdk:cloudformation:props": { + "destinationCidrBlock": "0.0.0.0/0", + "gatewayId": { + "Ref": "VpcIGWD7BA715C" + }, + "routeTableId": { + "Ref": "VpcPublicSubnet3RouteTable93458DBB" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnRoute", + "version": "0.0.0" + } + }, + "EIP": { + "id": "EIP", + "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3/EIP", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::EIP", + "aws:cdk:cloudformation:props": { + "domain": "vpc", + "tags": [ + { + "key": "Name", + "value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnEIP", + "version": "0.0.0" + } + }, + "NATGateway": { + "id": "NATGateway", + "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3/NATGateway", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::NatGateway", + "aws:cdk:cloudformation:props": { + "allocationId": { + "Fn::GetAtt": [ + "VpcPublicSubnet3EIP3A666A23", + "AllocationId" + ] + }, + "subnetId": { + "Ref": "VpcPublicSubnet3SubnetBE12F0B6" + }, + "tags": [ + { + "key": "Name", + "value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnNatGateway", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.PublicSubnet", + "version": "0.0.0" + } + }, + "PrivateSubnet1": { + "id": "PrivateSubnet1", + "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet1", + "children": { + "Subnet": { + "id": "Subnet", + "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet1/Subnet", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", + "aws:cdk:cloudformation:props": { + "availabilityZone": "test-region-1a", + "cidrBlock": "10.0.96.0/19", + "mapPublicIpOnLaunch": false, + "tags": [ + { + "key": "aws-cdk:subnet-name", + "value": "Private" + }, + { + "key": "aws-cdk:subnet-type", + "value": "Private" + }, + { + "key": "Name", + "value": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet1" + } + ], + "vpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnet", + "version": "0.0.0" + } + }, + "Acl": { + "id": "Acl", + "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet1/Acl", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "RouteTable": { + "id": "RouteTable", + "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet1/RouteTable", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", + "aws:cdk:cloudformation:props": { + "tags": [ + { + "key": "Name", + "value": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet1" + } + ], + "vpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnRouteTable", + "version": "0.0.0" + } + }, + "RouteTableAssociation": { + "id": "RouteTableAssociation", + "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet1/RouteTableAssociation", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "VpcPrivateSubnet1RouteTableB2C5B500" + }, + "subnetId": { + "Ref": "VpcPrivateSubnet1Subnet536B997A" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnetRouteTableAssociation", + "version": "0.0.0" + } + }, + "DefaultRoute": { + "id": "DefaultRoute", + "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet1/DefaultRoute", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Route", + "aws:cdk:cloudformation:props": { + "destinationCidrBlock": "0.0.0.0/0", + "natGatewayId": { + "Ref": "VpcPublicSubnet1NATGateway4D7517AA" + }, + "routeTableId": { + "Ref": "VpcPrivateSubnet1RouteTableB2C5B500" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnRoute", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.PrivateSubnet", + "version": "0.0.0" + } + }, + "PrivateSubnet2": { + "id": "PrivateSubnet2", + "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet2", + "children": { + "Subnet": { + "id": "Subnet", + "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet2/Subnet", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", + "aws:cdk:cloudformation:props": { + "availabilityZone": "test-region-1b", + "cidrBlock": "10.0.128.0/19", + "mapPublicIpOnLaunch": false, + "tags": [ + { + "key": "aws-cdk:subnet-name", + "value": "Private" + }, + { + "key": "aws-cdk:subnet-type", + "value": "Private" + }, + { + "key": "Name", + "value": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet2" + } + ], + "vpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnet", + "version": "0.0.0" + } + }, + "Acl": { + "id": "Acl", + "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet2/Acl", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "RouteTable": { + "id": "RouteTable", + "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet2/RouteTable", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", + "aws:cdk:cloudformation:props": { + "tags": [ + { + "key": "Name", + "value": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet2" + } + ], + "vpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnRouteTable", + "version": "0.0.0" + } + }, + "RouteTableAssociation": { + "id": "RouteTableAssociation", + "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet2/RouteTableAssociation", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "VpcPrivateSubnet2RouteTableA678073B" + }, + "subnetId": { + "Ref": "VpcPrivateSubnet2Subnet3788AAA1" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnetRouteTableAssociation", + "version": "0.0.0" + } + }, + "DefaultRoute": { + "id": "DefaultRoute", + "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet2/DefaultRoute", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Route", + "aws:cdk:cloudformation:props": { + "destinationCidrBlock": "0.0.0.0/0", + "natGatewayId": { + "Ref": "VpcPublicSubnet2NATGateway9182C01D" + }, + "routeTableId": { + "Ref": "VpcPrivateSubnet2RouteTableA678073B" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnRoute", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.PrivateSubnet", + "version": "0.0.0" + } + }, + "PrivateSubnet3": { + "id": "PrivateSubnet3", + "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet3", + "children": { + "Subnet": { + "id": "Subnet", + "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet3/Subnet", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", + "aws:cdk:cloudformation:props": { + "availabilityZone": "test-region-1c", + "cidrBlock": "10.0.160.0/19", + "mapPublicIpOnLaunch": false, + "tags": [ + { + "key": "aws-cdk:subnet-name", + "value": "Private" + }, + { + "key": "aws-cdk:subnet-type", + "value": "Private" + }, + { + "key": "Name", + "value": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet3" + } + ], + "vpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnet", + "version": "0.0.0" + } + }, + "Acl": { + "id": "Acl", + "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet3/Acl", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "RouteTable": { + "id": "RouteTable", + "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet3/RouteTable", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", + "aws:cdk:cloudformation:props": { + "tags": [ + { + "key": "Name", + "value": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet3" + } + ], + "vpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnRouteTable", + "version": "0.0.0" + } + }, + "RouteTableAssociation": { + "id": "RouteTableAssociation", + "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet3/RouteTableAssociation", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "VpcPrivateSubnet3RouteTableD98824C7" + }, + "subnetId": { + "Ref": "VpcPrivateSubnet3SubnetF258B56E" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSubnetRouteTableAssociation", + "version": "0.0.0" + } + }, + "DefaultRoute": { + "id": "DefaultRoute", + "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet3/DefaultRoute", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Route", + "aws:cdk:cloudformation:props": { + "destinationCidrBlock": "0.0.0.0/0", + "natGatewayId": { + "Ref": "VpcPublicSubnet3NATGateway7640CD1D" + }, + "routeTableId": { + "Ref": "VpcPrivateSubnet3RouteTableD98824C7" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnRoute", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.PrivateSubnet", + "version": "0.0.0" + } + }, + "IGW": { + "id": "IGW", + "path": "integ-ec2-machine-image-cached-test/Vpc/IGW", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::InternetGateway", + "aws:cdk:cloudformation:props": { + "tags": [ + { + "key": "Name", + "value": "integ-ec2-machine-image-cached-test/Vpc" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnInternetGateway", + "version": "0.0.0" + } + }, + "VPCGW": { + "id": "VPCGW", + "path": "integ-ec2-machine-image-cached-test/Vpc/VPCGW", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::VPCGatewayAttachment", + "aws:cdk:cloudformation:props": { + "internetGatewayId": { + "Ref": "VpcIGWD7BA715C" + }, + "vpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnVPCGatewayAttachment", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.Vpc", + "version": "0.0.0" + } + }, + "al2023Cached": { + "id": "al2023Cached", + "path": "integ-ec2-machine-image-cached-test/al2023Cached", + "children": { + "InstanceSecurityGroup": { + "id": "InstanceSecurityGroup", + "path": "integ-ec2-machine-image-cached-test/al2023Cached/InstanceSecurityGroup", + "children": { + "Resource": { + "id": "Resource", + "path": "integ-ec2-machine-image-cached-test/al2023Cached/InstanceSecurityGroup/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SecurityGroup", + "aws:cdk:cloudformation:props": { + "groupDescription": "integ-ec2-machine-image-cached-test/al2023Cached/InstanceSecurityGroup", + "securityGroupEgress": [ + { + "cidrIp": "0.0.0.0/0", + "description": "Allow all outbound traffic by default", + "ipProtocol": "-1" + } + ], + "tags": [ + { + "key": "Name", + "value": "integ-ec2-machine-image-cached-test/al2023Cached" + } + ], + "vpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSecurityGroup", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.SecurityGroup", + "version": "0.0.0" + } + }, + "InstanceRole": { + "id": "InstanceRole", + "path": "integ-ec2-machine-image-cached-test/al2023Cached/InstanceRole", + "children": { + "ImportInstanceRole": { + "id": "ImportInstanceRole", + "path": "integ-ec2-machine-image-cached-test/al2023Cached/InstanceRole/ImportInstanceRole", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "integ-ec2-machine-image-cached-test/al2023Cached/InstanceRole/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "assumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "ec2.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "tags": [ + { + "key": "Name", + "value": "integ-ec2-machine-image-cached-test/al2023Cached" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.CfnRole", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.Role", + "version": "0.0.0" + } + }, + "InstanceProfile": { + "id": "InstanceProfile", + "path": "integ-ec2-machine-image-cached-test/al2023Cached/InstanceProfile", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::InstanceProfile", + "aws:cdk:cloudformation:props": { + "roles": [ + { + "Ref": "al2023CachedInstanceRoleD76E1DF5" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.CfnInstanceProfile", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "integ-ec2-machine-image-cached-test/al2023Cached/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Instance", + "aws:cdk:cloudformation:props": { + "availabilityZone": "test-region-1a", + "iamInstanceProfile": { + "Ref": "al2023CachedInstanceProfileD264357E" + }, + "imageId": "dummy-value-for-integ-ec2-machine-image-cached-test/al2023Cached-/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64", + "instanceType": "t2.nano", + "securityGroupIds": [ + { + "Fn::GetAtt": [ + "al2023CachedInstanceSecurityGroup2719C9BA", + "GroupId" + ] + } + ], + "subnetId": { + "Ref": "VpcPrivateSubnet1Subnet536B997A" + }, + "tags": [ + { + "key": "Name", + "value": "integ-ec2-machine-image-cached-test/al2023Cached" + } + ], + "userData": { + "Fn::Base64": "#!/bin/bash" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnInstance", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.Instance", + "version": "0.0.0" + } + }, + "al2023CachedScope": { + "id": "al2023CachedScope", + "path": "integ-ec2-machine-image-cached-test/al2023CachedScope", + "children": { + "InstanceSecurityGroup": { + "id": "InstanceSecurityGroup", + "path": "integ-ec2-machine-image-cached-test/al2023CachedScope/InstanceSecurityGroup", + "children": { + "Resource": { + "id": "Resource", + "path": "integ-ec2-machine-image-cached-test/al2023CachedScope/InstanceSecurityGroup/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SecurityGroup", + "aws:cdk:cloudformation:props": { + "groupDescription": "integ-ec2-machine-image-cached-test/al2023CachedScope/InstanceSecurityGroup", + "securityGroupEgress": [ + { + "cidrIp": "0.0.0.0/0", + "description": "Allow all outbound traffic by default", + "ipProtocol": "-1" + } + ], + "tags": [ + { + "key": "Name", + "value": "integ-ec2-machine-image-cached-test/al2023CachedScope" + } + ], + "vpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSecurityGroup", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.SecurityGroup", + "version": "0.0.0" + } + }, + "InstanceRole": { + "id": "InstanceRole", + "path": "integ-ec2-machine-image-cached-test/al2023CachedScope/InstanceRole", + "children": { + "ImportInstanceRole": { + "id": "ImportInstanceRole", + "path": "integ-ec2-machine-image-cached-test/al2023CachedScope/InstanceRole/ImportInstanceRole", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "integ-ec2-machine-image-cached-test/al2023CachedScope/InstanceRole/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "assumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "ec2.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "tags": [ + { + "key": "Name", + "value": "integ-ec2-machine-image-cached-test/al2023CachedScope" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.CfnRole", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.Role", + "version": "0.0.0" + } + }, + "InstanceProfile": { + "id": "InstanceProfile", + "path": "integ-ec2-machine-image-cached-test/al2023CachedScope/InstanceProfile", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::InstanceProfile", + "aws:cdk:cloudformation:props": { + "roles": [ + { + "Ref": "al2023CachedScopeInstanceRoleB7C63F12" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.CfnInstanceProfile", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "integ-ec2-machine-image-cached-test/al2023CachedScope/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Instance", + "aws:cdk:cloudformation:props": { + "availabilityZone": "test-region-1a", + "iamInstanceProfile": { + "Ref": "al2023CachedScopeInstanceProfileD8064966" + }, + "imageId": "dummy-value-for-integ-ec2-machine-image-cached-test/al2023CachedScope-/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64", + "instanceType": "t2.nano", + "securityGroupIds": [ + { + "Fn::GetAtt": [ + "al2023CachedScopeInstanceSecurityGroupADC3C195", + "GroupId" + ] + } + ], + "subnetId": { + "Ref": "VpcPrivateSubnet1Subnet536B997A" + }, + "tags": [ + { + "key": "Name", + "value": "integ-ec2-machine-image-cached-test/al2023CachedScope" + } + ], + "userData": { + "Fn::Base64": "#!/bin/bash" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnInstance", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.Instance", + "version": "0.0.0" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "integ-ec2-machine-image-cached-test/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "integ-ec2-machine-image-cached-test/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + }, + "integ-test": { + "id": "integ-test", + "path": "integ-test", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "integ-test/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "integ-test/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.70" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "integ-test/DefaultTest/DeployAssert", + "children": { + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "integ-test/DefaultTest/DeployAssert/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "integ-test/DefaultTest/DeployAssert/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTestCase", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTest", + "version": "0.0.0" + } + }, + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.70" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.App", + "version": "0.0.0" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.ts new file mode 100644 index 0000000000000..6a3845cb2c1c7 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.ts @@ -0,0 +1,53 @@ +import { IntegTest } from '@aws-cdk/integ-tests-alpha'; +import { + Stack, + StackProps, + App, + aws_ec2 as ec2, + // aws_autoscaling as asg, + // aws_ssm as ssm, +} from 'aws-cdk-lib'; +import { Construct } from 'constructs'; +import { EC2_RESTRICT_DEFAULT_SECURITY_GROUP } from 'aws-cdk-lib/cx-api'; + +// we associate this stack with an explicit environment since this is required by the +// environmental context provider used with `cachedInContext`. CDK_INTEG_XXX are set +// when producing the .expected file and CDK_DEFAULT_XXX is passed in through from +// the CLI in actual deployment. +const env = { + account: process.env.CDK_INTEG_ACCOUNT || process.env.CDK_DEFAULT_ACCOUNT, + region: process.env.CDK_INTEG_REGION || process.env.CDK_DEFAULT_REGION, +}; + +export class TestCase extends Stack { + constructor(scope: Construct, id: string, props?: StackProps) { + super(scope, id, props); + this.node.setContext(EC2_RESTRICT_DEFAULT_SECURITY_GROUP, false); + const vpc = new ec2.Vpc(this, 'Vpc'); + + const instanceType = ec2.InstanceType.of(ec2.InstanceClass.T2, ec2.InstanceSize.NANO); + + new ec2.Instance(this, 'al2023Cached', { + instanceType, + machineImage: ec2.MachineImage.latestAmazonLinux2023({ + cachedInContext: true, + }), + vpc, + }); + + new ec2.Instance(this, 'al2023CachedScope', { + instanceType, + machineImage: ec2.MachineImage.latestAmazonLinux2023({ + cachedInContext: true, + linkContextToScope: true, + }), + vpc, + }); + } +} + +const app = new App(); +new IntegTest(app, 'integ-test', { + testCases: [new TestCase(app, 'integ-ec2-machine-image-cached-test', { env })], + enableLookups: true, +}); From ea2d380ef096d3241b36e5652e470a2264ce7ce4 Mon Sep 17 00:00:00 2001 From: Jonathan Romano Date: Sat, 2 Sep 2023 01:52:43 -0400 Subject: [PATCH 05/22] Fix default in AmazonLinuxImageSsmParameterBase --- packages/aws-cdk-lib/aws-ec2/lib/machine-image/common.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/common.ts b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/common.ts index 55e3c7cc051af..47ec933dd1c00 100644 --- a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/common.ts +++ b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/common.ts @@ -76,7 +76,7 @@ export abstract class AmazonLinuxImageSsmParameterBase implements IMachineImage private readonly linkContextToScope: boolean; constructor(private readonly props: AmazonLinuxImageSsmParameterBaseProps) { this.cachedInContext = this.props.cachedInContext ?? true; - this.linkContextToScope = this.props.linkContextToScope ?? true; + this.linkContextToScope = this.props.linkContextToScope ?? false; } getImage(scope: Construct): MachineImageConfig { From edbccad93b47218fd0ae0de269b487d371c2bc7a Mon Sep 17 00:00:00 2001 From: Jonathan Romano Date: Sat, 2 Sep 2023 02:31:40 -0400 Subject: [PATCH 06/22] Update snapshot --- .../integ-ec2-machine-image-cached-test.assets.json | 4 ++-- .../integ-ec2-machine-image-cached-test.template.json | 2 +- .../integ.machine-image-cached.js.snapshot/manifest.json | 5 ++--- .../test/integ.machine-image-cached.js.snapshot/tree.json | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ-ec2-machine-image-cached-test.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ-ec2-machine-image-cached-test.assets.json index 72a63a5679816..230c74860af55 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ-ec2-machine-image-cached-test.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ-ec2-machine-image-cached-test.assets.json @@ -1,7 +1,7 @@ { "version": "34.0.0", "files": { - "6110c57085f3942fd06f447c35d36d8649b434ca69763c6e7c0adce298dfeef1": { + "b377d63fffd8297ea8ff3722d1b313faadf0a8fab1a05b53dacd9a8b1550ea75": { "source": { "path": "integ-ec2-machine-image-cached-test.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "12345678-test-region": { "bucketName": "cdk-hnb659fds-assets-12345678-test-region", - "objectKey": "6110c57085f3942fd06f447c35d36d8649b434ca69763c6e7c0adce298dfeef1.json", + "objectKey": "b377d63fffd8297ea8ff3722d1b313faadf0a8fab1a05b53dacd9a8b1550ea75.json", "region": "test-region", "assumeRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-file-publishing-role-12345678-test-region" } diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ-ec2-machine-image-cached-test.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ-ec2-machine-image-cached-test.template.json index 08bb9c6db64d4..39078f199f717 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ-ec2-machine-image-cached-test.template.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ-ec2-machine-image-cached-test.template.json @@ -588,7 +588,7 @@ "IamInstanceProfile": { "Ref": "al2023CachedInstanceProfileD264357E" }, - "ImageId": "dummy-value-for-integ-ec2-machine-image-cached-test/al2023Cached-/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64", + "ImageId": "dummy-value-for-/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64", "InstanceType": "t2.nano", "SecurityGroupIds": [ { diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/manifest.json index 1b167678e5497..843587a0c986a 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/manifest.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/manifest.json @@ -17,7 +17,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-deploy-role-12345678-test-region", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-cfn-exec-role-12345678-test-region", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-12345678-test-region/6110c57085f3942fd06f447c35d36d8649b434ca69763c6e7c0adce298dfeef1.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-12345678-test-region/b377d63fffd8297ea8ff3722d1b313faadf0a8fab1a05b53dacd9a8b1550ea75.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -350,12 +350,11 @@ }, "missing": [ { - "key": "ssm:account=12345678:parameterName=/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64:region=test-region:scope=integ-ec2-machine-image-cached-test/al2023Cached", + "key": "ssm:account=12345678:parameterName=/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64:region=test-region", "provider": "ssm", "props": { "account": "12345678", "region": "test-region", - "scope": "integ-ec2-machine-image-cached-test/al2023Cached", "parameterName": "/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64", "lookupRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-lookup-role-12345678-test-region" } diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/tree.json index c56bff81ff346..32cea7f2d2cb5 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/tree.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/tree.json @@ -1016,7 +1016,7 @@ "iamInstanceProfile": { "Ref": "al2023CachedInstanceProfileD264357E" }, - "imageId": "dummy-value-for-integ-ec2-machine-image-cached-test/al2023Cached-/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64", + "imageId": "dummy-value-for-/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64", "instanceType": "t2.nano", "securityGroupIds": [ { From 285fa901d0a0d8a27ceeb4169498ae4666e2f507 Mon Sep 17 00:00:00 2001 From: Jonathan Romano Date: Tue, 19 Sep 2023 19:08:21 +0000 Subject: [PATCH 07/22] Use explicit cache key instead of opting in to scope key --- ...-ec2-machine-image-cached-test.assets.json | 4 +- ...c2-machine-image-cached-test.template.json | 2 +- .../manifest.json | 6 +-- .../tree.json | 2 +- .../test/integ.machine-image-cached.ts | 2 +- packages/aws-cdk-lib/aws-ec2/README.md | 21 ++++----- .../lib/machine-image/amazon-linux-2022.ts | 2 +- .../lib/machine-image/amazon-linux-2023.ts | 2 +- .../lib/machine-image/amazon-linux2.ts | 2 +- .../aws-ec2/lib/machine-image/common.ts | 13 +++--- .../lib/machine-image/machine-image.ts | 34 +++++++------- .../aws-ec2/lib/machine-image/utils.ts | 4 +- .../aws-cdk-lib/aws-ec2/lib/security-group.ts | 30 ++++++------- .../aws-cdk-lib/aws-ec2/lib/vpc-lookup.ts | 6 +++ packages/aws-cdk-lib/aws-ec2/lib/vpc.ts | 6 +-- .../aws-ec2/test/machine-image.test.ts | 4 +- packages/aws-cdk-lib/aws-ecs/README.md | 9 ++-- packages/aws-cdk-lib/aws-ecs/lib/amis.ts | 45 +++++++++---------- .../aws-elasticloadbalancingv2/README.md | 8 ++-- .../lib/alb/application-listener.ts | 5 +-- .../lib/alb/application-load-balancer.ts | 5 +-- .../lib/nlb/network-listener.ts | 6 +-- .../lib/nlb/network-load-balancer.ts | 5 +-- .../lib/shared/base-listener.ts | 10 ++++- .../lib/shared/base-load-balancer.ts | 9 +++- packages/aws-cdk-lib/aws-kms/README.md | 8 ++-- .../aws-cdk-lib/aws-kms/lib/key-lookup.ts | 6 +++ packages/aws-cdk-lib/aws-kms/lib/key.ts | 6 +-- packages/aws-cdk-lib/aws-route53/README.md | 8 ++-- .../aws-route53/lib/hosted-zone-provider.ts | 6 +++ .../aws-route53/lib/hosted-zone.ts | 5 +-- packages/aws-cdk-lib/aws-ssm/README.md | 8 ++-- packages/aws-cdk-lib/aws-ssm/lib/parameter.ts | 8 ++-- .../aws-cdk-lib/core/lib/context-provider.ts | 8 ---- .../aws-cdk-lib/core/test/context.test.ts | 28 ------------ 35 files changed, 149 insertions(+), 184 deletions(-) diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ-ec2-machine-image-cached-test.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ-ec2-machine-image-cached-test.assets.json index 230c74860af55..b959f8b0a1419 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ-ec2-machine-image-cached-test.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ-ec2-machine-image-cached-test.assets.json @@ -1,7 +1,7 @@ { "version": "34.0.0", "files": { - "b377d63fffd8297ea8ff3722d1b313faadf0a8fab1a05b53dacd9a8b1550ea75": { + "28b0c40087d5092de80f9eb21ff6e74380b5503e7fe85d136141b47f90ba55dc": { "source": { "path": "integ-ec2-machine-image-cached-test.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "12345678-test-region": { "bucketName": "cdk-hnb659fds-assets-12345678-test-region", - "objectKey": "b377d63fffd8297ea8ff3722d1b313faadf0a8fab1a05b53dacd9a8b1550ea75.json", + "objectKey": "28b0c40087d5092de80f9eb21ff6e74380b5503e7fe85d136141b47f90ba55dc.json", "region": "test-region", "assumeRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-file-publishing-role-12345678-test-region" } diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ-ec2-machine-image-cached-test.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ-ec2-machine-image-cached-test.template.json index 39078f199f717..35364454908e7 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ-ec2-machine-image-cached-test.template.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ-ec2-machine-image-cached-test.template.json @@ -677,7 +677,7 @@ "IamInstanceProfile": { "Ref": "al2023CachedScopeInstanceProfileD8064966" }, - "ImageId": "dummy-value-for-integ-ec2-machine-image-cached-test/al2023CachedScope-/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64", + "ImageId": "dummy-value-for-/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64", "InstanceType": "t2.nano", "SecurityGroupIds": [ { diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/manifest.json index 843587a0c986a..f5297cc4d5f4b 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/manifest.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/manifest.json @@ -17,7 +17,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-deploy-role-12345678-test-region", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-cfn-exec-role-12345678-test-region", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-12345678-test-region/b377d63fffd8297ea8ff3722d1b313faadf0a8fab1a05b53dacd9a8b1550ea75.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-12345678-test-region/28b0c40087d5092de80f9eb21ff6e74380b5503e7fe85d136141b47f90ba55dc.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -360,13 +360,13 @@ } }, { - "key": "ssm:account=12345678:parameterName=/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64:region=test-region:scope=integ-ec2-machine-image-cached-test/al2023CachedScope", + "key": "ssm:account=12345678:additionalCacheKey=extraKey:parameterName=/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64:region=test-region", "provider": "ssm", "props": { "account": "12345678", "region": "test-region", - "scope": "integ-ec2-machine-image-cached-test/al2023CachedScope", "parameterName": "/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64", + "additionalCacheKey": "extraKey", "lookupRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-lookup-role-12345678-test-region" } } diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/tree.json index 32cea7f2d2cb5..79577a7c5b691 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/tree.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/tree.json @@ -1172,7 +1172,7 @@ "iamInstanceProfile": { "Ref": "al2023CachedScopeInstanceProfileD8064966" }, - "imageId": "dummy-value-for-integ-ec2-machine-image-cached-test/al2023CachedScope-/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64", + "imageId": "dummy-value-for-/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64", "instanceType": "t2.nano", "securityGroupIds": [ { diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.ts index 6a3845cb2c1c7..428399864948e 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.ts @@ -39,7 +39,7 @@ export class TestCase extends Stack { instanceType, machineImage: ec2.MachineImage.latestAmazonLinux2023({ cachedInContext: true, - linkContextToScope: true, + additionalCacheKey: 'extraKey', }), vpc, }); diff --git a/packages/aws-cdk-lib/aws-ec2/README.md b/packages/aws-cdk-lib/aws-ec2/README.md index 676916a648fb6..950a9b091625a 100644 --- a/packages/aws-cdk-lib/aws-ec2/README.md +++ b/packages/aws-cdk-lib/aws-ec2/README.md @@ -504,10 +504,10 @@ The result of the `Vpc.fromLookup()` operation will be written to a file called `cdk.context.json`. You must commit this file to source control so that the lookup values are available in non-privileged environments such as CI build steps, and to ensure your template builds are repeatable. -If you want the key of the context variable to be tied to the scope -passed to `fromLookup` instead of being global (usinwhich would use the same -value any time you call `fromLookup` across your entire app), -you can set the `linkContextToScope` argument to `true` +If you do not want the value of the context variable to be global (ie, having the same +value returned any time you call `fromLookup` across your entire app), +you can set the `additionalCacheKey` argument (eg, to `this.node.path` to tie it +to the scope of the current construct) Here's how `Vpc.fromLookup()` can be used: @@ -748,7 +748,7 @@ If the security group ID is known and configuration details are unknown, use met const sg = ec2.SecurityGroup.fromLookupById(this, 'SecurityGroupLookup', 'sg-1234'); ``` -The result of `SecurityGroup.fromLookupByName` and `SecurityGroup.fromLookupById` operations will be written to a file called `cdk.context.json`. You must commit this file to source control so that the lookup values are available in non-privileged environments such as CI build steps, and to ensure your template builds are repeatable. If you want the key of the context variable to be tied to the scope passed to `fromLookupByName`/`fromLookupById` instead of being global (which would use the same value any time you call `fromLookup` across your entire app), you can set the `linkContextToScope` argument to `true` +The result of `SecurityGroup.fromLookupByName` and `SecurityGroup.fromLookupById` operations will be written to a file called `cdk.context.json`. You must commit this file to source control so that the lookup values are available in non-privileged environments such as CI build steps, and to ensure your template builds are repeatable. If you do not want the value of the context variable to be global (ie, having the same value returned any time you call `fromLookup` across your entire app), you can set the `additionalCacheKey` argument (eg, to `this.node.path` to tie it to the scope of the current construct) ### Cross Stack Connections @@ -836,9 +836,10 @@ examples of images you might want to use: > [Runtime Context](https://docs.aws.amazon.com/cdk/latest/guide/context.html) in the CDK > developer guide. > -> If you want the key of the context variable to be tied to the scope -> passed to `lookup` instead of being global (which would use the same value any -> time you call `lookup` across your entire app), you can set the `linkContextToScope` argument to `true` +> If you do not want the value of the context variable to be to be global +> (ie, having the same value returned any time you call `lookup` across your entire app), +> you can set the `additionalCacheKey` argument (eg, to `this.node.path` to tie it +> to the scope of the current construct) > > `MachineImage.genericLinux()`, `MachineImage.genericWindows()` will use `CfnMapping` in > an agnostic stack. @@ -1168,7 +1169,7 @@ new ec2.Instance(this, 'LatestAl2023', { cachedInContext: true, // creates a distinct context variable for this image, instead of resolving to the same // value anywhere this lookup is done in your app - linkContextToScope: true, + additionalCacheKey: this.node.path, }), }); @@ -1180,7 +1181,7 @@ new ec2.Instance(this, 'LatestAl2023', { machineImage: new ec2.AmazonLinux2023ImageSsmParameter({ // creates a distinct context variable for this image, instead of resolving to the same // value anywhere this lookup is done in your app - linkContextToScope: true, + additionalCacheKey: this.node.path, }), }); diff --git a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/amazon-linux-2022.ts b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/amazon-linux-2022.ts index 123dc925f6c7a..fb55c06cb0ed1 100644 --- a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/amazon-linux-2022.ts +++ b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/amazon-linux-2022.ts @@ -84,7 +84,7 @@ export class AmazonLinux2022ImageSsmParameter extends AmazonLinuxImageSsmParamet super({ parameterName: AmazonLinux2022ImageSsmParameter.ssmParameterName(props), cachedInContext: props.cachedInContext, - linkContextToScope: props.linkContextToScope, + additionalCacheKey: props.additionalCacheKey, userData: props.userData, }); } diff --git a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/amazon-linux-2023.ts b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/amazon-linux-2023.ts index 62da6e959509a..0d0ed064f971c 100644 --- a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/amazon-linux-2023.ts +++ b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/amazon-linux-2023.ts @@ -83,7 +83,7 @@ export class AmazonLinux2023ImageSsmParameter extends AmazonLinuxImageSsmParamet super({ parameterName: AmazonLinux2023ImageSsmParameter.ssmParameterName(props), cachedInContext: props.cachedInContext, - linkContextToScope: props.linkContextToScope, + additionalCacheKey: props.additionalCacheKey, userData: props.userData, }); } diff --git a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/amazon-linux2.ts b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/amazon-linux2.ts index 310d425e10ec6..b1bf191157c50 100644 --- a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/amazon-linux2.ts +++ b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/amazon-linux2.ts @@ -103,7 +103,7 @@ export class AmazonLinux2ImageSsmParameter extends AmazonLinuxImageSsmParameterB super({ parameterName: AmazonLinux2ImageSsmParameter.ssmParameterName(props), cachedInContext: props.cachedInContext, - linkContextToScope: props.linkContextToScope, + additionalCacheKey: props.additionalCacheKey, userData: props.userData, }); } diff --git a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/common.ts b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/common.ts index 47ec933dd1c00..c236000e95141 100644 --- a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/common.ts +++ b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/common.ts @@ -47,11 +47,10 @@ export interface AmazonLinuxImageSsmParameterBaseOptions { readonly cachedInContext?: boolean; /** - * If true and cachedInContext is true, the context key will be tied to the passed scope rather than global - * - * @default false + * When the image is cached in cdk.context.json, adds an additional discriminator to the + * cache key so that separate lookups with the same parameters can have separate cache lifecycles */ - readonly linkContextToScope?: boolean + readonly additionalCacheKey?: string; /** * Initial user data @@ -73,14 +72,14 @@ export interface AmazonLinuxImageSsmParameterBaseProps extends AmazonLinuxImageS export abstract class AmazonLinuxImageSsmParameterBase implements IMachineImage { private readonly cachedInContext: boolean; - private readonly linkContextToScope: boolean; + private readonly additionalCacheKey?: string; constructor(private readonly props: AmazonLinuxImageSsmParameterBaseProps) { this.cachedInContext = this.props.cachedInContext ?? true; - this.linkContextToScope = this.props.linkContextToScope ?? false; + if (props.additionalCacheKey) this.additionalCacheKey = this.props.additionalCacheKey; } getImage(scope: Construct): MachineImageConfig { - const imageId = lookupImage(scope, this.cachedInContext && this.linkContextToScope ? 'scope' : this.cachedInContext, this.props.parameterName); + const imageId = lookupImage(scope, this.cachedInContext, this.props.parameterName, this.additionalCacheKey); const osType = OperatingSystemType.LINUX; return { diff --git a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/machine-image.ts b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/machine-image.ts index 57164c64b9a1d..fe8729b955c26 100644 --- a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/machine-image.ts +++ b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/machine-image.ts @@ -303,11 +303,10 @@ export interface SsmParameterImageOptions { readonly cachedInContext?: boolean; /** - * If true and cachedInContext is true, the context key will be tied to the passed scope rather than global - * - * @default false + * When the image is cached in cdk.context.json, adds an additional discriminator to the + * cache key so that separate lookups with the same parameters can have separate cache lifecycles */ - readonly linkContextToScope?: boolean + readonly additionalCacheKey?: string; /** * The version of the SSM parameter. @@ -335,7 +334,7 @@ class GenericSsmParameterImage implements IMachineImage { * Return the image to use in the given context */ public getImage(scope: Construct): MachineImageConfig { - const imageId = lookupImage(scope, this.props.cachedInContext && this.props.linkContextToScope ? 'scope' : this.props.cachedInContext, this.parameterName); + const imageId = lookupImage(scope, this.props.cachedInContext ?? false, this.parameterName, this.props.additionalCacheKey); const osType = this.props.os ?? OperatingSystemType.LINUX; return { @@ -468,11 +467,10 @@ export interface AmazonLinuxImageProps { readonly cachedInContext?: boolean; /** - * If true and cachedInContext is true, the context key will be tied to the passed scope rather than global - * - * @default false + * When the image is cached in cdk.context.json, adds an additional discriminator to the + * cache key so that separate lookups with the same parameters can have separate cache lifecycles */ - readonly linkContextToScope?: boolean + readonly additionalCacheKey?: string; } /** @@ -525,20 +523,20 @@ export class AmazonLinuxImage extends GenericSSMParameterImage { private readonly cachedInContext: boolean; - private readonly linkContextToScope: boolean; + private readonly additionalCacheKey?: string; constructor(private readonly props: AmazonLinuxImageProps = {}) { super(AmazonLinuxImage.ssmParameterName(props), OperatingSystemType.LINUX, props.userData); this.cachedInContext = props.cachedInContext ?? false; - this.linkContextToScope = props.linkContextToScope ?? false; + if (props.additionalCacheKey) this.additionalCacheKey = props.additionalCacheKey; } /** * Return the image to use in the given context */ public getImage(scope: Construct): MachineImageConfig { - const imageId = lookupImage(scope, this.cachedInContext && this.linkContextToScope ? 'scope' : this.cachedInContext, this.parameterName); + const imageId = lookupImage(scope, this.cachedInContext, this.parameterName, this.additionalCacheKey); const osType = OperatingSystemType.LINUX; return { @@ -669,7 +667,8 @@ export class GenericWindowsImage implements IMachineImage { * will be used on future runs. To refresh the AMI lookup, you will have to * evict the value from the cache using the `cdk context` command. See * https://docs.aws.amazon.com/cdk/latest/guide/context.html for more information. - * If `props.linkContextToScope` is true, the context key will be tied to the passed scope rather than global + * If `props.additionalCacheKey` is true, the context key use that value as a discriminator + * rather than the cached value being global across all lookups */ export class LookupMachineImage implements IMachineImage { constructor(private readonly props: LookupMachineImageProps) { @@ -694,9 +693,9 @@ export class LookupMachineImage implements IMachineImage { props: { owners: this.props.owners, filters, + ...(this.props.additionalCacheKey ? { additionalCacheKey: this.props.additionalCacheKey } : {}), } as cxschema.AmiContextQuery, dummyValue: 'ami-1234', - includeScope: this.props.linkContextToScope, }).value as cxapi.AmiContextResponse; if (typeof value !== 'string') { @@ -752,10 +751,9 @@ export interface LookupMachineImageProps { readonly userData?: UserData; /** - * If true, the context key will be tied to the passed scope rather than global - * - * @default false + * When the image is cached in cdk.context.json, adds an additional discriminator to the + * cache key so that separate lookups with the same parameters can have separate cache lifecycles */ - readonly linkContextToScope?: boolean + readonly additionalCacheKey?: string; } diff --git a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/utils.ts b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/utils.ts index 0423c4550de05..9b782b2dedfd5 100644 --- a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/utils.ts +++ b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/utils.ts @@ -1,9 +1,9 @@ import { Construct } from 'constructs'; import * as ssm from '../../../aws-ssm'; -export function lookupImage(scope: Construct, cachedInContext: boolean | undefined | 'scope', parameterName: string) { +export function lookupImage(scope: Construct, cachedInContext: boolean, parameterName: string, additionalCacheKey?: string) { return cachedInContext - ? ssm.StringParameter.valueFromLookup(scope, parameterName, cachedInContext === 'scope') + ? ssm.StringParameter.valueFromLookup(scope, parameterName, additionalCacheKey) : ssm.StringParameter.valueForTypedStringParameterV2(scope, parameterName, ssm.ParameterValueType.AWS_EC2_IMAGE_ID); } diff --git a/packages/aws-cdk-lib/aws-ec2/lib/security-group.ts b/packages/aws-cdk-lib/aws-ec2/lib/security-group.ts index bb8141ccbd761..4bebd70f45b38 100644 --- a/packages/aws-cdk-lib/aws-ec2/lib/security-group.ts +++ b/packages/aws-cdk-lib/aws-ec2/lib/security-group.ts @@ -367,30 +367,24 @@ export class SecurityGroup extends SecurityGroupBase { /** * Look up a security group by id. * - * If linkContextToScope is true, the context key will be tied to the passed scope rather than global - * * @deprecated Use `fromLookupById()` instead */ - public static fromLookup(scope: Construct, id: string, securityGroupId: string, linkContextToScope?: boolean) { - return this.fromLookupAttributes(scope, id, { securityGroupId }, linkContextToScope); + public static fromLookup(scope: Construct, id: string, securityGroupId: string, additionalCacheKey?: string) { + return this.fromLookupAttributes(scope, id, { securityGroupId, additionalCacheKey }); } /** * Look up a security group by id. - * - * If linkContextToScope is true, the context key will be tied to the passed scope rather than global */ - public static fromLookupById(scope: Construct, id: string, securityGroupId: string, linkContextToScope?: boolean) { - return this.fromLookupAttributes(scope, id, { securityGroupId }, linkContextToScope); + public static fromLookupById(scope: Construct, id: string, securityGroupId: string, additionalCacheKey?: string) { + return this.fromLookupAttributes(scope, id, { securityGroupId, additionalCacheKey }); } /** * Look up a security group by name. - * - * If linkContextToScope is true, the context key will be tied to the passed scope rather than global */ - public static fromLookupByName(scope: Construct, id: string, securityGroupName: string, vpc: IVpc, linkContextToScope?: boolean) { - return this.fromLookupAttributes(scope, id, { securityGroupName, vpc }, linkContextToScope); + public static fromLookupByName(scope: Construct, id: string, securityGroupName: string, vpc: IVpc, additionalCacheKey?: string) { + return this.fromLookupAttributes(scope, id, { securityGroupName, vpc, additionalCacheKey }); } /** @@ -438,10 +432,8 @@ export class SecurityGroup extends SecurityGroupBase { /** * Look up a security group. - * - * If linkContextToScope is true, the context key will be tied to the passed scope rather than global */ - private static fromLookupAttributes(scope: Construct, id: string, options: SecurityGroupLookupOptions, linkContextToScope?: boolean) { + private static fromLookupAttributes(scope: Construct, id: string, options: SecurityGroupLookupOptions) { if (Token.isUnresolved(options.securityGroupId) || Token.isUnresolved(options.securityGroupName) || Token.isUnresolved(options.vpc?.vpcId)) { throw new Error('All arguments to look up a security group must be concrete (no Tokens)'); } @@ -452,12 +444,12 @@ export class SecurityGroup extends SecurityGroupBase { securityGroupId: options.securityGroupId, securityGroupName: options.securityGroupName, vpcId: options.vpc?.vpcId, + ...(options.additionalCacheKey ? { additionalCacheKey: options.additionalCacheKey } : {}), }, dummyValue: { securityGroupId: 'sg-12345678', allowAllOutbound: true, } as cxapi.SecurityGroupContextResponse, - includeScope: linkContextToScope, }).value; return SecurityGroup.fromSecurityGroupId(scope, id, attributes.securityGroupId, { @@ -852,4 +844,10 @@ interface SecurityGroupLookupOptions { * @default Don't filter on VPC */ readonly vpc?: IVpc, + + /** + * When the security group is cached in cdk.context.json, adds an additional discriminator to the + * cache key so that separate lookups with the same parameters can have separate cache lifecycles + */ + readonly additionalCacheKey?: string; } diff --git a/packages/aws-cdk-lib/aws-ec2/lib/vpc-lookup.ts b/packages/aws-cdk-lib/aws-ec2/lib/vpc-lookup.ts index 42ee55969d97f..d84d4666ab986 100644 --- a/packages/aws-cdk-lib/aws-ec2/lib/vpc-lookup.ts +++ b/packages/aws-cdk-lib/aws-ec2/lib/vpc-lookup.ts @@ -75,4 +75,10 @@ export interface VpcLookupOptions { * @default the account id of the parent stack */ readonly ownerAccountId?: string; + + /** + * When the vpc is cached in cdk.context.json, adds an additional discriminator to the + * cache key so that separate lookups with the same parameters can have separate cache lifecycles + */ + readonly additionalCacheKey?: string; } diff --git a/packages/aws-cdk-lib/aws-ec2/lib/vpc.ts b/packages/aws-cdk-lib/aws-ec2/lib/vpc.ts index 030759bb03392..bbd33cb6d4312 100644 --- a/packages/aws-cdk-lib/aws-ec2/lib/vpc.ts +++ b/packages/aws-cdk-lib/aws-ec2/lib/vpc.ts @@ -1260,10 +1260,8 @@ export class Vpc extends VpcBase { * will be used on future runs. To refresh the lookup, you will have to * evict the value from the cache using the `cdk context` command. See * https://docs.aws.amazon.com/cdk/latest/guide/context.html for more information. - * - * If linkContextToScope is true, the context key will be tied to the passed scope rather than global */ - public static fromLookup(scope: Construct, id: string, options: VpcLookupOptions, linkContextToScope?: boolean): IVpc { + public static fromLookup(scope: Construct, id: string, options: VpcLookupOptions): IVpc { if (Token.isUnresolved(options.vpcId) || Token.isUnresolved(options.vpcName) || Object.values(options.tags || {}).some(Token.isUnresolved) @@ -1294,9 +1292,9 @@ export class Vpc extends VpcBase { returnAsymmetricSubnets: true, returnVpnGateways: options.returnVpnGateways, subnetGroupNameTag: options.subnetGroupNameTag, + ...(options.additionalCacheKey ? { additionalCacheKey: options.additionalCacheKey } : {}), } as cxschema.VpcContextQuery, dummyValue: undefined, - includeScope: linkContextToScope, }).value; return new LookedUpVpc(scope, id, attributes ?? DUMMY_VPC_PROPS, attributes === undefined); diff --git a/packages/aws-cdk-lib/aws-ec2/test/machine-image.test.ts b/packages/aws-cdk-lib/aws-ec2/test/machine-image.test.ts index 4f011557919fd..776c06aaa9c25 100644 --- a/packages/aws-cdk-lib/aws-ec2/test/machine-image.test.ts +++ b/packages/aws-cdk-lib/aws-ec2/test/machine-image.test.ts @@ -209,7 +209,7 @@ test('cached lookups of Amazon Linux', () => { test('cached lookups of Amazon Linux linked to scope', () => { // WHEN - const ami = ec2.MachineImage.latestAmazonLinux({ cachedInContext: true, linkContextToScope: true }).getImage(stack).imageId; + const ami = ec2.MachineImage.latestAmazonLinux({ cachedInContext: true, additionalCacheKey: 'extraKey' }).getImage(stack).imageId; // THEN expect(ami).toEqual('dummy-value-for-Stack-/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2'); @@ -221,7 +221,7 @@ test('cached lookups of Amazon Linux linked to scope', () => { lookupRoleArn: 'arn:${AWS::Partition}:iam::1234:role/cdk-hnb659fds-lookup-role-1234-testregion', region: 'testregion', parameterName: '/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2', - scope: 'Stack', + additionalCacheKey: 'extraKey', }, provider: 'ssm', }, diff --git a/packages/aws-cdk-lib/aws-ecs/README.md b/packages/aws-cdk-lib/aws-ecs/README.md index 36f513185861f..35dba18c27ed1 100644 --- a/packages/aws-cdk-lib/aws-ecs/README.md +++ b/packages/aws-cdk-lib/aws-ecs/README.md @@ -156,14 +156,15 @@ const autoScalingGroup = new autoscaling.AutoScalingGroup(this, 'ASG', { }); ``` -If you want to create a distinct context variable for the AutoScalingGroup instead of -using a global variable that will resolve to the same variable across your entire app, -you can pass `linkContextToScope: true`: +If you do not want the value of the context variable to be global (ie, having the same +value returned any time you call `EcsOptimizedImage.amazonLinux` across your entire app), +you can set the `additionalCacheKey` argument (eg, to `this.node.path` to tie it +to the scope of the current construct) ```ts declare const vpc: ec2.Vpc; const autoScalingGroup = new autoscaling.AutoScalingGroup(this, 'ASG', { - machineImage: ecs.EcsOptimizedImage.amazonLinux({ cachedInContext: true, linkContextToScope: true }), + machineImage: ecs.EcsOptimizedImage.amazonLinux({ cachedInContext: true, additionalCacheKey: this.node.path }), vpc, instanceType: new ec2.InstanceType('t2.micro'), }); diff --git a/packages/aws-cdk-lib/aws-ecs/lib/amis.ts b/packages/aws-cdk-lib/aws-ecs/lib/amis.ts index 23331df9f675b..5852b9440d597 100644 --- a/packages/aws-cdk-lib/aws-ecs/lib/amis.ts +++ b/packages/aws-cdk-lib/aws-ecs/lib/amis.ts @@ -94,11 +94,10 @@ export interface EcsOptimizedAmiProps { readonly cachedInContext?: boolean; /** - * If true and cachedInContext is true, the context key will be tied to the passed scope rather than global - * - * @default false + * When the image is cached in cdk.context.json, adds an additional discriminator to the + * cache key so that separate lookups with the same parameters can have separate cache lifecycles */ - readonly linkContextToScope?: boolean + readonly additionalCacheKey?: string; } /* @@ -116,7 +115,7 @@ export class EcsOptimizedAmi implements ec2.IMachineImage { private readonly amiParameterName: string; private readonly cachedInContext: boolean; - private readonly linkContextToScope: boolean; + private readonly additionalCacheKey?: string; /** * Constructs a new instance of the EcsOptimizedAmi class. @@ -153,14 +152,14 @@ export class EcsOptimizedAmi implements ec2.IMachineImage { + (this.windowsVersion ? 'image_id' : 'recommended/image_id'); this.cachedInContext = props?.cachedInContext ?? false; - this.linkContextToScope = props?.linkContextToScope ?? false; + if (props?.additionalCacheKey) this.additionalCacheKey = props.additionalCacheKey; } /** * Return the correct image */ public getImage(scope: Construct): ec2.MachineImageConfig { - const ami = lookupImage(scope, this.cachedInContext && this.linkContextToScope ? 'scope' : this.cachedInContext, this.amiParameterName); + const ami = lookupImage(scope, this.cachedInContext, this.amiParameterName, this.additionalCacheKey); const osType = this.windowsVersion ? ec2.OperatingSystemType.WINDOWS : ec2.OperatingSystemType.LINUX; return { @@ -197,11 +196,10 @@ export interface EcsOptimizedImageOptions { readonly cachedInContext?: boolean; /** - * If true and cachedInContext is true, the context key will be tied to the passed scope rather than global - * - * @default false + * When the image is cached in cdk.context.json, adds an additional discriminator to the + * cache key so that separate lookups with the same parameters can have separate cache lifecycles */ - readonly linkContextToScope?: boolean + readonly additionalCacheKey?: string; } /** @@ -249,7 +247,7 @@ export class EcsOptimizedImage implements ec2.IMachineImage { private readonly amiParameterName: string; private readonly cachedInContext: boolean; - private readonly linkContextToScope: boolean; + private readonly additionalCacheKey?: string; /** * Constructs a new instance of the EcsOptimizedAmi class. @@ -276,14 +274,14 @@ export class EcsOptimizedImage implements ec2.IMachineImage { + (this.windowsVersion ? 'image_id' : 'recommended/image_id'); this.cachedInContext = props.cachedInContext ?? false; - this.linkContextToScope = props.linkContextToScope ?? false; + if (props.additionalCacheKey) this.additionalCacheKey = props.additionalCacheKey; } /** * Return the correct image */ public getImage(scope: Construct): ec2.MachineImageConfig { - const ami = lookupImage(scope, this.cachedInContext && this.linkContextToScope ? 'scope' : this.cachedInContext, this.amiParameterName); + const ami = lookupImage(scope, this.cachedInContext, this.amiParameterName, this.additionalCacheKey); const osType = this.windowsVersion ? ec2.OperatingSystemType.WINDOWS : ec2.OperatingSystemType.LINUX; return { @@ -346,11 +344,10 @@ export interface BottleRocketImageProps { readonly cachedInContext?: boolean; /** - * If true and cachedInContext is true, the context key will be tied to the passed scope rather than global - * - * @default false + * When the image is cached in cdk.context.json, adds an additional discriminator to the + * cache key so that separate lookups with the same parameters can have separate cache lifecycles */ - readonly linkContextToScope?: boolean + readonly additionalCacheKey?: string; } /** @@ -377,7 +374,7 @@ export class BottleRocketImage implements ec2.IMachineImage { private readonly cachedInContext: boolean; - private readonly linkContextToScope: boolean; + private readonly additionalCacheKey?: string; /** * Constructs a new instance of the BottleRocketImage class. @@ -390,16 +387,14 @@ export class BottleRocketImage implements ec2.IMachineImage { this.amiParameterName = `/aws/service/bottlerocket/${this.variant}/${this.architecture}/latest/image_id`; this.cachedInContext = props.cachedInContext ?? false; - this.linkContextToScope = props.linkContextToScope ?? false; + if (props.additionalCacheKey) this.additionalCacheKey = props.additionalCacheKey; } /** * Return the correct image - * - * If linkContextToScope is true, the context key will be tied to the passed scope rather than global */ public getImage(scope: Construct): ec2.MachineImageConfig { - const ami = lookupImage(scope, this.cachedInContext && this.linkContextToScope ? 'scope' : this.cachedInContext, this.amiParameterName); + const ami = lookupImage(scope, this.cachedInContext, this.amiParameterName, this.additionalCacheKey); return { imageId: ami, @@ -415,8 +410,8 @@ Object.defineProperty(BottleRocketImage.prototype, BR_IMAGE_SYMBOL, { writable: false, }); -function lookupImage(scope: Construct, cachedInContext: boolean | undefined | 'scope', parameterName: string) { +function lookupImage(scope: Construct, cachedInContext: boolean, parameterName: string, additionalCacheKey?: string) { return cachedInContext - ? ssm.StringParameter.valueFromLookup(scope, parameterName, cachedInContext === 'scope') + ? ssm.StringParameter.valueFromLookup(scope, parameterName, additionalCacheKey) : ssm.StringParameter.valueForTypedStringParameterV2(scope, parameterName, ssm.ParameterValueType.AWS_EC2_IMAGE_ID); } diff --git a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/README.md b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/README.md index db0c84fc3d4a3..27f79df0ebdcc 100644 --- a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/README.md +++ b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/README.md @@ -523,10 +523,10 @@ The result of a `fromLookup()` operation will be written to a file called `cdk.context.json`. You must commit this file to source control so that the lookup values are available in non-privileged environments such as CI build steps, and to ensure your template builds are repeatable. -If you want the key of the context variable to be tied to the scope -passed to `fromLookup` instead of being global (usinwhich would use the same -value any time you call `fromLookup` across your entire app), -you can set the `linkContextToScope` argument to `true` +If you do not want the value of the context variable to be global (ie, having the same +value returned any time you call `fromLookup` across your entire app), +you can set the `additionalCacheKey` argument (eg, to `this.node.path` to tie it +to the scope of the current construct) ### Load Balancer lookup options diff --git a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-listener.ts b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-listener.ts index c56c1014518f5..44a5eaf5ecb65 100644 --- a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-listener.ts +++ b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-listener.ts @@ -133,14 +133,11 @@ export interface ApplicationListenerLookupOptions extends BaseListenerLookupOpti export class ApplicationListener extends BaseListener implements IApplicationListener { /** * Look up an ApplicationListener. - * - * If linkContextToScope is true, the cached context key will be tied to the passed scope rather than global */ public static fromLookup( scope: Construct, id: string, options: ApplicationListenerLookupOptions, - linkContextToScope?: boolean, ): IApplicationListener { if (Token.isUnresolved(options.listenerArn)) { throw new Error('All arguments to look up a load balancer listener must be concrete (no Tokens)'); @@ -157,7 +154,7 @@ export class ApplicationListener extends BaseListener implements IApplicationLis loadBalancerType: cxschema.LoadBalancerType.APPLICATION, listenerArn: options.listenerArn, listenerProtocol, - }, linkContextToScope); + }); return new LookedUpApplicationListener(scope, id, props); } diff --git a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-load-balancer.ts b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-load-balancer.ts index 64480b14b2574..3e8d49bfe3ca4 100644 --- a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-load-balancer.ts +++ b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-load-balancer.ts @@ -76,19 +76,16 @@ export interface ApplicationLoadBalancerLookupOptions extends BaseLoadBalancerLo export class ApplicationLoadBalancer extends BaseLoadBalancer implements IApplicationLoadBalancer { /** * Look up an application load balancer. - * - * If linkContextToScope is true, the context key will be tied to the passed scope rather than global */ public static fromLookup( scope: Construct, id: string, options: ApplicationLoadBalancerLookupOptions, - linkContextToScope?: boolean, ): IApplicationLoadBalancer { const props = BaseLoadBalancer._queryContextProvider(scope, { userOptions: options, loadBalancerType: cxschema.LoadBalancerType.APPLICATION, - }, linkContextToScope); + }); return new LookedUpApplicationLoadBalancer(scope, id, props); } diff --git a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/nlb/network-listener.ts b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/nlb/network-listener.ts index 8645c3afdb52e..191a9251d4ff9 100644 --- a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/nlb/network-listener.ts +++ b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/nlb/network-listener.ts @@ -117,10 +117,8 @@ export interface NetworkListenerLookupOptions extends BaseListenerLookupOptions export class NetworkListener extends BaseListener implements INetworkListener { /** * Looks up a network listener - * - * If linkContextToScope is true, the cached context key will be tied to the passed scope rather than global */ - public static fromLookup(scope: Construct, id: string, options: NetworkListenerLookupOptions, linkContextToScope?: boolean): INetworkListener { + public static fromLookup(scope: Construct, id: string, options: NetworkListenerLookupOptions): INetworkListener { let listenerProtocol: cxschema.LoadBalancerListenerProtocol | undefined; if (options.listenerProtocol) { validateNetworkProtocol(options.listenerProtocol); @@ -137,7 +135,7 @@ export class NetworkListener extends BaseListener implements INetworkListener { userOptions: options, listenerProtocol: listenerProtocol, loadBalancerType: cxschema.LoadBalancerType.NETWORK, - }, linkContextToScope); + }); class LookedUp extends Resource implements INetworkListener { public listenerArn = props.listenerArn; diff --git a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/nlb/network-load-balancer.ts b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/nlb/network-load-balancer.ts index d36f450fd8a22..f04546fbbd501 100644 --- a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/nlb/network-load-balancer.ts +++ b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/nlb/network-load-balancer.ts @@ -128,19 +128,16 @@ class NetworkLoadBalancerMetrics implements INetworkLoadBalancerMetrics { export class NetworkLoadBalancer extends BaseLoadBalancer implements INetworkLoadBalancer { /** * Looks up the network load balancer. - * - * If linkContextToScope is true, the cached context key will be tied to the passed scope rather than global */ public static fromLookup( scope: Construct, id: string, options: NetworkLoadBalancerLookupOptions, - linkContextToScope?: boolean, ): INetworkLoadBalancer { const props = BaseLoadBalancer._queryContextProvider(scope, { userOptions: options, loadBalancerType: cxschema.LoadBalancerType.NETWORK, - }, linkContextToScope); + }); return new LookedUpNetworkLoadBalancer(scope, id, props); } diff --git a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-listener.ts b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-listener.ts index 56a0a59912c9f..eecf881cd7530 100644 --- a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-listener.ts +++ b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-listener.ts @@ -27,6 +27,12 @@ export interface BaseListenerLookupOptions { * @default - does not filter by listener port */ readonly listenerPort?: number; + + /** + * When the listener is cached in cdk.context.json, adds an additional discriminator to the + * cache key so that separate lookups with the same parameters can have separate cache lifecycles + */ + readonly additionalCacheKey?: string; } /** @@ -76,7 +82,7 @@ export abstract class BaseListener extends Resource implements IListener { * listener info. * @internal */ - protected static _queryContextProvider(scope: Construct, options: ListenerQueryContextProviderOptions, linkContextToScope?: boolean) { + protected static _queryContextProvider(scope: Construct, options: ListenerQueryContextProviderOptions) { if (Token.isUnresolved(options.userOptions.loadBalancerArn) || Object.values(options.userOptions.loadBalancerTags ?? {}).some(Token.isUnresolved) || Token.isUnresolved(options.userOptions.listenerPort)) { @@ -97,6 +103,7 @@ export abstract class BaseListener extends Resource implements IListener { loadBalancerArn: options.userOptions.loadBalancerArn, loadBalancerTags: cxschemaTags, loadBalancerType: options.loadBalancerType, + ...(options.userOptions.additionalCacheKey ? { additionalCacheKey: options.userOptions.additionalCacheKey } : {}), } as cxschema.LoadBalancerListenerContextQuery, dummyValue: { // eslint-disable-next-line @aws-cdk/no-literal-partition @@ -104,7 +111,6 @@ export abstract class BaseListener extends Resource implements IListener { listenerPort: 80, securityGroupIds: ['sg-123456789012'], } as cxapi.LoadBalancerListenerContextResponse, - includeScope: linkContextToScope, }).value; return props; diff --git a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts index bf3033d397e90..aa68215e225b6 100644 --- a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts +++ b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts @@ -84,6 +84,12 @@ export interface BaseLoadBalancerLookupOptions { * @default - does not match load balancers by tags */ readonly loadBalancerTags?: Record; + + /** + * When the load balancer is cached in cdk.context.json, adds an additional discriminator to the + * cache key so that separate lookups with the same parameters can have separate cache lifecycles + */ + readonly additionalCacheKey?: string; } /** @@ -113,7 +119,6 @@ export abstract class BaseLoadBalancer extends Resource { protected static _queryContextProvider( scope: Construct, options: LoadBalancerQueryContextProviderOptions, - contextCachelinkContextToScope?: boolean, ) { if (Token.isUnresolved(options.userOptions.loadBalancerArn) || Object.values(options.userOptions.loadBalancerTags ?? {}).some(Token.isUnresolved)) { @@ -131,6 +136,7 @@ export abstract class BaseLoadBalancer extends Resource { loadBalancerArn: options.userOptions.loadBalancerArn, loadBalancerTags: cxschemaTags, loadBalancerType: options.loadBalancerType, + ...(options.userOptions.additionalCacheKey ? { additionalCacheKey: options.userOptions.additionalCacheKey } : {}), } as cxschema.LoadBalancerContextQuery, dummyValue: { ipAddressType: cxapi.LoadBalancerIpAddressType.DUAL_STACK, @@ -141,7 +147,6 @@ export abstract class BaseLoadBalancer extends Resource { securityGroupIds: ['sg-1234'], vpcId: 'vpc-12345', } as cxapi.LoadBalancerContextResponse, - includeScope: contextCachelinkContextToScope, }).value; return props; diff --git a/packages/aws-cdk-lib/aws-kms/README.md b/packages/aws-cdk-lib/aws-kms/README.md index 7e263ec23f309..893aa48620cee 100644 --- a/packages/aws-cdk-lib/aws-kms/README.md +++ b/packages/aws-cdk-lib/aws-kms/README.md @@ -95,10 +95,10 @@ The result of the `Key.fromLookup()` operation will be written to a file called `cdk.context.json`. You must commit this file to source control so that the lookup values are available in non-privileged environments such as CI build steps, and to ensure your template builds are repeatable. -If you want the key of the context variable to be tied to the scope -passed to `fromLookup` instead of being global (usinwhich would use the same -value any time you call `fromLookup` across your entire app), -you can set the `linkContextToScope` argument to `true` +If you do not want the value of the context variable to be global (ie, having the same +value returned any time you call `fromLookup` across your entire app), +you can set the `additionalCacheKey` argument (eg, to `this.node.path` to tie it +to the scope of the current construct) Here's how `Key.fromLookup()` can be used: diff --git a/packages/aws-cdk-lib/aws-kms/lib/key-lookup.ts b/packages/aws-cdk-lib/aws-kms/lib/key-lookup.ts index 0ac02b2185d49..8f8ead5da98a3 100644 --- a/packages/aws-cdk-lib/aws-kms/lib/key-lookup.ts +++ b/packages/aws-cdk-lib/aws-kms/lib/key-lookup.ts @@ -8,4 +8,10 @@ export interface KeyLookupOptions { * Must be in the format `alias/`. */ readonly aliasName: string; + + /** + * When the key is cached in cdk.context.json, adds an additional discriminator to the + * cache key so that separate lookups with the same parameters can have separate cache lifecycles + */ + readonly additionalCacheKey?: string; } diff --git a/packages/aws-cdk-lib/aws-kms/lib/key.ts b/packages/aws-cdk-lib/aws-kms/lib/key.ts index 2105667afd879..d4e123162490d 100644 --- a/packages/aws-cdk-lib/aws-kms/lib/key.ts +++ b/packages/aws-cdk-lib/aws-kms/lib/key.ts @@ -622,10 +622,8 @@ export class Key extends KeyBase { * will be used on future runs. To refresh the lookup, you will have to * evict the value from the cache using the `cdk context` command. See * https://docs.aws.amazon.com/cdk/latest/guide/context.html for more information. - * - * If linkContextToScope is true, the context key will be tied to the passed scope rather than global */ - public static fromLookup(scope: Construct, id: string, options: KeyLookupOptions, linkContextToScope?: boolean): IKey { + public static fromLookup(scope: Construct, id: string, options: KeyLookupOptions): IKey { class Import extends KeyBase { public readonly keyArn: string; public readonly keyId: string; @@ -650,11 +648,11 @@ export class Key extends KeyBase { provider: cxschema.ContextProvider.KEY_PROVIDER, props: { aliasName: options.aliasName, + ...(options.additionalCacheKey ? { additionalCacheKey: options.additionalCacheKey } : {}), } as cxschema.KeyContextQuery, dummyValue: { keyId: '1234abcd-12ab-34cd-56ef-1234567890ab', }, - includeScope: linkContextToScope, }).value; return new Import(attributes.keyId, diff --git a/packages/aws-cdk-lib/aws-route53/README.md b/packages/aws-cdk-lib/aws-route53/README.md index 06aa42f6681bd..f6e8accef21d2 100644 --- a/packages/aws-cdk-lib/aws-route53/README.md +++ b/packages/aws-cdk-lib/aws-route53/README.md @@ -251,10 +251,10 @@ The result of the `HostedZone.fromLookup()` operation will be written to a file called `cdk.context.json`. You must commit this file to source control so that the lookup values are available in non-privileged environments such as CI build steps, and to ensure your template builds are repeatable. -If you want the key of the context variable to be tied to the scope -passed to `fromLookup` instead of being global (usinwhich would use the same -value any time you call `fromLookup` across your entire app), -you can set the `linkContextToScope` argument to `true` +If you do not want the value of the context variable to be global (ie, having the same +value returned any time you call `fromLookup` across your entire app), +you can set the `additionalCacheKey` argument (eg, to `this.node.path` to tie it +to the scope of the current construct) `HostedZone.fromLookup` requires an environment to be configured. Check out the [documentation](https://docs.aws.amazon.com/cdk/latest/guide/environments.html) for more documentation and examples. CDK diff --git a/packages/aws-cdk-lib/aws-route53/lib/hosted-zone-provider.ts b/packages/aws-cdk-lib/aws-route53/lib/hosted-zone-provider.ts index 99f7132112e07..00a2bb51e5bf9 100644 --- a/packages/aws-cdk-lib/aws-route53/lib/hosted-zone-provider.ts +++ b/packages/aws-cdk-lib/aws-route53/lib/hosted-zone-provider.ts @@ -23,4 +23,10 @@ export interface HostedZoneProviderProps { * @default - No VPC ID */ readonly vpcId?: string; + + /** + * When the hosted zone is cached in cdk.context.json, adds an additional discriminator to the + * cache key so that separate lookups with the same parameters can have separate cache lifecycles + */ + readonly additionalCacheKey?: string; } diff --git a/packages/aws-cdk-lib/aws-route53/lib/hosted-zone.ts b/packages/aws-cdk-lib/aws-route53/lib/hosted-zone.ts index 317cb06079820..d9361ee2b2d08 100644 --- a/packages/aws-cdk-lib/aws-route53/lib/hosted-zone.ts +++ b/packages/aws-cdk-lib/aws-route53/lib/hosted-zone.ts @@ -122,11 +122,9 @@ export class HostedZone extends Resource implements IHostedZone { * * Use to easily query hosted zones. * - * If linkContextToScope is true, the context key will be tied to the passed scope rather than global - * * @see https://docs.aws.amazon.com/cdk/latest/guide/environments.html */ - public static fromLookup(scope: Construct, id: string, query: HostedZoneProviderProps, linkContextToScope?: boolean): IHostedZone { + public static fromLookup(scope: Construct, id: string, query: HostedZoneProviderProps): IHostedZone { if (!query.domainName) { throw new Error('Cannot use undefined value for attribute `domainName`'); } @@ -145,7 +143,6 @@ export class HostedZone extends Resource implements IHostedZone { provider: cxschema.ContextProvider.HOSTED_ZONE_PROVIDER, dummyValue: DEFAULT_HOSTED_ZONE, props: query, - includeScope: linkContextToScope, }).value; // CDK handles the '.' at the end, so remove it here diff --git a/packages/aws-cdk-lib/aws-ssm/README.md b/packages/aws-cdk-lib/aws-ssm/README.md index 32e964b215702..cdd401d3f48f3 100644 --- a/packages/aws-cdk-lib/aws-ssm/README.md +++ b/packages/aws-cdk-lib/aws-ssm/README.md @@ -62,10 +62,10 @@ The result of the `StringParameter.valueFromLookup()` operation will be written called `cdk.context.json`. You must commit this file to source control so that the lookup values are available in non-privileged environments such as CI build steps, and to ensure your template builds are repeatable. -If you want the key of the context variable to be tied to the scope -passed to `fromLookup` instead of being global (usinwhich would use the same -value any time you call `fromLookup` across your entire app), -you can set the `linkContextToScope` argument to `true` +If you do not want the key of the context variable to be global +(ie, having the same value returned any time you call `fromLookup` across your entire app), +you can set the `additionalCacheKey` argument (eg, to `this.node.path` to tie it +to the scope of the current construct) When using `valueFromLookup` an initial value of 'dummy-value-for-${parameterName}' diff --git a/packages/aws-cdk-lib/aws-ssm/lib/parameter.ts b/packages/aws-cdk-lib/aws-ssm/lib/parameter.ts index 205a526be5bf0..1120cdc18559c 100644 --- a/packages/aws-cdk-lib/aws-ssm/lib/parameter.ts +++ b/packages/aws-cdk-lib/aws-ssm/lib/parameter.ts @@ -531,17 +531,15 @@ export class StringParameter extends ParameterBase implements IStringParameter { * * Requires that the stack this scope is defined in will have explicit * account/region information. Otherwise, it will fail during synthesis. - * - * If linkContextToScope is true, the context key will be tied to the passed scope rather than global */ - public static valueFromLookup(scope: Construct, parameterName: string, linkContextToScope?: boolean): string { + public static valueFromLookup(scope: Construct, parameterName: string, additionalCacheKey?: string): string { const value = ContextProvider.getValue(scope, { provider: cxschema.ContextProvider.SSM_PARAMETER_PROVIDER, props: { parameterName, + additionalCacheKey, }, - dummyValue: linkContextToScope ? `dummy-value-for-${scope.node.path}-${parameterName}` : `dummy-value-for-${parameterName}`, - includeScope: linkContextToScope, + dummyValue: `dummy-value-for-${parameterName}`, }).value; return value; diff --git a/packages/aws-cdk-lib/core/lib/context-provider.ts b/packages/aws-cdk-lib/core/lib/context-provider.ts index 3a0cd5bd6249c..2bbaf7336feed 100644 --- a/packages/aws-cdk-lib/core/lib/context-provider.ts +++ b/packages/aws-cdk-lib/core/lib/context-provider.ts @@ -24,13 +24,6 @@ export interface GetContextKeyOptions { * @default true */ readonly includeEnvironment?: boolean; - - /** - * Whether to include the scope automatically - * - * @default false - */ - readonly includeScope?: boolean; } /** @@ -76,7 +69,6 @@ export class ContextProvider { const props = { ...((options.includeEnvironment ?? true) ? { account: stack.account, region: stack.region } : {}), - ...(options.includeScope ? { scope: scope.node.path } : {}), ...options.props, }; diff --git a/packages/aws-cdk-lib/core/test/context.test.ts b/packages/aws-cdk-lib/core/test/context.test.ts index 0ea7aab2efac7..e7d8c638ed5de 100644 --- a/packages/aws-cdk-lib/core/test/context.test.ts +++ b/packages/aws-cdk-lib/core/test/context.test.ts @@ -134,34 +134,6 @@ describe('context', () => { }); }); - test('Key generation includes the scope when requested', () => { - // GIVEN - const stack = new Stack(undefined, 'TestStack', { env: { account: '12345', region: 'us-east-1' } }); - const resource = new Construct(stack, 'resource'); - - // WHEN - const result = ContextProvider.getKey(resource, { - provider: 'provider', - props: { - p1: 42, - p2: undefined, - }, - includeScope: true, - }); - - // THEN - expect(result).toEqual({ - key: 'provider:account=12345:p1=42:region=us-east-1:scope=TestStack/resource', - props: { - account: '12345', - region: 'us-east-1', - p1: 42, - p2: undefined, - scope: 'TestStack/resource', - }, - }); - }); - test('context provider errors are attached to tree', () => { const contextProps = { provider: 'availability-zones' }; const contextKey = 'availability-zones:account=12345:region=us-east-1'; // Depends on the mangling algo From bf8c6c1ad97db69866321fcffeaf9adb4f943972 Mon Sep 17 00:00:00 2001 From: Jonathan Romano Date: Tue, 19 Sep 2023 15:32:59 -0400 Subject: [PATCH 08/22] Fix unit tests --- packages/aws-cdk-lib/aws-ec2/test/machine-image.test.ts | 4 ++-- packages/aws-cdk-lib/aws-ssm/test/parameter.test.ts | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/aws-cdk-lib/aws-ec2/test/machine-image.test.ts b/packages/aws-cdk-lib/aws-ec2/test/machine-image.test.ts index 776c06aaa9c25..86497001b8ccb 100644 --- a/packages/aws-cdk-lib/aws-ec2/test/machine-image.test.ts +++ b/packages/aws-cdk-lib/aws-ec2/test/machine-image.test.ts @@ -212,10 +212,10 @@ test('cached lookups of Amazon Linux linked to scope', () => { const ami = ec2.MachineImage.latestAmazonLinux({ cachedInContext: true, additionalCacheKey: 'extraKey' }).getImage(stack).imageId; // THEN - expect(ami).toEqual('dummy-value-for-Stack-/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2'); + expect(ami).toEqual('dummy-value-for-/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2'); expect(app.synth().manifest.missing).toEqual([ { - key: 'ssm:account=1234:parameterName=/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2:region=testregion:scope=Stack', + key: 'ssm:account=1234:additionalCacheKey=extraKey:parameterName=/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2:region=testregion', props: { account: '1234', lookupRoleArn: 'arn:${AWS::Partition}:iam::1234:role/cdk-hnb659fds-lookup-role-1234-testregion', diff --git a/packages/aws-cdk-lib/aws-ssm/test/parameter.test.ts b/packages/aws-cdk-lib/aws-ssm/test/parameter.test.ts index 8297a38828241..c712b2b797ba7 100644 --- a/packages/aws-cdk-lib/aws-ssm/test/parameter.test.ts +++ b/packages/aws-cdk-lib/aws-ssm/test/parameter.test.ts @@ -658,18 +658,18 @@ test('fromLookup will use the SSM context provider to read value during synthesi const stack = new cdk.Stack(app, 'my-staq', { env: { region: 'us-east-1', account: '12344' } }); // WHEN - const value = ssm.StringParameter.valueFromLookup(stack, 'my-param-name', true); + const value = ssm.StringParameter.valueFromLookup(stack, 'my-param-name', 'extraKey'); // THEN - expect(value).toEqual('dummy-value-for-my-staq-my-param-name'); + expect(value).toEqual('dummy-value-for-my-param-name'); expect(app.synth().manifest.missing).toEqual([ { - key: 'ssm:account=12344:parameterName=my-param-name:region=us-east-1:scope=my-staq', + key: 'ssm:account=12344:additionalCacheKey=extraKey:parameterName=my-param-name:region=us-east-1', props: { account: '12344', region: 'us-east-1', parameterName: 'my-param-name', - scope: 'my-staq', + additionalCacheKey: 'extraKey', }, provider: 'ssm', }, From 4608dbab73a84508ab0be19350b22b3351e83d8b Mon Sep 17 00:00:00 2001 From: Jonathan Romano Date: Thu, 16 Nov 2023 03:39:34 +0000 Subject: [PATCH 09/22] Remove dead imports --- .../test/aws-ec2/test/integ.machine-image-cached.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.ts index 428399864948e..119688dba9103 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.ts @@ -4,8 +4,6 @@ import { StackProps, App, aws_ec2 as ec2, - // aws_autoscaling as asg, - // aws_ssm as ssm, } from 'aws-cdk-lib'; import { Construct } from 'constructs'; import { EC2_RESTRICT_DEFAULT_SECURITY_GROUP } from 'aws-cdk-lib/cx-api'; From 925bd4881ae562af164e27535ebbccba8f6362d7 Mon Sep 17 00:00:00 2001 From: Jonathan Romano Date: Thu, 16 Nov 2023 03:53:55 +0000 Subject: [PATCH 10/22] Integ structure --- ... cdk-ec2-machine-image-cached.assets.json} | 6 +- ...dk-ec2-machine-image-cached.template.json} | 56 ++--- .../integ.json | 8 +- ...faultTestDeployAssert24B647BE.assets.json} | 2 +- ...ultTestDeployAssert24B647BE.template.json} | 0 .../manifest.json | 120 +++++----- .../tree.json | 206 +++++++++--------- .../test/integ.machine-image-cached.ts | 6 +- 8 files changed, 203 insertions(+), 201 deletions(-) rename packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/{integ-ec2-machine-image-cached-test.assets.json => cdk-ec2-machine-image-cached.assets.json} (64%) rename packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/{integ-ec2-machine-image-cached-test.template.json => cdk-ec2-machine-image-cached.template.json} (87%) rename packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/{integtestDefaultTestDeployAssert24D5C536.assets.json => integec2machineimagecachedDefaultTestDeployAssert24B647BE.assets.json} (87%) rename packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/{integtestDefaultTestDeployAssert24D5C536.template.json => integec2machineimagecachedDefaultTestDeployAssert24B647BE.template.json} (100%) diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ-ec2-machine-image-cached-test.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/cdk-ec2-machine-image-cached.assets.json similarity index 64% rename from packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ-ec2-machine-image-cached-test.assets.json rename to packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/cdk-ec2-machine-image-cached.assets.json index b959f8b0a1419..d71428145dbd8 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ-ec2-machine-image-cached-test.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/cdk-ec2-machine-image-cached.assets.json @@ -1,15 +1,15 @@ { "version": "34.0.0", "files": { - "28b0c40087d5092de80f9eb21ff6e74380b5503e7fe85d136141b47f90ba55dc": { + "18035a5c59b3c622a6f952b627e53ba58bcfc4f09c0ba6b55886e25644395ce6": { "source": { - "path": "integ-ec2-machine-image-cached-test.template.json", + "path": "cdk-ec2-machine-image-cached.template.json", "packaging": "file" }, "destinations": { "12345678-test-region": { "bucketName": "cdk-hnb659fds-assets-12345678-test-region", - "objectKey": "28b0c40087d5092de80f9eb21ff6e74380b5503e7fe85d136141b47f90ba55dc.json", + "objectKey": "18035a5c59b3c622a6f952b627e53ba58bcfc4f09c0ba6b55886e25644395ce6.json", "region": "test-region", "assumeRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-file-publishing-role-12345678-test-region" } diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ-ec2-machine-image-cached-test.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/cdk-ec2-machine-image-cached.template.json similarity index 87% rename from packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ-ec2-machine-image-cached-test.template.json rename to packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/cdk-ec2-machine-image-cached.template.json index 35364454908e7..df901543822cc 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ-ec2-machine-image-cached-test.template.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/cdk-ec2-machine-image-cached.template.json @@ -10,7 +10,7 @@ "Tags": [ { "Key": "Name", - "Value": "integ-ec2-machine-image-cached-test/Vpc" + "Value": "cdk-ec2-machine-image-cached/Vpc" } ] } @@ -32,7 +32,7 @@ }, { "Key": "Name", - "Value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1" + "Value": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet1" } ], "VpcId": { @@ -46,7 +46,7 @@ "Tags": [ { "Key": "Name", - "Value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1" + "Value": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet1" } ], "VpcId": { @@ -87,7 +87,7 @@ "Tags": [ { "Key": "Name", - "Value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1" + "Value": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet1" } ] } @@ -107,7 +107,7 @@ "Tags": [ { "Key": "Name", - "Value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1" + "Value": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet1" } ] }, @@ -133,7 +133,7 @@ }, { "Key": "Name", - "Value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2" + "Value": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet2" } ], "VpcId": { @@ -147,7 +147,7 @@ "Tags": [ { "Key": "Name", - "Value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2" + "Value": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet2" } ], "VpcId": { @@ -188,7 +188,7 @@ "Tags": [ { "Key": "Name", - "Value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2" + "Value": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet2" } ] } @@ -208,7 +208,7 @@ "Tags": [ { "Key": "Name", - "Value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2" + "Value": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet2" } ] }, @@ -234,7 +234,7 @@ }, { "Key": "Name", - "Value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3" + "Value": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet3" } ], "VpcId": { @@ -248,7 +248,7 @@ "Tags": [ { "Key": "Name", - "Value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3" + "Value": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet3" } ], "VpcId": { @@ -289,7 +289,7 @@ "Tags": [ { "Key": "Name", - "Value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3" + "Value": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet3" } ] } @@ -309,7 +309,7 @@ "Tags": [ { "Key": "Name", - "Value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3" + "Value": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet3" } ] }, @@ -335,7 +335,7 @@ }, { "Key": "Name", - "Value": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet1" + "Value": "cdk-ec2-machine-image-cached/Vpc/PrivateSubnet1" } ], "VpcId": { @@ -349,7 +349,7 @@ "Tags": [ { "Key": "Name", - "Value": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet1" + "Value": "cdk-ec2-machine-image-cached/Vpc/PrivateSubnet1" } ], "VpcId": { @@ -397,7 +397,7 @@ }, { "Key": "Name", - "Value": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet2" + "Value": "cdk-ec2-machine-image-cached/Vpc/PrivateSubnet2" } ], "VpcId": { @@ -411,7 +411,7 @@ "Tags": [ { "Key": "Name", - "Value": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet2" + "Value": "cdk-ec2-machine-image-cached/Vpc/PrivateSubnet2" } ], "VpcId": { @@ -459,7 +459,7 @@ }, { "Key": "Name", - "Value": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet3" + "Value": "cdk-ec2-machine-image-cached/Vpc/PrivateSubnet3" } ], "VpcId": { @@ -473,7 +473,7 @@ "Tags": [ { "Key": "Name", - "Value": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet3" + "Value": "cdk-ec2-machine-image-cached/Vpc/PrivateSubnet3" } ], "VpcId": { @@ -510,7 +510,7 @@ "Tags": [ { "Key": "Name", - "Value": "integ-ec2-machine-image-cached-test/Vpc" + "Value": "cdk-ec2-machine-image-cached/Vpc" } ] } @@ -529,7 +529,7 @@ "al2023CachedInstanceSecurityGroup2719C9BA": { "Type": "AWS::EC2::SecurityGroup", "Properties": { - "GroupDescription": "integ-ec2-machine-image-cached-test/al2023Cached/InstanceSecurityGroup", + "GroupDescription": "cdk-ec2-machine-image-cached/al2023Cached/InstanceSecurityGroup", "SecurityGroupEgress": [ { "CidrIp": "0.0.0.0/0", @@ -540,7 +540,7 @@ "Tags": [ { "Key": "Name", - "Value": "integ-ec2-machine-image-cached-test/al2023Cached" + "Value": "cdk-ec2-machine-image-cached/al2023Cached" } ], "VpcId": { @@ -566,7 +566,7 @@ "Tags": [ { "Key": "Name", - "Value": "integ-ec2-machine-image-cached-test/al2023Cached" + "Value": "cdk-ec2-machine-image-cached/al2023Cached" } ] } @@ -604,7 +604,7 @@ "Tags": [ { "Key": "Name", - "Value": "integ-ec2-machine-image-cached-test/al2023Cached" + "Value": "cdk-ec2-machine-image-cached/al2023Cached" } ], "UserData": { @@ -618,7 +618,7 @@ "al2023CachedScopeInstanceSecurityGroupADC3C195": { "Type": "AWS::EC2::SecurityGroup", "Properties": { - "GroupDescription": "integ-ec2-machine-image-cached-test/al2023CachedScope/InstanceSecurityGroup", + "GroupDescription": "cdk-ec2-machine-image-cached/al2023CachedScope/InstanceSecurityGroup", "SecurityGroupEgress": [ { "CidrIp": "0.0.0.0/0", @@ -629,7 +629,7 @@ "Tags": [ { "Key": "Name", - "Value": "integ-ec2-machine-image-cached-test/al2023CachedScope" + "Value": "cdk-ec2-machine-image-cached/al2023CachedScope" } ], "VpcId": { @@ -655,7 +655,7 @@ "Tags": [ { "Key": "Name", - "Value": "integ-ec2-machine-image-cached-test/al2023CachedScope" + "Value": "cdk-ec2-machine-image-cached/al2023CachedScope" } ] } @@ -693,7 +693,7 @@ "Tags": [ { "Key": "Name", - "Value": "integ-ec2-machine-image-cached-test/al2023CachedScope" + "Value": "cdk-ec2-machine-image-cached/al2023CachedScope" } ], "UserData": { diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ.json index ca879e60af22b..90c551c143d47 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integ.json @@ -2,12 +2,12 @@ "enableLookups": true, "version": "34.0.0", "testCases": { - "integ-test/DefaultTest": { + "integ-ec2-machine-image-cached/DefaultTest": { "stacks": [ - "integ-ec2-machine-image-cached-test" + "cdk-ec2-machine-image-cached" ], - "assertionStack": "integ-test/DefaultTest/DeployAssert", - "assertionStackName": "integtestDefaultTestDeployAssert24D5C536" + "assertionStack": "integ-ec2-machine-image-cached/DefaultTest/DeployAssert", + "assertionStackName": "integec2machineimagecachedDefaultTestDeployAssert24B647BE" } } } \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integtestDefaultTestDeployAssert24D5C536.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integec2machineimagecachedDefaultTestDeployAssert24B647BE.assets.json similarity index 87% rename from packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integtestDefaultTestDeployAssert24D5C536.assets.json rename to packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integec2machineimagecachedDefaultTestDeployAssert24B647BE.assets.json index 2b470996152e4..e729a7bb8fce7 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integtestDefaultTestDeployAssert24D5C536.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integec2machineimagecachedDefaultTestDeployAssert24B647BE.assets.json @@ -3,7 +3,7 @@ "files": { "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { "source": { - "path": "integtestDefaultTestDeployAssert24D5C536.template.json", + "path": "integec2machineimagecachedDefaultTestDeployAssert24B647BE.template.json", "packaging": "file" }, "destinations": { diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integtestDefaultTestDeployAssert24D5C536.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integec2machineimagecachedDefaultTestDeployAssert24B647BE.template.json similarity index 100% rename from packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integtestDefaultTestDeployAssert24D5C536.template.json rename to packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/integec2machineimagecachedDefaultTestDeployAssert24B647BE.template.json diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/manifest.json index f5297cc4d5f4b..38dd0484a013d 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/manifest.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/manifest.json @@ -1,27 +1,27 @@ { "version": "34.0.0", "artifacts": { - "integ-ec2-machine-image-cached-test.assets": { + "cdk-ec2-machine-image-cached.assets": { "type": "cdk:asset-manifest", "properties": { - "file": "integ-ec2-machine-image-cached-test.assets.json", + "file": "cdk-ec2-machine-image-cached.assets.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" } }, - "integ-ec2-machine-image-cached-test": { + "cdk-ec2-machine-image-cached": { "type": "aws:cloudformation:stack", "environment": "aws://12345678/test-region", "properties": { - "templateFile": "integ-ec2-machine-image-cached-test.template.json", + "templateFile": "cdk-ec2-machine-image-cached.template.json", "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-deploy-role-12345678-test-region", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-cfn-exec-role-12345678-test-region", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-12345678-test-region/28b0c40087d5092de80f9eb21ff6e74380b5503e7fe85d136141b47f90ba55dc.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-12345678-test-region/18035a5c59b3c622a6f952b627e53ba58bcfc4f09c0ba6b55886e25644395ce6.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ - "integ-ec2-machine-image-cached-test.assets" + "cdk-ec2-machine-image-cached.assets" ], "lookupRole": { "arn": "arn:${AWS::Partition}:iam::12345678:role/cdk-hnb659fds-lookup-role-12345678-test-region", @@ -30,283 +30,283 @@ } }, "dependencies": [ - "integ-ec2-machine-image-cached-test.assets" + "cdk-ec2-machine-image-cached.assets" ], "metadata": { - "/integ-ec2-machine-image-cached-test/Vpc/Resource": [ + "/cdk-ec2-machine-image-cached/Vpc/Resource": [ { "type": "aws:cdk:logicalId", "data": "Vpc8378EB38" } ], - "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1/Subnet": [ + "/cdk-ec2-machine-image-cached/Vpc/PublicSubnet1/Subnet": [ { "type": "aws:cdk:logicalId", "data": "VpcPublicSubnet1Subnet5C2D37C4" } ], - "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1/RouteTable": [ + "/cdk-ec2-machine-image-cached/Vpc/PublicSubnet1/RouteTable": [ { "type": "aws:cdk:logicalId", "data": "VpcPublicSubnet1RouteTable6C95E38E" } ], - "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1/RouteTableAssociation": [ + "/cdk-ec2-machine-image-cached/Vpc/PublicSubnet1/RouteTableAssociation": [ { "type": "aws:cdk:logicalId", "data": "VpcPublicSubnet1RouteTableAssociation97140677" } ], - "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1/DefaultRoute": [ + "/cdk-ec2-machine-image-cached/Vpc/PublicSubnet1/DefaultRoute": [ { "type": "aws:cdk:logicalId", "data": "VpcPublicSubnet1DefaultRoute3DA9E72A" } ], - "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1/EIP": [ + "/cdk-ec2-machine-image-cached/Vpc/PublicSubnet1/EIP": [ { "type": "aws:cdk:logicalId", "data": "VpcPublicSubnet1EIPD7E02669" } ], - "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1/NATGateway": [ + "/cdk-ec2-machine-image-cached/Vpc/PublicSubnet1/NATGateway": [ { "type": "aws:cdk:logicalId", "data": "VpcPublicSubnet1NATGateway4D7517AA" } ], - "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2/Subnet": [ + "/cdk-ec2-machine-image-cached/Vpc/PublicSubnet2/Subnet": [ { "type": "aws:cdk:logicalId", "data": "VpcPublicSubnet2Subnet691E08A3" } ], - "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2/RouteTable": [ + "/cdk-ec2-machine-image-cached/Vpc/PublicSubnet2/RouteTable": [ { "type": "aws:cdk:logicalId", "data": "VpcPublicSubnet2RouteTable94F7E489" } ], - "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2/RouteTableAssociation": [ + "/cdk-ec2-machine-image-cached/Vpc/PublicSubnet2/RouteTableAssociation": [ { "type": "aws:cdk:logicalId", "data": "VpcPublicSubnet2RouteTableAssociationDD5762D8" } ], - "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2/DefaultRoute": [ + "/cdk-ec2-machine-image-cached/Vpc/PublicSubnet2/DefaultRoute": [ { "type": "aws:cdk:logicalId", "data": "VpcPublicSubnet2DefaultRoute97F91067" } ], - "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2/EIP": [ + "/cdk-ec2-machine-image-cached/Vpc/PublicSubnet2/EIP": [ { "type": "aws:cdk:logicalId", "data": "VpcPublicSubnet2EIP3C605A87" } ], - "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2/NATGateway": [ + "/cdk-ec2-machine-image-cached/Vpc/PublicSubnet2/NATGateway": [ { "type": "aws:cdk:logicalId", "data": "VpcPublicSubnet2NATGateway9182C01D" } ], - "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3/Subnet": [ + "/cdk-ec2-machine-image-cached/Vpc/PublicSubnet3/Subnet": [ { "type": "aws:cdk:logicalId", "data": "VpcPublicSubnet3SubnetBE12F0B6" } ], - "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3/RouteTable": [ + "/cdk-ec2-machine-image-cached/Vpc/PublicSubnet3/RouteTable": [ { "type": "aws:cdk:logicalId", "data": "VpcPublicSubnet3RouteTable93458DBB" } ], - "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3/RouteTableAssociation": [ + "/cdk-ec2-machine-image-cached/Vpc/PublicSubnet3/RouteTableAssociation": [ { "type": "aws:cdk:logicalId", "data": "VpcPublicSubnet3RouteTableAssociation1F1EDF02" } ], - "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3/DefaultRoute": [ + "/cdk-ec2-machine-image-cached/Vpc/PublicSubnet3/DefaultRoute": [ { "type": "aws:cdk:logicalId", "data": "VpcPublicSubnet3DefaultRoute4697774F" } ], - "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3/EIP": [ + "/cdk-ec2-machine-image-cached/Vpc/PublicSubnet3/EIP": [ { "type": "aws:cdk:logicalId", "data": "VpcPublicSubnet3EIP3A666A23" } ], - "/integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3/NATGateway": [ + "/cdk-ec2-machine-image-cached/Vpc/PublicSubnet3/NATGateway": [ { "type": "aws:cdk:logicalId", "data": "VpcPublicSubnet3NATGateway7640CD1D" } ], - "/integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet1/Subnet": [ + "/cdk-ec2-machine-image-cached/Vpc/PrivateSubnet1/Subnet": [ { "type": "aws:cdk:logicalId", "data": "VpcPrivateSubnet1Subnet536B997A" } ], - "/integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet1/RouteTable": [ + "/cdk-ec2-machine-image-cached/Vpc/PrivateSubnet1/RouteTable": [ { "type": "aws:cdk:logicalId", "data": "VpcPrivateSubnet1RouteTableB2C5B500" } ], - "/integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet1/RouteTableAssociation": [ + "/cdk-ec2-machine-image-cached/Vpc/PrivateSubnet1/RouteTableAssociation": [ { "type": "aws:cdk:logicalId", "data": "VpcPrivateSubnet1RouteTableAssociation70C59FA6" } ], - "/integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet1/DefaultRoute": [ + "/cdk-ec2-machine-image-cached/Vpc/PrivateSubnet1/DefaultRoute": [ { "type": "aws:cdk:logicalId", "data": "VpcPrivateSubnet1DefaultRouteBE02A9ED" } ], - "/integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet2/Subnet": [ + "/cdk-ec2-machine-image-cached/Vpc/PrivateSubnet2/Subnet": [ { "type": "aws:cdk:logicalId", "data": "VpcPrivateSubnet2Subnet3788AAA1" } ], - "/integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet2/RouteTable": [ + "/cdk-ec2-machine-image-cached/Vpc/PrivateSubnet2/RouteTable": [ { "type": "aws:cdk:logicalId", "data": "VpcPrivateSubnet2RouteTableA678073B" } ], - "/integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet2/RouteTableAssociation": [ + "/cdk-ec2-machine-image-cached/Vpc/PrivateSubnet2/RouteTableAssociation": [ { "type": "aws:cdk:logicalId", "data": "VpcPrivateSubnet2RouteTableAssociationA89CAD56" } ], - "/integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet2/DefaultRoute": [ + "/cdk-ec2-machine-image-cached/Vpc/PrivateSubnet2/DefaultRoute": [ { "type": "aws:cdk:logicalId", "data": "VpcPrivateSubnet2DefaultRoute060D2087" } ], - "/integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet3/Subnet": [ + "/cdk-ec2-machine-image-cached/Vpc/PrivateSubnet3/Subnet": [ { "type": "aws:cdk:logicalId", "data": "VpcPrivateSubnet3SubnetF258B56E" } ], - "/integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet3/RouteTable": [ + "/cdk-ec2-machine-image-cached/Vpc/PrivateSubnet3/RouteTable": [ { "type": "aws:cdk:logicalId", "data": "VpcPrivateSubnet3RouteTableD98824C7" } ], - "/integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet3/RouteTableAssociation": [ + "/cdk-ec2-machine-image-cached/Vpc/PrivateSubnet3/RouteTableAssociation": [ { "type": "aws:cdk:logicalId", "data": "VpcPrivateSubnet3RouteTableAssociation16BDDC43" } ], - "/integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet3/DefaultRoute": [ + "/cdk-ec2-machine-image-cached/Vpc/PrivateSubnet3/DefaultRoute": [ { "type": "aws:cdk:logicalId", "data": "VpcPrivateSubnet3DefaultRoute94B74F0D" } ], - "/integ-ec2-machine-image-cached-test/Vpc/IGW": [ + "/cdk-ec2-machine-image-cached/Vpc/IGW": [ { "type": "aws:cdk:logicalId", "data": "VpcIGWD7BA715C" } ], - "/integ-ec2-machine-image-cached-test/Vpc/VPCGW": [ + "/cdk-ec2-machine-image-cached/Vpc/VPCGW": [ { "type": "aws:cdk:logicalId", "data": "VpcVPCGWBF912B6E" } ], - "/integ-ec2-machine-image-cached-test/al2023Cached/InstanceSecurityGroup/Resource": [ + "/cdk-ec2-machine-image-cached/al2023Cached/InstanceSecurityGroup/Resource": [ { "type": "aws:cdk:logicalId", "data": "al2023CachedInstanceSecurityGroup2719C9BA" } ], - "/integ-ec2-machine-image-cached-test/al2023Cached/InstanceRole/Resource": [ + "/cdk-ec2-machine-image-cached/al2023Cached/InstanceRole/Resource": [ { "type": "aws:cdk:logicalId", "data": "al2023CachedInstanceRoleD76E1DF5" } ], - "/integ-ec2-machine-image-cached-test/al2023Cached/InstanceProfile": [ + "/cdk-ec2-machine-image-cached/al2023Cached/InstanceProfile": [ { "type": "aws:cdk:logicalId", "data": "al2023CachedInstanceProfileD264357E" } ], - "/integ-ec2-machine-image-cached-test/al2023Cached/Resource": [ + "/cdk-ec2-machine-image-cached/al2023Cached/Resource": [ { "type": "aws:cdk:logicalId", "data": "al2023Cached1FFF710B" } ], - "/integ-ec2-machine-image-cached-test/al2023CachedScope/InstanceSecurityGroup/Resource": [ + "/cdk-ec2-machine-image-cached/al2023CachedScope/InstanceSecurityGroup/Resource": [ { "type": "aws:cdk:logicalId", "data": "al2023CachedScopeInstanceSecurityGroupADC3C195" } ], - "/integ-ec2-machine-image-cached-test/al2023CachedScope/InstanceRole/Resource": [ + "/cdk-ec2-machine-image-cached/al2023CachedScope/InstanceRole/Resource": [ { "type": "aws:cdk:logicalId", "data": "al2023CachedScopeInstanceRoleB7C63F12" } ], - "/integ-ec2-machine-image-cached-test/al2023CachedScope/InstanceProfile": [ + "/cdk-ec2-machine-image-cached/al2023CachedScope/InstanceProfile": [ { "type": "aws:cdk:logicalId", "data": "al2023CachedScopeInstanceProfileD8064966" } ], - "/integ-ec2-machine-image-cached-test/al2023CachedScope/Resource": [ + "/cdk-ec2-machine-image-cached/al2023CachedScope/Resource": [ { "type": "aws:cdk:logicalId", "data": "al2023CachedScopeF8E30E37" } ], - "/integ-ec2-machine-image-cached-test/BootstrapVersion": [ + "/cdk-ec2-machine-image-cached/BootstrapVersion": [ { "type": "aws:cdk:logicalId", "data": "BootstrapVersion" } ], - "/integ-ec2-machine-image-cached-test/CheckBootstrapVersion": [ + "/cdk-ec2-machine-image-cached/CheckBootstrapVersion": [ { "type": "aws:cdk:logicalId", "data": "CheckBootstrapVersion" } ] }, - "displayName": "integ-ec2-machine-image-cached-test" + "displayName": "cdk-ec2-machine-image-cached" }, - "integtestDefaultTestDeployAssert24D5C536.assets": { + "integec2machineimagecachedDefaultTestDeployAssert24B647BE.assets": { "type": "cdk:asset-manifest", "properties": { - "file": "integtestDefaultTestDeployAssert24D5C536.assets.json", + "file": "integec2machineimagecachedDefaultTestDeployAssert24B647BE.assets.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" } }, - "integtestDefaultTestDeployAssert24D5C536": { + "integec2machineimagecachedDefaultTestDeployAssert24B647BE": { "type": "aws:cloudformation:stack", "environment": "aws://unknown-account/unknown-region", "properties": { - "templateFile": "integtestDefaultTestDeployAssert24D5C536.template.json", + "templateFile": "integec2machineimagecachedDefaultTestDeployAssert24B647BE.template.json", "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", @@ -314,7 +314,7 @@ "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ - "integtestDefaultTestDeployAssert24D5C536.assets" + "integec2machineimagecachedDefaultTestDeployAssert24B647BE.assets" ], "lookupRole": { "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", @@ -323,23 +323,23 @@ } }, "dependencies": [ - "integtestDefaultTestDeployAssert24D5C536.assets" + "integec2machineimagecachedDefaultTestDeployAssert24B647BE.assets" ], "metadata": { - "/integ-test/DefaultTest/DeployAssert/BootstrapVersion": [ + "/integ-ec2-machine-image-cached/DefaultTest/DeployAssert/BootstrapVersion": [ { "type": "aws:cdk:logicalId", "data": "BootstrapVersion" } ], - "/integ-test/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + "/integ-ec2-machine-image-cached/DefaultTest/DeployAssert/CheckBootstrapVersion": [ { "type": "aws:cdk:logicalId", "data": "CheckBootstrapVersion" } ] }, - "displayName": "integ-test/DefaultTest/DeployAssert" + "displayName": "integ-ec2-machine-image-cached/DefaultTest/DeployAssert" }, "Tree": { "type": "cdk:tree", diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/tree.json index 79577a7c5b691..ec51bfe019314 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/tree.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.js.snapshot/tree.json @@ -4,17 +4,17 @@ "id": "App", "path": "", "children": { - "integ-ec2-machine-image-cached-test": { - "id": "integ-ec2-machine-image-cached-test", - "path": "integ-ec2-machine-image-cached-test", + "cdk-ec2-machine-image-cached": { + "id": "cdk-ec2-machine-image-cached", + "path": "cdk-ec2-machine-image-cached", "children": { "Vpc": { "id": "Vpc", - "path": "integ-ec2-machine-image-cached-test/Vpc", + "path": "cdk-ec2-machine-image-cached/Vpc", "children": { "Resource": { "id": "Resource", - "path": "integ-ec2-machine-image-cached-test/Vpc/Resource", + "path": "cdk-ec2-machine-image-cached/Vpc/Resource", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::VPC", "aws:cdk:cloudformation:props": { @@ -25,7 +25,7 @@ "tags": [ { "key": "Name", - "value": "integ-ec2-machine-image-cached-test/Vpc" + "value": "cdk-ec2-machine-image-cached/Vpc" } ] } @@ -37,11 +37,11 @@ }, "PublicSubnet1": { "id": "PublicSubnet1", - "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1", + "path": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet1", "children": { "Subnet": { "id": "Subnet", - "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1/Subnet", + "path": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet1/Subnet", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", "aws:cdk:cloudformation:props": { @@ -59,7 +59,7 @@ }, { "key": "Name", - "value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1" + "value": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet1" } ], "vpcId": { @@ -74,7 +74,7 @@ }, "Acl": { "id": "Acl", - "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1/Acl", + "path": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet1/Acl", "constructInfo": { "fqn": "aws-cdk-lib.Resource", "version": "0.0.0" @@ -82,14 +82,14 @@ }, "RouteTable": { "id": "RouteTable", - "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1/RouteTable", + "path": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet1/RouteTable", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", "aws:cdk:cloudformation:props": { "tags": [ { "key": "Name", - "value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1" + "value": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet1" } ], "vpcId": { @@ -104,7 +104,7 @@ }, "RouteTableAssociation": { "id": "RouteTableAssociation", - "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1/RouteTableAssociation", + "path": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet1/RouteTableAssociation", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", "aws:cdk:cloudformation:props": { @@ -123,7 +123,7 @@ }, "DefaultRoute": { "id": "DefaultRoute", - "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1/DefaultRoute", + "path": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet1/DefaultRoute", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::Route", "aws:cdk:cloudformation:props": { @@ -143,7 +143,7 @@ }, "EIP": { "id": "EIP", - "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1/EIP", + "path": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet1/EIP", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::EIP", "aws:cdk:cloudformation:props": { @@ -151,7 +151,7 @@ "tags": [ { "key": "Name", - "value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1" + "value": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet1" } ] } @@ -163,7 +163,7 @@ }, "NATGateway": { "id": "NATGateway", - "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1/NATGateway", + "path": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet1/NATGateway", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::NatGateway", "aws:cdk:cloudformation:props": { @@ -179,7 +179,7 @@ "tags": [ { "key": "Name", - "value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet1" + "value": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet1" } ] } @@ -197,11 +197,11 @@ }, "PublicSubnet2": { "id": "PublicSubnet2", - "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2", + "path": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet2", "children": { "Subnet": { "id": "Subnet", - "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2/Subnet", + "path": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet2/Subnet", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", "aws:cdk:cloudformation:props": { @@ -219,7 +219,7 @@ }, { "key": "Name", - "value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2" + "value": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet2" } ], "vpcId": { @@ -234,7 +234,7 @@ }, "Acl": { "id": "Acl", - "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2/Acl", + "path": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet2/Acl", "constructInfo": { "fqn": "aws-cdk-lib.Resource", "version": "0.0.0" @@ -242,14 +242,14 @@ }, "RouteTable": { "id": "RouteTable", - "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2/RouteTable", + "path": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet2/RouteTable", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", "aws:cdk:cloudformation:props": { "tags": [ { "key": "Name", - "value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2" + "value": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet2" } ], "vpcId": { @@ -264,7 +264,7 @@ }, "RouteTableAssociation": { "id": "RouteTableAssociation", - "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2/RouteTableAssociation", + "path": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet2/RouteTableAssociation", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", "aws:cdk:cloudformation:props": { @@ -283,7 +283,7 @@ }, "DefaultRoute": { "id": "DefaultRoute", - "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2/DefaultRoute", + "path": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet2/DefaultRoute", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::Route", "aws:cdk:cloudformation:props": { @@ -303,7 +303,7 @@ }, "EIP": { "id": "EIP", - "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2/EIP", + "path": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet2/EIP", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::EIP", "aws:cdk:cloudformation:props": { @@ -311,7 +311,7 @@ "tags": [ { "key": "Name", - "value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2" + "value": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet2" } ] } @@ -323,7 +323,7 @@ }, "NATGateway": { "id": "NATGateway", - "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2/NATGateway", + "path": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet2/NATGateway", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::NatGateway", "aws:cdk:cloudformation:props": { @@ -339,7 +339,7 @@ "tags": [ { "key": "Name", - "value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet2" + "value": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet2" } ] } @@ -357,11 +357,11 @@ }, "PublicSubnet3": { "id": "PublicSubnet3", - "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3", + "path": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet3", "children": { "Subnet": { "id": "Subnet", - "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3/Subnet", + "path": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet3/Subnet", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", "aws:cdk:cloudformation:props": { @@ -379,7 +379,7 @@ }, { "key": "Name", - "value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3" + "value": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet3" } ], "vpcId": { @@ -394,7 +394,7 @@ }, "Acl": { "id": "Acl", - "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3/Acl", + "path": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet3/Acl", "constructInfo": { "fqn": "aws-cdk-lib.Resource", "version": "0.0.0" @@ -402,14 +402,14 @@ }, "RouteTable": { "id": "RouteTable", - "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3/RouteTable", + "path": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet3/RouteTable", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", "aws:cdk:cloudformation:props": { "tags": [ { "key": "Name", - "value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3" + "value": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet3" } ], "vpcId": { @@ -424,7 +424,7 @@ }, "RouteTableAssociation": { "id": "RouteTableAssociation", - "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3/RouteTableAssociation", + "path": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet3/RouteTableAssociation", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", "aws:cdk:cloudformation:props": { @@ -443,7 +443,7 @@ }, "DefaultRoute": { "id": "DefaultRoute", - "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3/DefaultRoute", + "path": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet3/DefaultRoute", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::Route", "aws:cdk:cloudformation:props": { @@ -463,7 +463,7 @@ }, "EIP": { "id": "EIP", - "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3/EIP", + "path": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet3/EIP", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::EIP", "aws:cdk:cloudformation:props": { @@ -471,7 +471,7 @@ "tags": [ { "key": "Name", - "value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3" + "value": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet3" } ] } @@ -483,7 +483,7 @@ }, "NATGateway": { "id": "NATGateway", - "path": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3/NATGateway", + "path": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet3/NATGateway", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::NatGateway", "aws:cdk:cloudformation:props": { @@ -499,7 +499,7 @@ "tags": [ { "key": "Name", - "value": "integ-ec2-machine-image-cached-test/Vpc/PublicSubnet3" + "value": "cdk-ec2-machine-image-cached/Vpc/PublicSubnet3" } ] } @@ -517,11 +517,11 @@ }, "PrivateSubnet1": { "id": "PrivateSubnet1", - "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet1", + "path": "cdk-ec2-machine-image-cached/Vpc/PrivateSubnet1", "children": { "Subnet": { "id": "Subnet", - "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet1/Subnet", + "path": "cdk-ec2-machine-image-cached/Vpc/PrivateSubnet1/Subnet", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", "aws:cdk:cloudformation:props": { @@ -539,7 +539,7 @@ }, { "key": "Name", - "value": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet1" + "value": "cdk-ec2-machine-image-cached/Vpc/PrivateSubnet1" } ], "vpcId": { @@ -554,7 +554,7 @@ }, "Acl": { "id": "Acl", - "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet1/Acl", + "path": "cdk-ec2-machine-image-cached/Vpc/PrivateSubnet1/Acl", "constructInfo": { "fqn": "aws-cdk-lib.Resource", "version": "0.0.0" @@ -562,14 +562,14 @@ }, "RouteTable": { "id": "RouteTable", - "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet1/RouteTable", + "path": "cdk-ec2-machine-image-cached/Vpc/PrivateSubnet1/RouteTable", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", "aws:cdk:cloudformation:props": { "tags": [ { "key": "Name", - "value": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet1" + "value": "cdk-ec2-machine-image-cached/Vpc/PrivateSubnet1" } ], "vpcId": { @@ -584,7 +584,7 @@ }, "RouteTableAssociation": { "id": "RouteTableAssociation", - "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet1/RouteTableAssociation", + "path": "cdk-ec2-machine-image-cached/Vpc/PrivateSubnet1/RouteTableAssociation", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", "aws:cdk:cloudformation:props": { @@ -603,7 +603,7 @@ }, "DefaultRoute": { "id": "DefaultRoute", - "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet1/DefaultRoute", + "path": "cdk-ec2-machine-image-cached/Vpc/PrivateSubnet1/DefaultRoute", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::Route", "aws:cdk:cloudformation:props": { @@ -629,11 +629,11 @@ }, "PrivateSubnet2": { "id": "PrivateSubnet2", - "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet2", + "path": "cdk-ec2-machine-image-cached/Vpc/PrivateSubnet2", "children": { "Subnet": { "id": "Subnet", - "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet2/Subnet", + "path": "cdk-ec2-machine-image-cached/Vpc/PrivateSubnet2/Subnet", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", "aws:cdk:cloudformation:props": { @@ -651,7 +651,7 @@ }, { "key": "Name", - "value": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet2" + "value": "cdk-ec2-machine-image-cached/Vpc/PrivateSubnet2" } ], "vpcId": { @@ -666,7 +666,7 @@ }, "Acl": { "id": "Acl", - "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet2/Acl", + "path": "cdk-ec2-machine-image-cached/Vpc/PrivateSubnet2/Acl", "constructInfo": { "fqn": "aws-cdk-lib.Resource", "version": "0.0.0" @@ -674,14 +674,14 @@ }, "RouteTable": { "id": "RouteTable", - "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet2/RouteTable", + "path": "cdk-ec2-machine-image-cached/Vpc/PrivateSubnet2/RouteTable", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", "aws:cdk:cloudformation:props": { "tags": [ { "key": "Name", - "value": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet2" + "value": "cdk-ec2-machine-image-cached/Vpc/PrivateSubnet2" } ], "vpcId": { @@ -696,7 +696,7 @@ }, "RouteTableAssociation": { "id": "RouteTableAssociation", - "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet2/RouteTableAssociation", + "path": "cdk-ec2-machine-image-cached/Vpc/PrivateSubnet2/RouteTableAssociation", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", "aws:cdk:cloudformation:props": { @@ -715,7 +715,7 @@ }, "DefaultRoute": { "id": "DefaultRoute", - "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet2/DefaultRoute", + "path": "cdk-ec2-machine-image-cached/Vpc/PrivateSubnet2/DefaultRoute", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::Route", "aws:cdk:cloudformation:props": { @@ -741,11 +741,11 @@ }, "PrivateSubnet3": { "id": "PrivateSubnet3", - "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet3", + "path": "cdk-ec2-machine-image-cached/Vpc/PrivateSubnet3", "children": { "Subnet": { "id": "Subnet", - "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet3/Subnet", + "path": "cdk-ec2-machine-image-cached/Vpc/PrivateSubnet3/Subnet", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", "aws:cdk:cloudformation:props": { @@ -763,7 +763,7 @@ }, { "key": "Name", - "value": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet3" + "value": "cdk-ec2-machine-image-cached/Vpc/PrivateSubnet3" } ], "vpcId": { @@ -778,7 +778,7 @@ }, "Acl": { "id": "Acl", - "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet3/Acl", + "path": "cdk-ec2-machine-image-cached/Vpc/PrivateSubnet3/Acl", "constructInfo": { "fqn": "aws-cdk-lib.Resource", "version": "0.0.0" @@ -786,14 +786,14 @@ }, "RouteTable": { "id": "RouteTable", - "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet3/RouteTable", + "path": "cdk-ec2-machine-image-cached/Vpc/PrivateSubnet3/RouteTable", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", "aws:cdk:cloudformation:props": { "tags": [ { "key": "Name", - "value": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet3" + "value": "cdk-ec2-machine-image-cached/Vpc/PrivateSubnet3" } ], "vpcId": { @@ -808,7 +808,7 @@ }, "RouteTableAssociation": { "id": "RouteTableAssociation", - "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet3/RouteTableAssociation", + "path": "cdk-ec2-machine-image-cached/Vpc/PrivateSubnet3/RouteTableAssociation", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", "aws:cdk:cloudformation:props": { @@ -827,7 +827,7 @@ }, "DefaultRoute": { "id": "DefaultRoute", - "path": "integ-ec2-machine-image-cached-test/Vpc/PrivateSubnet3/DefaultRoute", + "path": "cdk-ec2-machine-image-cached/Vpc/PrivateSubnet3/DefaultRoute", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::Route", "aws:cdk:cloudformation:props": { @@ -853,14 +853,14 @@ }, "IGW": { "id": "IGW", - "path": "integ-ec2-machine-image-cached-test/Vpc/IGW", + "path": "cdk-ec2-machine-image-cached/Vpc/IGW", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::InternetGateway", "aws:cdk:cloudformation:props": { "tags": [ { "key": "Name", - "value": "integ-ec2-machine-image-cached-test/Vpc" + "value": "cdk-ec2-machine-image-cached/Vpc" } ] } @@ -872,7 +872,7 @@ }, "VPCGW": { "id": "VPCGW", - "path": "integ-ec2-machine-image-cached-test/Vpc/VPCGW", + "path": "cdk-ec2-machine-image-cached/Vpc/VPCGW", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::VPCGatewayAttachment", "aws:cdk:cloudformation:props": { @@ -897,19 +897,19 @@ }, "al2023Cached": { "id": "al2023Cached", - "path": "integ-ec2-machine-image-cached-test/al2023Cached", + "path": "cdk-ec2-machine-image-cached/al2023Cached", "children": { "InstanceSecurityGroup": { "id": "InstanceSecurityGroup", - "path": "integ-ec2-machine-image-cached-test/al2023Cached/InstanceSecurityGroup", + "path": "cdk-ec2-machine-image-cached/al2023Cached/InstanceSecurityGroup", "children": { "Resource": { "id": "Resource", - "path": "integ-ec2-machine-image-cached-test/al2023Cached/InstanceSecurityGroup/Resource", + "path": "cdk-ec2-machine-image-cached/al2023Cached/InstanceSecurityGroup/Resource", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::SecurityGroup", "aws:cdk:cloudformation:props": { - "groupDescription": "integ-ec2-machine-image-cached-test/al2023Cached/InstanceSecurityGroup", + "groupDescription": "cdk-ec2-machine-image-cached/al2023Cached/InstanceSecurityGroup", "securityGroupEgress": [ { "cidrIp": "0.0.0.0/0", @@ -920,7 +920,7 @@ "tags": [ { "key": "Name", - "value": "integ-ec2-machine-image-cached-test/al2023Cached" + "value": "cdk-ec2-machine-image-cached/al2023Cached" } ], "vpcId": { @@ -941,11 +941,11 @@ }, "InstanceRole": { "id": "InstanceRole", - "path": "integ-ec2-machine-image-cached-test/al2023Cached/InstanceRole", + "path": "cdk-ec2-machine-image-cached/al2023Cached/InstanceRole", "children": { "ImportInstanceRole": { "id": "ImportInstanceRole", - "path": "integ-ec2-machine-image-cached-test/al2023Cached/InstanceRole/ImportInstanceRole", + "path": "cdk-ec2-machine-image-cached/al2023Cached/InstanceRole/ImportInstanceRole", "constructInfo": { "fqn": "aws-cdk-lib.Resource", "version": "0.0.0" @@ -953,7 +953,7 @@ }, "Resource": { "id": "Resource", - "path": "integ-ec2-machine-image-cached-test/al2023Cached/InstanceRole/Resource", + "path": "cdk-ec2-machine-image-cached/al2023Cached/InstanceRole/Resource", "attributes": { "aws:cdk:cloudformation:type": "AWS::IAM::Role", "aws:cdk:cloudformation:props": { @@ -972,7 +972,7 @@ "tags": [ { "key": "Name", - "value": "integ-ec2-machine-image-cached-test/al2023Cached" + "value": "cdk-ec2-machine-image-cached/al2023Cached" } ] } @@ -990,7 +990,7 @@ }, "InstanceProfile": { "id": "InstanceProfile", - "path": "integ-ec2-machine-image-cached-test/al2023Cached/InstanceProfile", + "path": "cdk-ec2-machine-image-cached/al2023Cached/InstanceProfile", "attributes": { "aws:cdk:cloudformation:type": "AWS::IAM::InstanceProfile", "aws:cdk:cloudformation:props": { @@ -1008,7 +1008,7 @@ }, "Resource": { "id": "Resource", - "path": "integ-ec2-machine-image-cached-test/al2023Cached/Resource", + "path": "cdk-ec2-machine-image-cached/al2023Cached/Resource", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::Instance", "aws:cdk:cloudformation:props": { @@ -1032,7 +1032,7 @@ "tags": [ { "key": "Name", - "value": "integ-ec2-machine-image-cached-test/al2023Cached" + "value": "cdk-ec2-machine-image-cached/al2023Cached" } ], "userData": { @@ -1053,19 +1053,19 @@ }, "al2023CachedScope": { "id": "al2023CachedScope", - "path": "integ-ec2-machine-image-cached-test/al2023CachedScope", + "path": "cdk-ec2-machine-image-cached/al2023CachedScope", "children": { "InstanceSecurityGroup": { "id": "InstanceSecurityGroup", - "path": "integ-ec2-machine-image-cached-test/al2023CachedScope/InstanceSecurityGroup", + "path": "cdk-ec2-machine-image-cached/al2023CachedScope/InstanceSecurityGroup", "children": { "Resource": { "id": "Resource", - "path": "integ-ec2-machine-image-cached-test/al2023CachedScope/InstanceSecurityGroup/Resource", + "path": "cdk-ec2-machine-image-cached/al2023CachedScope/InstanceSecurityGroup/Resource", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::SecurityGroup", "aws:cdk:cloudformation:props": { - "groupDescription": "integ-ec2-machine-image-cached-test/al2023CachedScope/InstanceSecurityGroup", + "groupDescription": "cdk-ec2-machine-image-cached/al2023CachedScope/InstanceSecurityGroup", "securityGroupEgress": [ { "cidrIp": "0.0.0.0/0", @@ -1076,7 +1076,7 @@ "tags": [ { "key": "Name", - "value": "integ-ec2-machine-image-cached-test/al2023CachedScope" + "value": "cdk-ec2-machine-image-cached/al2023CachedScope" } ], "vpcId": { @@ -1097,11 +1097,11 @@ }, "InstanceRole": { "id": "InstanceRole", - "path": "integ-ec2-machine-image-cached-test/al2023CachedScope/InstanceRole", + "path": "cdk-ec2-machine-image-cached/al2023CachedScope/InstanceRole", "children": { "ImportInstanceRole": { "id": "ImportInstanceRole", - "path": "integ-ec2-machine-image-cached-test/al2023CachedScope/InstanceRole/ImportInstanceRole", + "path": "cdk-ec2-machine-image-cached/al2023CachedScope/InstanceRole/ImportInstanceRole", "constructInfo": { "fqn": "aws-cdk-lib.Resource", "version": "0.0.0" @@ -1109,7 +1109,7 @@ }, "Resource": { "id": "Resource", - "path": "integ-ec2-machine-image-cached-test/al2023CachedScope/InstanceRole/Resource", + "path": "cdk-ec2-machine-image-cached/al2023CachedScope/InstanceRole/Resource", "attributes": { "aws:cdk:cloudformation:type": "AWS::IAM::Role", "aws:cdk:cloudformation:props": { @@ -1128,7 +1128,7 @@ "tags": [ { "key": "Name", - "value": "integ-ec2-machine-image-cached-test/al2023CachedScope" + "value": "cdk-ec2-machine-image-cached/al2023CachedScope" } ] } @@ -1146,7 +1146,7 @@ }, "InstanceProfile": { "id": "InstanceProfile", - "path": "integ-ec2-machine-image-cached-test/al2023CachedScope/InstanceProfile", + "path": "cdk-ec2-machine-image-cached/al2023CachedScope/InstanceProfile", "attributes": { "aws:cdk:cloudformation:type": "AWS::IAM::InstanceProfile", "aws:cdk:cloudformation:props": { @@ -1164,7 +1164,7 @@ }, "Resource": { "id": "Resource", - "path": "integ-ec2-machine-image-cached-test/al2023CachedScope/Resource", + "path": "cdk-ec2-machine-image-cached/al2023CachedScope/Resource", "attributes": { "aws:cdk:cloudformation:type": "AWS::EC2::Instance", "aws:cdk:cloudformation:props": { @@ -1188,7 +1188,7 @@ "tags": [ { "key": "Name", - "value": "integ-ec2-machine-image-cached-test/al2023CachedScope" + "value": "cdk-ec2-machine-image-cached/al2023CachedScope" } ], "userData": { @@ -1209,7 +1209,7 @@ }, "BootstrapVersion": { "id": "BootstrapVersion", - "path": "integ-ec2-machine-image-cached-test/BootstrapVersion", + "path": "cdk-ec2-machine-image-cached/BootstrapVersion", "constructInfo": { "fqn": "aws-cdk-lib.CfnParameter", "version": "0.0.0" @@ -1217,7 +1217,7 @@ }, "CheckBootstrapVersion": { "id": "CheckBootstrapVersion", - "path": "integ-ec2-machine-image-cached-test/CheckBootstrapVersion", + "path": "cdk-ec2-machine-image-cached/CheckBootstrapVersion", "constructInfo": { "fqn": "aws-cdk-lib.CfnRule", "version": "0.0.0" @@ -1229,17 +1229,17 @@ "version": "0.0.0" } }, - "integ-test": { - "id": "integ-test", - "path": "integ-test", + "integ-ec2-machine-image-cached": { + "id": "integ-ec2-machine-image-cached", + "path": "integ-ec2-machine-image-cached", "children": { "DefaultTest": { "id": "DefaultTest", - "path": "integ-test/DefaultTest", + "path": "integ-ec2-machine-image-cached/DefaultTest", "children": { "Default": { "id": "Default", - "path": "integ-test/DefaultTest/Default", + "path": "integ-ec2-machine-image-cached/DefaultTest/Default", "constructInfo": { "fqn": "constructs.Construct", "version": "10.2.70" @@ -1247,11 +1247,11 @@ }, "DeployAssert": { "id": "DeployAssert", - "path": "integ-test/DefaultTest/DeployAssert", + "path": "integ-ec2-machine-image-cached/DefaultTest/DeployAssert", "children": { "BootstrapVersion": { "id": "BootstrapVersion", - "path": "integ-test/DefaultTest/DeployAssert/BootstrapVersion", + "path": "integ-ec2-machine-image-cached/DefaultTest/DeployAssert/BootstrapVersion", "constructInfo": { "fqn": "aws-cdk-lib.CfnParameter", "version": "0.0.0" @@ -1259,7 +1259,7 @@ }, "CheckBootstrapVersion": { "id": "CheckBootstrapVersion", - "path": "integ-test/DefaultTest/DeployAssert/CheckBootstrapVersion", + "path": "integ-ec2-machine-image-cached/DefaultTest/DeployAssert/CheckBootstrapVersion", "constructInfo": { "fqn": "aws-cdk-lib.CfnRule", "version": "0.0.0" diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.ts index 119688dba9103..0439c1f11f40a 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.machine-image-cached.ts @@ -45,7 +45,9 @@ export class TestCase extends Stack { } const app = new App(); -new IntegTest(app, 'integ-test', { - testCases: [new TestCase(app, 'integ-ec2-machine-image-cached-test', { env })], +const stack = new TestCase(app, 'cdk-ec2-machine-image-cached', { env }); +new IntegTest(app, 'integ-ec2-machine-image-cached', { + testCases: [stack], enableLookups: true, }); +app.synth(); From f5324ac34f9dad0653a041aac76860f320181efc Mon Sep 17 00:00:00 2001 From: Jonathan Romano Date: Thu, 16 Nov 2023 03:56:23 +0000 Subject: [PATCH 11/22] Streamline info in README --- packages/aws-cdk-lib/aws-ec2/README.md | 9 ++++----- .../aws-cdk-lib/aws-elasticloadbalancingv2/README.md | 7 +++---- packages/aws-cdk-lib/aws-kms/README.md | 7 +++---- packages/aws-cdk-lib/aws-route53/README.md | 7 +++---- packages/aws-cdk-lib/aws-ssm/README.md | 7 +++---- 5 files changed, 16 insertions(+), 21 deletions(-) diff --git a/packages/aws-cdk-lib/aws-ec2/README.md b/packages/aws-cdk-lib/aws-ec2/README.md index 950a9b091625a..823e67c1fa278 100644 --- a/packages/aws-cdk-lib/aws-ec2/README.md +++ b/packages/aws-cdk-lib/aws-ec2/README.md @@ -504,10 +504,9 @@ The result of the `Vpc.fromLookup()` operation will be written to a file called `cdk.context.json`. You must commit this file to source control so that the lookup values are available in non-privileged environments such as CI build steps, and to ensure your template builds are repeatable. -If you do not want the value of the context variable to be global (ie, having the same -value returned any time you call `fromLookup` across your entire app), -you can set the `additionalCacheKey` argument (eg, to `this.node.path` to tie it -to the scope of the current construct) +To customize the cache key use the `additionalCacheKey` parameter. +This can be useful if you want to scope the context variable to a construct +(eg, using `additionalCacheKey: this.node.path`). Here's how `Vpc.fromLookup()` can be used: @@ -748,7 +747,7 @@ If the security group ID is known and configuration details are unknown, use met const sg = ec2.SecurityGroup.fromLookupById(this, 'SecurityGroupLookup', 'sg-1234'); ``` -The result of `SecurityGroup.fromLookupByName` and `SecurityGroup.fromLookupById` operations will be written to a file called `cdk.context.json`. You must commit this file to source control so that the lookup values are available in non-privileged environments such as CI build steps, and to ensure your template builds are repeatable. If you do not want the value of the context variable to be global (ie, having the same value returned any time you call `fromLookup` across your entire app), you can set the `additionalCacheKey` argument (eg, to `this.node.path` to tie it to the scope of the current construct) +The result of `SecurityGroup.fromLookupByName` and `SecurityGroup.fromLookupById` operations will be written to a file called `cdk.context.json`. You must commit this file to source control so that the lookup values are available in non-privileged environments such as CI build steps, and to ensure your template builds are repeatable. To customize the cache key use the `additionalCacheKey` parameter. This can be useful if you want to scope the context variable to a construct (eg, using `additionalCacheKey: this.node.path`). ### Cross Stack Connections diff --git a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/README.md b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/README.md index 27f79df0ebdcc..7ccf25aa5b3e8 100644 --- a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/README.md +++ b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/README.md @@ -523,10 +523,9 @@ The result of a `fromLookup()` operation will be written to a file called `cdk.context.json`. You must commit this file to source control so that the lookup values are available in non-privileged environments such as CI build steps, and to ensure your template builds are repeatable. -If you do not want the value of the context variable to be global (ie, having the same -value returned any time you call `fromLookup` across your entire app), -you can set the `additionalCacheKey` argument (eg, to `this.node.path` to tie it -to the scope of the current construct) +To customize the cache key use the `additionalCacheKey` parameter. +This can be useful if you want to scope the context variable to a construct +(eg, using `additionalCacheKey: this.node.path`). ### Load Balancer lookup options diff --git a/packages/aws-cdk-lib/aws-kms/README.md b/packages/aws-cdk-lib/aws-kms/README.md index 893aa48620cee..23fc83c7befa0 100644 --- a/packages/aws-cdk-lib/aws-kms/README.md +++ b/packages/aws-cdk-lib/aws-kms/README.md @@ -95,10 +95,9 @@ The result of the `Key.fromLookup()` operation will be written to a file called `cdk.context.json`. You must commit this file to source control so that the lookup values are available in non-privileged environments such as CI build steps, and to ensure your template builds are repeatable. -If you do not want the value of the context variable to be global (ie, having the same -value returned any time you call `fromLookup` across your entire app), -you can set the `additionalCacheKey` argument (eg, to `this.node.path` to tie it -to the scope of the current construct) +To customize the cache key use the `additionalCacheKey` parameter. +This can be useful if you want to scope the context variable to a construct +(eg, using `additionalCacheKey: this.node.path`). Here's how `Key.fromLookup()` can be used: diff --git a/packages/aws-cdk-lib/aws-route53/README.md b/packages/aws-cdk-lib/aws-route53/README.md index f6e8accef21d2..a9ecf39a51b2d 100644 --- a/packages/aws-cdk-lib/aws-route53/README.md +++ b/packages/aws-cdk-lib/aws-route53/README.md @@ -251,10 +251,9 @@ The result of the `HostedZone.fromLookup()` operation will be written to a file called `cdk.context.json`. You must commit this file to source control so that the lookup values are available in non-privileged environments such as CI build steps, and to ensure your template builds are repeatable. -If you do not want the value of the context variable to be global (ie, having the same -value returned any time you call `fromLookup` across your entire app), -you can set the `additionalCacheKey` argument (eg, to `this.node.path` to tie it -to the scope of the current construct) +To customize the cache key use the `additionalCacheKey` parameter. +This can be useful if you want to scope the context variable to a construct +(eg, using `additionalCacheKey: this.node.path`). `HostedZone.fromLookup` requires an environment to be configured. Check out the [documentation](https://docs.aws.amazon.com/cdk/latest/guide/environments.html) for more documentation and examples. CDK diff --git a/packages/aws-cdk-lib/aws-ssm/README.md b/packages/aws-cdk-lib/aws-ssm/README.md index cdd401d3f48f3..ba4b0da9f7e66 100644 --- a/packages/aws-cdk-lib/aws-ssm/README.md +++ b/packages/aws-cdk-lib/aws-ssm/README.md @@ -62,10 +62,9 @@ The result of the `StringParameter.valueFromLookup()` operation will be written called `cdk.context.json`. You must commit this file to source control so that the lookup values are available in non-privileged environments such as CI build steps, and to ensure your template builds are repeatable. -If you do not want the key of the context variable to be global -(ie, having the same value returned any time you call `fromLookup` across your entire app), -you can set the `additionalCacheKey` argument (eg, to `this.node.path` to tie it -to the scope of the current construct) +To customize the cache key use the `additionalCacheKey` parameter. +This can be useful if you want to scope the context variable to a construct +(eg, using `additionalCacheKey: this.node.path`). When using `valueFromLookup` an initial value of 'dummy-value-for-${parameterName}' From bc36cabf1cfb569b754665382a4939dac8522dd0 Mon Sep 17 00:00:00 2001 From: Jonathan Romano Date: Thu, 16 Nov 2023 04:02:58 +0000 Subject: [PATCH 12/22] Correct comment --- packages/aws-cdk-lib/aws-ec2/lib/machine-image/machine-image.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/machine-image.ts b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/machine-image.ts index fe8729b955c26..c4abe9b29811d 100644 --- a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/machine-image.ts +++ b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/machine-image.ts @@ -667,7 +667,7 @@ export class GenericWindowsImage implements IMachineImage { * will be used on future runs. To refresh the AMI lookup, you will have to * evict the value from the cache using the `cdk context` command. See * https://docs.aws.amazon.com/cdk/latest/guide/context.html for more information. - * If `props.additionalCacheKey` is true, the context key use that value as a discriminator + * If `props.additionalCacheKey` is set, the context key uses that value as a discriminator * rather than the cached value being global across all lookups */ export class LookupMachineImage implements IMachineImage { From bf503e85fd44f530431fac2709e8f4ea2cb03a18 Mon Sep 17 00:00:00 2001 From: Jonathan Romano Date: Thu, 16 Nov 2023 04:14:28 +0000 Subject: [PATCH 13/22] Simplify references from props --- packages/aws-cdk-lib/aws-ec2/lib/machine-image/common.ts | 4 +--- .../aws-cdk-lib/aws-ec2/lib/machine-image/machine-image.ts | 5 +---- packages/aws-cdk-lib/aws-ecs/lib/amis.ts | 6 +++--- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/common.ts b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/common.ts index c236000e95141..d08121fadb60f 100644 --- a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/common.ts +++ b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/common.ts @@ -72,14 +72,12 @@ export interface AmazonLinuxImageSsmParameterBaseProps extends AmazonLinuxImageS export abstract class AmazonLinuxImageSsmParameterBase implements IMachineImage { private readonly cachedInContext: boolean; - private readonly additionalCacheKey?: string; constructor(private readonly props: AmazonLinuxImageSsmParameterBaseProps) { this.cachedInContext = this.props.cachedInContext ?? true; - if (props.additionalCacheKey) this.additionalCacheKey = this.props.additionalCacheKey; } getImage(scope: Construct): MachineImageConfig { - const imageId = lookupImage(scope, this.cachedInContext, this.props.parameterName, this.additionalCacheKey); + const imageId = lookupImage(scope, this.cachedInContext, this.props.parameterName, this.props.additionalCacheKey); const osType = OperatingSystemType.LINUX; return { diff --git a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/machine-image.ts b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/machine-image.ts index c4abe9b29811d..0976d4f005374 100644 --- a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/machine-image.ts +++ b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/machine-image.ts @@ -523,20 +523,17 @@ export class AmazonLinuxImage extends GenericSSMParameterImage { private readonly cachedInContext: boolean; - private readonly additionalCacheKey?: string; - constructor(private readonly props: AmazonLinuxImageProps = {}) { super(AmazonLinuxImage.ssmParameterName(props), OperatingSystemType.LINUX, props.userData); this.cachedInContext = props.cachedInContext ?? false; - if (props.additionalCacheKey) this.additionalCacheKey = props.additionalCacheKey; } /** * Return the image to use in the given context */ public getImage(scope: Construct): MachineImageConfig { - const imageId = lookupImage(scope, this.cachedInContext, this.parameterName, this.additionalCacheKey); + const imageId = lookupImage(scope, this.cachedInContext, this.parameterName, this.props.additionalCacheKey); const osType = OperatingSystemType.LINUX; return { diff --git a/packages/aws-cdk-lib/aws-ecs/lib/amis.ts b/packages/aws-cdk-lib/aws-ecs/lib/amis.ts index 5852b9440d597..e6181cce9766c 100644 --- a/packages/aws-cdk-lib/aws-ecs/lib/amis.ts +++ b/packages/aws-cdk-lib/aws-ecs/lib/amis.ts @@ -152,7 +152,7 @@ export class EcsOptimizedAmi implements ec2.IMachineImage { + (this.windowsVersion ? 'image_id' : 'recommended/image_id'); this.cachedInContext = props?.cachedInContext ?? false; - if (props?.additionalCacheKey) this.additionalCacheKey = props.additionalCacheKey; + this.additionalCacheKey = props?.additionalCacheKey; } /** @@ -274,7 +274,7 @@ export class EcsOptimizedImage implements ec2.IMachineImage { + (this.windowsVersion ? 'image_id' : 'recommended/image_id'); this.cachedInContext = props.cachedInContext ?? false; - if (props.additionalCacheKey) this.additionalCacheKey = props.additionalCacheKey; + this.additionalCacheKey = props.additionalCacheKey; } /** @@ -387,7 +387,7 @@ export class BottleRocketImage implements ec2.IMachineImage { this.amiParameterName = `/aws/service/bottlerocket/${this.variant}/${this.architecture}/latest/image_id`; this.cachedInContext = props.cachedInContext ?? false; - if (props.additionalCacheKey) this.additionalCacheKey = props.additionalCacheKey; + this.additionalCacheKey = props.additionalCacheKey; } /** From b783667079579c5a10242eec8a5461a76ce0eb44 Mon Sep 17 00:00:00 2001 From: Jonathan Romano Date: Thu, 16 Nov 2023 04:14:54 +0000 Subject: [PATCH 14/22] No need to spread --- packages/aws-cdk-lib/aws-ec2/lib/security-group.ts | 2 +- packages/aws-cdk-lib/aws-ec2/lib/vpc.ts | 2 +- packages/aws-cdk-lib/aws-kms/lib/key.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/aws-cdk-lib/aws-ec2/lib/security-group.ts b/packages/aws-cdk-lib/aws-ec2/lib/security-group.ts index 4bebd70f45b38..16ce0fb988064 100644 --- a/packages/aws-cdk-lib/aws-ec2/lib/security-group.ts +++ b/packages/aws-cdk-lib/aws-ec2/lib/security-group.ts @@ -444,7 +444,7 @@ export class SecurityGroup extends SecurityGroupBase { securityGroupId: options.securityGroupId, securityGroupName: options.securityGroupName, vpcId: options.vpc?.vpcId, - ...(options.additionalCacheKey ? { additionalCacheKey: options.additionalCacheKey } : {}), + additionalCacheKey: options.additionalCacheKey, }, dummyValue: { securityGroupId: 'sg-12345678', diff --git a/packages/aws-cdk-lib/aws-ec2/lib/vpc.ts b/packages/aws-cdk-lib/aws-ec2/lib/vpc.ts index bbd33cb6d4312..4eb21a61e3048 100644 --- a/packages/aws-cdk-lib/aws-ec2/lib/vpc.ts +++ b/packages/aws-cdk-lib/aws-ec2/lib/vpc.ts @@ -1292,7 +1292,7 @@ export class Vpc extends VpcBase { returnAsymmetricSubnets: true, returnVpnGateways: options.returnVpnGateways, subnetGroupNameTag: options.subnetGroupNameTag, - ...(options.additionalCacheKey ? { additionalCacheKey: options.additionalCacheKey } : {}), + additionalCacheKey: options.additionalCacheKey, } as cxschema.VpcContextQuery, dummyValue: undefined, }).value; diff --git a/packages/aws-cdk-lib/aws-kms/lib/key.ts b/packages/aws-cdk-lib/aws-kms/lib/key.ts index d4e123162490d..878f0f39f1120 100644 --- a/packages/aws-cdk-lib/aws-kms/lib/key.ts +++ b/packages/aws-cdk-lib/aws-kms/lib/key.ts @@ -648,7 +648,7 @@ export class Key extends KeyBase { provider: cxschema.ContextProvider.KEY_PROVIDER, props: { aliasName: options.aliasName, - ...(options.additionalCacheKey ? { additionalCacheKey: options.additionalCacheKey } : {}), + additionalCacheKey: options.additionalCacheKey, } as cxschema.KeyContextQuery, dummyValue: { keyId: '1234abcd-12ab-34cd-56ef-1234567890ab', From 0b3980985f5ec0eb54e823337d6cf77301370691 Mon Sep 17 00:00:00 2001 From: Jonathan Romano Date: Thu, 16 Nov 2023 04:17:02 +0000 Subject: [PATCH 15/22] Revert format change --- packages/aws-cdk-lib/core/lib/context-provider.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/aws-cdk-lib/core/lib/context-provider.ts b/packages/aws-cdk-lib/core/lib/context-provider.ts index 2bbaf7336feed..d0e79fc02c7fb 100644 --- a/packages/aws-cdk-lib/core/lib/context-provider.ts +++ b/packages/aws-cdk-lib/core/lib/context-provider.ts @@ -67,10 +67,9 @@ export class ContextProvider { public static getKey(scope: Construct, options: GetContextKeyOptions): GetContextKeyResult { const stack = Stack.of(scope); - const props = { - ...((options.includeEnvironment ?? true) ? { account: stack.account, region: stack.region } : {}), - ...options.props, - }; + const props = options.includeEnvironment ?? true + ? { account: stack.account, region: stack.region, ...options.props } + : (options.props ?? {}); if (Object.values(props).find(x => Token.isUnresolved(x))) { throw new Error( From 0e6cfb5fdf425369845d5e7837f3be8148867a83 Mon Sep 17 00:00:00 2001 From: Jonathan Romano Date: Thu, 16 Nov 2023 04:22:59 +0000 Subject: [PATCH 16/22] Revert function signature change --- packages/aws-cdk-lib/aws-ec2/lib/machine-image/utils.ts | 2 +- packages/aws-cdk-lib/aws-ecs/lib/amis.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/utils.ts b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/utils.ts index 9b782b2dedfd5..34c96d3ebbc93 100644 --- a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/utils.ts +++ b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/utils.ts @@ -1,7 +1,7 @@ import { Construct } from 'constructs'; import * as ssm from '../../../aws-ssm'; -export function lookupImage(scope: Construct, cachedInContext: boolean, parameterName: string, additionalCacheKey?: string) { +export function lookupImage(scope: Construct, cachedInContext: boolean | undefined, parameterName: string, additionalCacheKey?: string) { return cachedInContext ? ssm.StringParameter.valueFromLookup(scope, parameterName, additionalCacheKey) : ssm.StringParameter.valueForTypedStringParameterV2(scope, parameterName, ssm.ParameterValueType.AWS_EC2_IMAGE_ID); diff --git a/packages/aws-cdk-lib/aws-ecs/lib/amis.ts b/packages/aws-cdk-lib/aws-ecs/lib/amis.ts index e6181cce9766c..ebf48bd982009 100644 --- a/packages/aws-cdk-lib/aws-ecs/lib/amis.ts +++ b/packages/aws-cdk-lib/aws-ecs/lib/amis.ts @@ -410,7 +410,7 @@ Object.defineProperty(BottleRocketImage.prototype, BR_IMAGE_SYMBOL, { writable: false, }); -function lookupImage(scope: Construct, cachedInContext: boolean, parameterName: string, additionalCacheKey?: string) { +function lookupImage(scope: Construct, cachedInContext: boolean | undefined, parameterName: string, additionalCacheKey?: string) { return cachedInContext ? ssm.StringParameter.valueFromLookup(scope, parameterName, additionalCacheKey) : ssm.StringParameter.valueForTypedStringParameterV2(scope, parameterName, ssm.ParameterValueType.AWS_EC2_IMAGE_ID); From 7dc950159b3bfadff919ba2de5f5971cfa5b9fd8 Mon Sep 17 00:00:00 2001 From: Jonathan Romano Date: Thu, 16 Nov 2023 04:42:06 +0000 Subject: [PATCH 17/22] Remove more spreads, add to interfaces --- .../lib/shared/base-listener.ts | 2 +- .../lib/shared/base-load-balancer.ts | 2 +- .../lib/cloud-assembly/context-queries.ts | 30 +++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-listener.ts b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-listener.ts index eecf881cd7530..265f14f065e42 100644 --- a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-listener.ts +++ b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-listener.ts @@ -103,7 +103,7 @@ export abstract class BaseListener extends Resource implements IListener { loadBalancerArn: options.userOptions.loadBalancerArn, loadBalancerTags: cxschemaTags, loadBalancerType: options.loadBalancerType, - ...(options.userOptions.additionalCacheKey ? { additionalCacheKey: options.userOptions.additionalCacheKey } : {}), + additionalCacheKey: options.userOptions.additionalCacheKey, } as cxschema.LoadBalancerListenerContextQuery, dummyValue: { // eslint-disable-next-line @aws-cdk/no-literal-partition diff --git a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts index aa68215e225b6..36888ddf35578 100644 --- a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts +++ b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts @@ -136,7 +136,7 @@ export abstract class BaseLoadBalancer extends Resource { loadBalancerArn: options.userOptions.loadBalancerArn, loadBalancerTags: cxschemaTags, loadBalancerType: options.loadBalancerType, - ...(options.userOptions.additionalCacheKey ? { additionalCacheKey: options.userOptions.additionalCacheKey } : {}), + additionalCacheKey: options.userOptions.additionalCacheKey, } as cxschema.LoadBalancerContextQuery, dummyValue: { ipAddressType: cxapi.LoadBalancerIpAddressType.DUAL_STACK, diff --git a/packages/aws-cdk-lib/cloud-assembly-schema/lib/cloud-assembly/context-queries.ts b/packages/aws-cdk-lib/cloud-assembly-schema/lib/cloud-assembly/context-queries.ts index bd35d023dfe69..35c0e516fdc9f 100644 --- a/packages/aws-cdk-lib/cloud-assembly-schema/lib/cloud-assembly/context-queries.ts +++ b/packages/aws-cdk-lib/cloud-assembly-schema/lib/cloud-assembly/context-queries.ts @@ -245,6 +245,12 @@ export interface VpcContextQuery { * @default true */ readonly returnVpnGateways?: boolean; + + /** + * When the vpc is cached in cdk.context.json, adds an additional discriminator to the + * cache key so that separate lookups with the same parameters can have separate cache lifecycles + */ + readonly additionalCacheKey?: string; } /** @@ -331,6 +337,12 @@ export interface LoadBalancerContextQuery extends LoadBalancerFilter { * @default - None */ readonly lookupRoleArn?: string; + + /** + * When the load balancer is cached in cdk.context.json, adds an additional discriminator to the + * cache key so that separate lookups with the same parameters can have separate cache lifecycles + */ + readonly additionalCacheKey?: string; } /** @@ -406,6 +418,12 @@ export interface LoadBalancerListenerContextQuery extends LoadBalancerFilter { * @default - does not filter by a listener port */ readonly listenerPort?: number; + + /** + * When listener is cached in cdk.context.json, adds an additional discriminator to the + * cache key so that separate lookups with the same parameters can have separate cache lifecycles + */ + readonly additionalCacheKey?: string; } /** @@ -449,6 +467,12 @@ export interface SecurityGroupContextQuery { * @default - None */ readonly vpcId?: string; + + /** + * When the security group is cached in cdk.context.json, adds an additional discriminator to the + * cache key so that separate lookups with the same parameters can have separate cache lifecycles + */ + readonly additionalCacheKey?: string; } /** @@ -476,6 +500,12 @@ export interface KeyContextQuery { * Alias name used to search the Key */ readonly aliasName: string; + + /** + * When the key is cached in cdk.context.json, adds an additional discriminator to the + * cache key so that separate lookups with the same parameters can have separate cache lifecycles + */ + readonly additionalCacheKey?: string; } /** From f7bcd97c2674dcda508ff9b97be2a78ec51f0f15 Mon Sep 17 00:00:00 2001 From: Jonathan Romano Date: Wed, 15 Nov 2023 23:43:21 -0500 Subject: [PATCH 18/22] Fix unit test --- .../aws-route53/test/hosted-zone-provider.test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/aws-cdk-lib/aws-route53/test/hosted-zone-provider.test.ts b/packages/aws-cdk-lib/aws-route53/test/hosted-zone-provider.test.ts index 085204e50b872..a0b355a15b322 100644 --- a/packages/aws-cdk-lib/aws-route53/test/hosted-zone-provider.test.ts +++ b/packages/aws-cdk-lib/aws-route53/test/hosted-zone-provider.test.ts @@ -41,7 +41,7 @@ describe('hosted zone provider', () => { expect(zoneRef.hostedZoneId).toEqual(fakeZoneId); }); - test('HostedZoneProvider will return context values if available when linked to scope', () => { + test('HostedZoneProvider will return context values if available', () => { // GIVEN const app = new cdk.App(); const stack = new cdk.Stack(app, 'TestStack', { @@ -82,15 +82,15 @@ describe('hosted zone provider', () => { }); - test('HostedZoneProvider will return context values if available', () => { + test('HostedZoneProvider will return context values if available with additional cache key', () => { // GIVEN const app = new cdk.App(); const stack = new cdk.Stack(app, 'TestStack', { env: { account: '12345', region: 'us-east-1' }, }); - const filter = { domainName: 'test.com' }; + const filter = { domainName: 'test.com', additionalCacheKey: 'cacheKey' }; - HostedZone.fromLookup(stack, 'Ref', filter, true); + HostedZone.fromLookup(stack, 'Ref', filter); const assembly = app.synth().getStackArtifact(stack.artifactId); const missing = assembly.assembly.manifest.missing!; @@ -114,7 +114,7 @@ describe('hosted zone provider', () => { stack2.node.setContext(missing[0].key, fakeZone); // WHEN - const zoneRef = HostedZone.fromLookup(stack2, 'MyZoneProvider', filter, true); + const zoneRef = HostedZone.fromLookup(stack2, 'MyZoneProvider', filter); // THEN expect(zoneRef.hostedZoneId).toEqual(fakeZoneId); From 8c508ab0f7c58996544cc7a9056cff480dd7a30e Mon Sep 17 00:00:00 2001 From: Jonathan Romano Date: Thu, 16 Nov 2023 05:02:28 +0000 Subject: [PATCH 19/22] update schema --- .../schema/cloud-assembly.schema.json | 32 +++++++++++++++---- .../schema/cloud-assembly.version.json | 2 +- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/packages/aws-cdk-lib/cloud-assembly-schema/schema/cloud-assembly.schema.json b/packages/aws-cdk-lib/cloud-assembly-schema/schema/cloud-assembly.schema.json index ada87b31af985..c816d01810515 100644 --- a/packages/aws-cdk-lib/cloud-assembly-schema/schema/cloud-assembly.schema.json +++ b/packages/aws-cdk-lib/cloud-assembly-schema/schema/cloud-assembly.schema.json @@ -89,14 +89,14 @@ }, "ArtifactType": { "description": "Type of cloud artifact.", + "type": "string", "enum": [ "aws:cloudformation:stack", "cdk:asset-manifest", "cdk:cloud-assembly", "cdk:tree", "none" - ], - "type": "string" + ] }, "MetadataEntry": { "description": "A metadata entry in a cloud assembly artifact.", @@ -488,6 +488,7 @@ }, "ContextProvider": { "description": "Identifier for the context provider", + "type": "string", "enum": [ "ami", "availability-zones", @@ -500,8 +501,7 @@ "security-group", "ssm", "vpc-provider" - ], - "type": "string" + ] }, "ContextQueryProperties": { "anyOf": [ @@ -700,6 +700,10 @@ "returnVpnGateways": { "description": "Whether to populate the `vpnGatewayId` field of the `VpcContextResponse`,\nwhich contains the VPN Gateway ID, if one exists. You can explicitly\ndisable this in order to avoid the lookup if you know the VPC does not have\na VPN Gatway attached. (Default true)", "type": "boolean" + }, + "additionalCacheKey": { + "description": "When the vpc is cached in cdk.context.json, adds an additional discriminator to the\ncache key so that separate lookups with the same parameters can have separate cache lifecycles", + "type": "string" } }, "required": [ @@ -751,6 +755,10 @@ "description": "The ARN of the role that should be used to look up the missing values (Default - None)", "type": "string" }, + "additionalCacheKey": { + "description": "When the load balancer is cached in cdk.context.json, adds an additional discriminator to the\ncache key so that separate lookups with the same parameters can have separate cache lifecycles", + "type": "string" + }, "loadBalancerType": { "$ref": "#/definitions/LoadBalancerType", "description": "Filter load balancers by their type" @@ -775,11 +783,11 @@ }, "LoadBalancerType": { "description": "Type of load balancer", + "type": "string", "enum": [ "application", "network" - ], - "type": "string" + ] }, "LoadBalancerListenerContextQuery": { "description": "Query input for looking up a load balancer listener", @@ -817,6 +825,10 @@ "description": "Filter listeners by listener port (Default - does not filter by a listener port)", "type": "number" }, + "additionalCacheKey": { + "description": "When listener is cached in cdk.context.json, adds an additional discriminator to the\ncache key so that separate lookups with the same parameters can have separate cache lifecycles", + "type": "string" + }, "loadBalancerType": { "$ref": "#/definitions/LoadBalancerType", "description": "Filter load balancers by their type" @@ -866,6 +878,10 @@ "vpcId": { "description": "VPC ID (Default - None)", "type": "string" + }, + "additionalCacheKey": { + "description": "When the security group is cached in cdk.context.json, adds an additional discriminator to the\ncache key so that separate lookups with the same parameters can have separate cache lifecycles", + "type": "string" } }, "required": [ @@ -892,6 +908,10 @@ "aliasName": { "description": "Alias name used to search the Key", "type": "string" + }, + "additionalCacheKey": { + "description": "When the key is cached in cdk.context.json, adds an additional discriminator to the\ncache key so that separate lookups with the same parameters can have separate cache lifecycles", + "type": "string" } }, "required": [ diff --git a/packages/aws-cdk-lib/cloud-assembly-schema/schema/cloud-assembly.version.json b/packages/aws-cdk-lib/cloud-assembly-schema/schema/cloud-assembly.version.json index 2313ab5436501..c5cb2e5de6344 100644 --- a/packages/aws-cdk-lib/cloud-assembly-schema/schema/cloud-assembly.version.json +++ b/packages/aws-cdk-lib/cloud-assembly-schema/schema/cloud-assembly.version.json @@ -1 +1 @@ -{"version":"34.0.0"} \ No newline at end of file +{"version":"35.0.0"} \ No newline at end of file From 8397e442ebfaaeb99e8a5affb9ad2d3be69486fa Mon Sep 17 00:00:00 2001 From: Jonathan Romano Date: Mon, 20 Nov 2023 11:06:33 -0500 Subject: [PATCH 20/22] Docs improvements --- packages/aws-cdk-lib/aws-ec2/README.md | 16 +++++++--- .../aws-ec2/lib/machine-image/common.ts | 5 +-- .../lib/machine-image/machine-image.ts | 19 ++++++----- .../aws-cdk-lib/aws-ec2/lib/security-group.ts | 5 +-- .../aws-cdk-lib/aws-ec2/lib/vpc-lookup.ts | 5 +-- packages/aws-cdk-lib/aws-ecs/README.md | 7 ++-- packages/aws-cdk-lib/aws-ecs/lib/amis.ts | 15 +++++---- .../aws-elasticloadbalancingv2/README.md | 25 ++++++++++++++- .../lib/shared/base-listener.ts | 5 +-- .../lib/shared/base-load-balancer.ts | 5 +-- packages/aws-cdk-lib/aws-kms/README.md | 1 + .../aws-cdk-lib/aws-kms/lib/key-lookup.ts | 5 +-- packages/aws-cdk-lib/aws-route53/README.md | 8 +++++ .../aws-route53/lib/hosted-zone-provider.ts | 5 +-- packages/aws-cdk-lib/aws-ssm/README.md | 4 +++ .../lib/cloud-assembly/context-queries.ts | 32 +++++++++++++------ .../schema/cloud-assembly.schema.json | 14 +++++--- .../schema/cloud-assembly.version.json | 2 +- 18 files changed, 124 insertions(+), 54 deletions(-) diff --git a/packages/aws-cdk-lib/aws-ec2/README.md b/packages/aws-cdk-lib/aws-ec2/README.md index 72ff0aeda3246..f8ae6c2c2b5c8 100644 --- a/packages/aws-cdk-lib/aws-ec2/README.md +++ b/packages/aws-cdk-lib/aws-ec2/README.md @@ -505,6 +505,7 @@ The result of the `Vpc.fromLookup()` operation will be written to a file called `cdk.context.json`. You must commit this file to source control so that the lookup values are available in non-privileged environments such as CI build steps, and to ensure your template builds are repeatable. + To customize the cache key use the `additionalCacheKey` parameter. This can be useful if you want to scope the context variable to a construct (eg, using `additionalCacheKey: this.node.path`). @@ -748,7 +749,13 @@ If the security group ID is known and configuration details are unknown, use met const sg = ec2.SecurityGroup.fromLookupById(this, 'SecurityGroupLookup', 'sg-1234'); ``` -The result of `SecurityGroup.fromLookupByName` and `SecurityGroup.fromLookupById` operations will be written to a file called `cdk.context.json`. You must commit this file to source control so that the lookup values are available in non-privileged environments such as CI build steps, and to ensure your template builds are repeatable. To customize the cache key use the `additionalCacheKey` parameter. This can be useful if you want to scope the context variable to a construct (eg, using `additionalCacheKey: this.node.path`). +The result of `SecurityGroup.fromLookupByName` and `SecurityGroup.fromLookupById` operations will be +written to a file called `cdk.context.json`. +You must commit this file to source control so that the lookup values are available in non-privileged +environments such as CI build steps, and to ensure your template builds are repeatable. + +To customize the cache key use the `additionalCacheKey` parameter. +This can be useful if you want to scope the context variable to a construct (eg, using `additionalCacheKey: this.node.path`). ### Cross Stack Connections @@ -836,10 +843,9 @@ examples of images you might want to use: > [Runtime Context](https://docs.aws.amazon.com/cdk/latest/guide/context.html) in the CDK > developer guide. > -> If you do not want the value of the context variable to be to be global -> (ie, having the same value returned any time you call `lookup` across your entire app), -> you can set the `additionalCacheKey` argument (eg, to `this.node.path` to tie it -> to the scope of the current construct) +> To customize the cache key use the `additionalCacheKey` parameter. +> This can be useful if you want to scope the context variable to a construct +> (eg, using `additionalCacheKey: this.node.path`). > > `MachineImage.genericLinux()`, `MachineImage.genericWindows()` will use `CfnMapping` in > an agnostic stack. diff --git a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/common.ts b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/common.ts index d08121fadb60f..8043c6923a48c 100644 --- a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/common.ts +++ b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/common.ts @@ -47,8 +47,9 @@ export interface AmazonLinuxImageSsmParameterBaseOptions { readonly cachedInContext?: boolean; /** - * When the image is cached in cdk.context.json, adds an additional discriminator to the - * cache key so that separate lookups with the same parameters can have separate cache lifecycles + * Adds an additional discriminator to the `cdk.context.json` cache key. + * + * @default - no additional cache key */ readonly additionalCacheKey?: string; diff --git a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/machine-image.ts b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/machine-image.ts index f8569f415ba17..faf45d3d6496a 100644 --- a/packages/aws-cdk-lib/aws-ec2/lib/machine-image/machine-image.ts +++ b/packages/aws-cdk-lib/aws-ec2/lib/machine-image/machine-image.ts @@ -303,8 +303,9 @@ export interface SsmParameterImageOptions { readonly cachedInContext?: boolean; /** - * When the image is cached in cdk.context.json, adds an additional discriminator to the - * cache key so that separate lookups with the same parameters can have separate cache lifecycles + * Adds an additional discriminator to the `cdk.context.json` cache key. + * + * @default - no additional cache key */ readonly additionalCacheKey?: string; @@ -467,8 +468,9 @@ export interface AmazonLinuxImageProps { readonly cachedInContext?: boolean; /** - * When the image is cached in cdk.context.json, adds an additional discriminator to the - * cache key so that separate lookups with the same parameters can have separate cache lifecycles + * Adds an additional discriminator to the `cdk.context.json` cache key. + * + * @default - no additional cache key */ readonly additionalCacheKey?: string; } @@ -679,7 +681,7 @@ export class GenericWindowsImage implements IMachineImage { * evict the value from the cache using the `cdk context` command. See * https://docs.aws.amazon.com/cdk/latest/guide/context.html for more information. * If `props.additionalCacheKey` is set, the context key uses that value as a discriminator - * rather than the cached value being global across all lookups + * rather than the cached value being global across all lookups. */ export class LookupMachineImage implements IMachineImage { constructor(private readonly props: LookupMachineImageProps) { @@ -704,7 +706,7 @@ export class LookupMachineImage implements IMachineImage { props: { owners: this.props.owners, filters, - ...(this.props.additionalCacheKey ? { additionalCacheKey: this.props.additionalCacheKey } : {}), + additionalCacheKey: this.props.additionalCacheKey, } as cxschema.AmiContextQuery, dummyValue: 'ami-1234', }).value as cxapi.AmiContextResponse; @@ -762,8 +764,9 @@ export interface LookupMachineImageProps { readonly userData?: UserData; /** - * When the image is cached in cdk.context.json, adds an additional discriminator to the - * cache key so that separate lookups with the same parameters can have separate cache lifecycles + * Adds an additional discriminator to the `cdk.context.json` cache key. + * + * @default - no additional cache key */ readonly additionalCacheKey?: string; } diff --git a/packages/aws-cdk-lib/aws-ec2/lib/security-group.ts b/packages/aws-cdk-lib/aws-ec2/lib/security-group.ts index 16ce0fb988064..5ef2108748b25 100644 --- a/packages/aws-cdk-lib/aws-ec2/lib/security-group.ts +++ b/packages/aws-cdk-lib/aws-ec2/lib/security-group.ts @@ -846,8 +846,9 @@ interface SecurityGroupLookupOptions { readonly vpc?: IVpc, /** - * When the security group is cached in cdk.context.json, adds an additional discriminator to the - * cache key so that separate lookups with the same parameters can have separate cache lifecycles + * Adds an additional discriminator to the `cdk.context.json` cache key. + * + * @default - no additional cache key */ readonly additionalCacheKey?: string; } diff --git a/packages/aws-cdk-lib/aws-ec2/lib/vpc-lookup.ts b/packages/aws-cdk-lib/aws-ec2/lib/vpc-lookup.ts index d84d4666ab986..5344d888e3305 100644 --- a/packages/aws-cdk-lib/aws-ec2/lib/vpc-lookup.ts +++ b/packages/aws-cdk-lib/aws-ec2/lib/vpc-lookup.ts @@ -77,8 +77,9 @@ export interface VpcLookupOptions { readonly ownerAccountId?: string; /** - * When the vpc is cached in cdk.context.json, adds an additional discriminator to the - * cache key so that separate lookups with the same parameters can have separate cache lifecycles + * Adds an additional discriminator to the `cdk.context.json` cache key. + * + * @default - no additional cache key */ readonly additionalCacheKey?: string; } diff --git a/packages/aws-cdk-lib/aws-ecs/README.md b/packages/aws-cdk-lib/aws-ecs/README.md index 186d98bb1adce..6c4ece769aa6f 100644 --- a/packages/aws-cdk-lib/aws-ecs/README.md +++ b/packages/aws-cdk-lib/aws-ecs/README.md @@ -156,10 +156,9 @@ const autoScalingGroup = new autoscaling.AutoScalingGroup(this, 'ASG', { }); ``` -If you do not want the value of the context variable to be global (ie, having the same -value returned any time you call `EcsOptimizedImage.amazonLinux` across your entire app), -you can set the `additionalCacheKey` argument (eg, to `this.node.path` to tie it -to the scope of the current construct) +To customize the cache key use the `additionalCacheKey` parameter. +This can be useful if you want to scope the context variable to a construct +(eg, using `additionalCacheKey: this.node.path`). ```ts declare const vpc: ec2.Vpc; diff --git a/packages/aws-cdk-lib/aws-ecs/lib/amis.ts b/packages/aws-cdk-lib/aws-ecs/lib/amis.ts index 40fb162f87c55..24df2fe67d378 100644 --- a/packages/aws-cdk-lib/aws-ecs/lib/amis.ts +++ b/packages/aws-cdk-lib/aws-ecs/lib/amis.ts @@ -94,8 +94,9 @@ export interface EcsOptimizedAmiProps { readonly cachedInContext?: boolean; /** - * When the image is cached in cdk.context.json, adds an additional discriminator to the - * cache key so that separate lookups with the same parameters can have separate cache lifecycles + * Adds an additional discriminator to the `cdk.context.json` cache key. + * + * @default - no additional cache key */ readonly additionalCacheKey?: string; } @@ -197,8 +198,9 @@ export interface EcsOptimizedImageOptions { readonly cachedInContext?: boolean; /** - * When the image is cached in cdk.context.json, adds an additional discriminator to the - * cache key so that separate lookups with the same parameters can have separate cache lifecycles + * Adds an additional discriminator to the `cdk.context.json` cache key. + * + * @default - no additional cache key */ readonly additionalCacheKey?: string; } @@ -359,8 +361,9 @@ export interface BottleRocketImageProps { readonly cachedInContext?: boolean; /** - * When the image is cached in cdk.context.json, adds an additional discriminator to the - * cache key so that separate lookups with the same parameters can have separate cache lifecycles + * Adds an additional discriminator to the `cdk.context.json` cache key. + * + * @default - no additional cache key */ readonly additionalCacheKey?: string; } diff --git a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/README.md b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/README.md index 7ccf25aa5b3e8..89c671fcdafb9 100644 --- a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/README.md +++ b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/README.md @@ -523,6 +523,7 @@ The result of a `fromLookup()` operation will be written to a file called `cdk.context.json`. You must commit this file to source control so that the lookup values are available in non-privileged environments such as CI build steps, and to ensure your template builds are repeatable. + To customize the cache key use the `additionalCacheKey` parameter. This can be useful if you want to scope the context variable to a construct (eg, using `additionalCacheKey: this.node.path`). @@ -556,7 +557,18 @@ const loadBalancer = elbv2.ApplicationLoadBalancer.fromLookup(this, 'ALB', { }); ``` -## Load Balancer Listener lookup options +**Look up a Application Load Balancer by ARN, customizing the cache key** + +```ts +const loadBalancer = elbv2.ApplicationLoadBalancer.fromLookup(this, 'ALB', { + loadBalancerArn: 'arn:aws:elasticloadbalancing:us-east-2:123456789012:loadbalancer/app/my-load-balancer/1234567890123456', + additionalCacheKey: this.node.path, +}); +``` + +** + +### Load Balancer Listener lookup options You may look up a load balancer listener by the following criteria: @@ -604,6 +616,17 @@ const listener = elbv2.NetworkListener.fromLookup(this, 'ALBListener', { }); ``` +**Look up a Listener by associated Load Balancer, Port, and Protocol** + +```ts +const listener = elbv2.ApplicationListener.fromLookup(this, 'ALBListener', { + loadBalancerArn: 'arn:aws:elasticloadbalancing:us-east-2:123456789012:loadbalancer/app/my-load-balancer/1234567890123456', + listenerProtocol: elbv2.ApplicationProtocol.HTTPS, + listenerPort: 443, + additionalCacheKey: this.node.path, +}); +``` + ## Metrics You may create metrics for Load Balancers and Target Groups through the `metrics` attribute: diff --git a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-listener.ts b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-listener.ts index 265f14f065e42..40aedb0be887a 100644 --- a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-listener.ts +++ b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-listener.ts @@ -29,8 +29,9 @@ export interface BaseListenerLookupOptions { readonly listenerPort?: number; /** - * When the listener is cached in cdk.context.json, adds an additional discriminator to the - * cache key so that separate lookups with the same parameters can have separate cache lifecycles + * Adds an additional discriminator to the `cdk.context.json` cache key. + * + * @default - no additional cache key */ readonly additionalCacheKey?: string; } diff --git a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts index 2c21514e78bef..c00bf7389454e 100644 --- a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts +++ b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts @@ -86,8 +86,9 @@ export interface BaseLoadBalancerLookupOptions { readonly loadBalancerTags?: Record; /** - * When the load balancer is cached in cdk.context.json, adds an additional discriminator to the - * cache key so that separate lookups with the same parameters can have separate cache lifecycles + * Adds an additional discriminator to the `cdk.context.json` cache key. + * + * @default - no additional cache key */ readonly additionalCacheKey?: string; } diff --git a/packages/aws-cdk-lib/aws-kms/README.md b/packages/aws-cdk-lib/aws-kms/README.md index 23fc83c7befa0..f4b2579f1fd8c 100644 --- a/packages/aws-cdk-lib/aws-kms/README.md +++ b/packages/aws-cdk-lib/aws-kms/README.md @@ -95,6 +95,7 @@ The result of the `Key.fromLookup()` operation will be written to a file called `cdk.context.json`. You must commit this file to source control so that the lookup values are available in non-privileged environments such as CI build steps, and to ensure your template builds are repeatable. + To customize the cache key use the `additionalCacheKey` parameter. This can be useful if you want to scope the context variable to a construct (eg, using `additionalCacheKey: this.node.path`). diff --git a/packages/aws-cdk-lib/aws-kms/lib/key-lookup.ts b/packages/aws-cdk-lib/aws-kms/lib/key-lookup.ts index 8f8ead5da98a3..ab79fe2bcd645 100644 --- a/packages/aws-cdk-lib/aws-kms/lib/key-lookup.ts +++ b/packages/aws-cdk-lib/aws-kms/lib/key-lookup.ts @@ -10,8 +10,9 @@ export interface KeyLookupOptions { readonly aliasName: string; /** - * When the key is cached in cdk.context.json, adds an additional discriminator to the - * cache key so that separate lookups with the same parameters can have separate cache lifecycles + * Adds an additional discriminator to the `cdk.context.json` cache key. + * + * @default - no additional cache key */ readonly additionalCacheKey?: string; } diff --git a/packages/aws-cdk-lib/aws-route53/README.md b/packages/aws-cdk-lib/aws-route53/README.md index a9ecf39a51b2d..414c5574aaa03 100644 --- a/packages/aws-cdk-lib/aws-route53/README.md +++ b/packages/aws-cdk-lib/aws-route53/README.md @@ -251,10 +251,18 @@ The result of the `HostedZone.fromLookup()` operation will be written to a file called `cdk.context.json`. You must commit this file to source control so that the lookup values are available in non-privileged environments such as CI build steps, and to ensure your template builds are repeatable. + To customize the cache key use the `additionalCacheKey` parameter. This can be useful if you want to scope the context variable to a construct (eg, using `additionalCacheKey: this.node.path`). +```ts +route53.HostedZone.fromLookup(this, 'MyZone', { + domainName: 'example.com', + additionalCacheKey: this.node.path, +}); +``` + `HostedZone.fromLookup` requires an environment to be configured. Check out the [documentation](https://docs.aws.amazon.com/cdk/latest/guide/environments.html) for more documentation and examples. CDK automatically looks into your `~/.aws/config` file for the `[default]` profile. diff --git a/packages/aws-cdk-lib/aws-route53/lib/hosted-zone-provider.ts b/packages/aws-cdk-lib/aws-route53/lib/hosted-zone-provider.ts index 00a2bb51e5bf9..4e9fcefff9373 100644 --- a/packages/aws-cdk-lib/aws-route53/lib/hosted-zone-provider.ts +++ b/packages/aws-cdk-lib/aws-route53/lib/hosted-zone-provider.ts @@ -25,8 +25,9 @@ export interface HostedZoneProviderProps { readonly vpcId?: string; /** - * When the hosted zone is cached in cdk.context.json, adds an additional discriminator to the - * cache key so that separate lookups with the same parameters can have separate cache lifecycles + * Adds an additional discriminator to the `cdk.context.json` cache key. + * + * @default - no additional cache key */ readonly additionalCacheKey?: string; } diff --git a/packages/aws-cdk-lib/aws-ssm/README.md b/packages/aws-cdk-lib/aws-ssm/README.md index ba4b0da9f7e66..cc421dcd90a02 100644 --- a/packages/aws-cdk-lib/aws-ssm/README.md +++ b/packages/aws-cdk-lib/aws-ssm/README.md @@ -62,10 +62,14 @@ The result of the `StringParameter.valueFromLookup()` operation will be written called `cdk.context.json`. You must commit this file to source control so that the lookup values are available in non-privileged environments such as CI build steps, and to ensure your template builds are repeatable. + To customize the cache key use the `additionalCacheKey` parameter. This can be useful if you want to scope the context variable to a construct (eg, using `additionalCacheKey: this.node.path`). +```ts +const stringValue = ssm.StringParameter.valueFromLookup(this, '/My/Public/Parameter', this.node.path); +``` When using `valueFromLookup` an initial value of 'dummy-value-for-${parameterName}' (`dummy-value-for-/My/Public/Parameter` in the above example) diff --git a/packages/aws-cdk-lib/cloud-assembly-schema/lib/cloud-assembly/context-queries.ts b/packages/aws-cdk-lib/cloud-assembly-schema/lib/cloud-assembly/context-queries.ts index 35c0e516fdc9f..b1975064dc755 100644 --- a/packages/aws-cdk-lib/cloud-assembly-schema/lib/cloud-assembly/context-queries.ts +++ b/packages/aws-cdk-lib/cloud-assembly-schema/lib/cloud-assembly/context-queries.ts @@ -92,6 +92,13 @@ export interface AmiContextQuery { * Filters to DescribeImages call */ readonly filters: {[key: string]: string[]}; + + /** + * Adds an additional discriminator to the `cdk.context.json` cache key. + * + * @default - no additional cache key + */ + readonly additionalCacheKey?: string; } /** @@ -247,8 +254,9 @@ export interface VpcContextQuery { readonly returnVpnGateways?: boolean; /** - * When the vpc is cached in cdk.context.json, adds an additional discriminator to the - * cache key so that separate lookups with the same parameters can have separate cache lifecycles + * Adds an additional discriminator to the `cdk.context.json` cache key. + * + * @default - no additional cache key */ readonly additionalCacheKey?: string; } @@ -339,8 +347,9 @@ export interface LoadBalancerContextQuery extends LoadBalancerFilter { readonly lookupRoleArn?: string; /** - * When the load balancer is cached in cdk.context.json, adds an additional discriminator to the - * cache key so that separate lookups with the same parameters can have separate cache lifecycles + * Adds an additional discriminator to the `cdk.context.json` cache key. + * + * @default - no additional cache key */ readonly additionalCacheKey?: string; } @@ -420,8 +429,9 @@ export interface LoadBalancerListenerContextQuery extends LoadBalancerFilter { readonly listenerPort?: number; /** - * When listener is cached in cdk.context.json, adds an additional discriminator to the - * cache key so that separate lookups with the same parameters can have separate cache lifecycles + * Adds an additional discriminator to the `cdk.context.json` cache key. + * + * @default - no additional cache key */ readonly additionalCacheKey?: string; } @@ -469,8 +479,9 @@ export interface SecurityGroupContextQuery { readonly vpcId?: string; /** - * When the security group is cached in cdk.context.json, adds an additional discriminator to the - * cache key so that separate lookups with the same parameters can have separate cache lifecycles + * Adds an additional discriminator to the `cdk.context.json` cache key. + * + * @default - no additional cache key */ readonly additionalCacheKey?: string; } @@ -502,8 +513,9 @@ export interface KeyContextQuery { readonly aliasName: string; /** - * When the key is cached in cdk.context.json, adds an additional discriminator to the - * cache key so that separate lookups with the same parameters can have separate cache lifecycles + * Adds an additional discriminator to the `cdk.context.json` cache key. + * + * @default - no additional cache key */ readonly additionalCacheKey?: string; } diff --git a/packages/aws-cdk-lib/cloud-assembly-schema/schema/cloud-assembly.schema.json b/packages/aws-cdk-lib/cloud-assembly-schema/schema/cloud-assembly.schema.json index c816d01810515..b44c72f63ef03 100644 --- a/packages/aws-cdk-lib/cloud-assembly-schema/schema/cloud-assembly.schema.json +++ b/packages/aws-cdk-lib/cloud-assembly-schema/schema/cloud-assembly.schema.json @@ -572,6 +572,10 @@ "type": "string" } } + }, + "additionalCacheKey": { + "description": "Adds an additional discriminator to the `cdk.context.json` cache key. (Default - no additional cache key)", + "type": "string" } }, "required": [ @@ -702,7 +706,7 @@ "type": "boolean" }, "additionalCacheKey": { - "description": "When the vpc is cached in cdk.context.json, adds an additional discriminator to the\ncache key so that separate lookups with the same parameters can have separate cache lifecycles", + "description": "Adds an additional discriminator to the `cdk.context.json` cache key. (Default - no additional cache key)", "type": "string" } }, @@ -756,7 +760,7 @@ "type": "string" }, "additionalCacheKey": { - "description": "When the load balancer is cached in cdk.context.json, adds an additional discriminator to the\ncache key so that separate lookups with the same parameters can have separate cache lifecycles", + "description": "Adds an additional discriminator to the `cdk.context.json` cache key. (Default - no additional cache key)", "type": "string" }, "loadBalancerType": { @@ -826,7 +830,7 @@ "type": "number" }, "additionalCacheKey": { - "description": "When listener is cached in cdk.context.json, adds an additional discriminator to the\ncache key so that separate lookups with the same parameters can have separate cache lifecycles", + "description": "Adds an additional discriminator to the `cdk.context.json` cache key. (Default - no additional cache key)", "type": "string" }, "loadBalancerType": { @@ -880,7 +884,7 @@ "type": "string" }, "additionalCacheKey": { - "description": "When the security group is cached in cdk.context.json, adds an additional discriminator to the\ncache key so that separate lookups with the same parameters can have separate cache lifecycles", + "description": "Adds an additional discriminator to the `cdk.context.json` cache key. (Default - no additional cache key)", "type": "string" } }, @@ -910,7 +914,7 @@ "type": "string" }, "additionalCacheKey": { - "description": "When the key is cached in cdk.context.json, adds an additional discriminator to the\ncache key so that separate lookups with the same parameters can have separate cache lifecycles", + "description": "Adds an additional discriminator to the `cdk.context.json` cache key. (Default - no additional cache key)", "type": "string" } }, diff --git a/packages/aws-cdk-lib/cloud-assembly-schema/schema/cloud-assembly.version.json b/packages/aws-cdk-lib/cloud-assembly-schema/schema/cloud-assembly.version.json index 1f0068d32659a..73a5830dc3eca 100644 --- a/packages/aws-cdk-lib/cloud-assembly-schema/schema/cloud-assembly.version.json +++ b/packages/aws-cdk-lib/cloud-assembly-schema/schema/cloud-assembly.version.json @@ -1 +1 @@ -{"version":"36.0.0"} \ No newline at end of file +{"version":"38.0.0"} \ No newline at end of file From 4cdc802c9f4bbfecb98d0ed634321e7cdcf313e4 Mon Sep 17 00:00:00 2001 From: Jonathan Romano Date: Mon, 20 Nov 2023 13:54:01 -0500 Subject: [PATCH 21/22] Regen schema from main --- .../cloud-assembly-schema/schema/cloud-assembly.version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/aws-cdk-lib/cloud-assembly-schema/schema/cloud-assembly.version.json b/packages/aws-cdk-lib/cloud-assembly-schema/schema/cloud-assembly.version.json index 73a5830dc3eca..1f0068d32659a 100644 --- a/packages/aws-cdk-lib/cloud-assembly-schema/schema/cloud-assembly.version.json +++ b/packages/aws-cdk-lib/cloud-assembly-schema/schema/cloud-assembly.version.json @@ -1 +1 @@ -{"version":"38.0.0"} \ No newline at end of file +{"version":"36.0.0"} \ No newline at end of file From 1b6955c99c3fca254bd7f82f629c2625869416fa Mon Sep 17 00:00:00 2001 From: Jonathan Romano Date: Mon, 20 Nov 2023 19:28:06 +0000 Subject: [PATCH 22/22] update-schema --- .../schema/cloud-assembly.schema.json | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/aws-cdk-lib/cloud-assembly-schema/schema/cloud-assembly.schema.json b/packages/aws-cdk-lib/cloud-assembly-schema/schema/cloud-assembly.schema.json index b44c72f63ef03..a4bdbf30b753e 100644 --- a/packages/aws-cdk-lib/cloud-assembly-schema/schema/cloud-assembly.schema.json +++ b/packages/aws-cdk-lib/cloud-assembly-schema/schema/cloud-assembly.schema.json @@ -91,11 +91,11 @@ "description": "Type of cloud artifact.", "type": "string", "enum": [ + "none", "aws:cloudformation:stack", - "cdk:asset-manifest", - "cdk:cloud-assembly", "cdk:tree", - "none" + "cdk:asset-manifest", + "cdk:cloud-assembly" ] }, "MetadataEntry": { @@ -492,15 +492,15 @@ "enum": [ "ami", "availability-zones", - "endpoint-service-availability-zones", "hosted-zone", - "key-provider", + "ssm", + "vpc-provider", + "endpoint-service-availability-zones", "load-balancer", "load-balancer-listener", - "plugin", "security-group", - "ssm", - "vpc-provider" + "key-provider", + "plugin" ] }, "ContextQueryProperties": { @@ -789,8 +789,8 @@ "description": "Type of load balancer", "type": "string", "enum": [ - "application", - "network" + "network", + "application" ] }, "LoadBalancerListenerContextQuery": {