diff --git a/lib/aurora-serverless.ts b/lib/aurora-serverless.ts index 309947a..771a9df 100644 --- a/lib/aurora-serverless.ts +++ b/lib/aurora-serverless.ts @@ -54,6 +54,7 @@ export class BastionHostAuroraServerlessForward extends BastionHostForward { clientTimeout: props.clientTimeout, serverTimeout: props.serverTimeout, shouldPatch: props.shouldPatch, + cachedInContext: props.cachedInContext, }); if (props.iamUser !== undefined && props.resourceIdentifier !== undefined) { diff --git a/lib/bastion-host-forward-base-props.ts b/lib/bastion-host-forward-base-props.ts index 846cfa0..b99aba5 100644 --- a/lib/bastion-host-forward-base-props.ts +++ b/lib/bastion-host-forward-base-props.ts @@ -54,4 +54,25 @@ export interface BastionHostForwardBaseProps { * @default true */ readonly shouldPatch?: boolean; + + /** + * Whether the AMI ID is cached to be stable between deployments + * + * By default, the newest image is used on each deployment. This will cause + * instances to be replaced whenever a new version is released, and may cause + * downtime if there aren't enough running instances in the AutoScalingGroup + * to reschedule the tasks on. + * + * If set to true, the AMI ID will be cached in `cdk.context.json` and the + * same value will be used on future runs. Your instances will not be replaced + * but your AMI version will grow old over time. 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. + * + * Can not be set to `true` in environment-agnostic stacks. + * + * @default false + */ + readonly cachedInContext?: boolean; } diff --git a/lib/bastion-host-forward.ts b/lib/bastion-host-forward.ts index 7c91e14..f1b1462 100644 --- a/lib/bastion-host-forward.ts +++ b/lib/bastion-host-forward.ts @@ -120,6 +120,7 @@ export class BastionHostForward extends Construct { machineImage: new AmazonLinuxImage({ cpuType: AmazonLinuxCpuType.ARM_64, generation: AmazonLinuxGeneration.AMAZON_LINUX_2023, + cachedInContext: props.cachedInContext, }), instanceType: InstanceType.of(InstanceClass.T4G, InstanceSize.NANO), blockDevices: [ diff --git a/lib/generic-bastion-host-forward.ts b/lib/generic-bastion-host-forward.ts index e7daebd..dbff105 100644 --- a/lib/generic-bastion-host-forward.ts +++ b/lib/generic-bastion-host-forward.ts @@ -33,6 +33,7 @@ export class GenericBastionHostForward extends BastionHostForward { clientTimeout: props.clientTimeout, serverTimeout: props.serverTimeout, shouldPatch: props.shouldPatch, + cachedInContext: props.cachedInContext, }); } } diff --git a/lib/rds.ts b/lib/rds.ts index aff1965..02eadf1 100644 --- a/lib/rds.ts +++ b/lib/rds.ts @@ -55,6 +55,7 @@ export class BastionHostRDSForward extends BastionHostForward { clientTimeout: props.clientTimeout, serverTimeout: props.serverTimeout, shouldPatch: props.shouldPatch, + cachedInContext: props.cachedInContext, }); if (props.iamUser !== undefined && props.rdsResourceIdentifier !== undefined) {