in packages/@aws-cdk/toolkit-lib/lib/api/bootstrap/deploy-bootstrap.ts [74:152]
public async update(
template: any,
parameters: Record<string, string | undefined>,
options: Omit<BootstrapEnvironmentOptions, 'parameters'>,
): Promise<SuccessfulDeployStackResult> {
if (this.currentToolkitInfo.found && !options.forceDeployment) {
// Safety checks
const abortResponse = {
type: 'did-deploy-stack',
noOp: true,
outputs: {},
stackArn: this.currentToolkitInfo.bootstrapStack.stackId,
} satisfies SuccessfulDeployStackResult;
// Validate that the bootstrap stack we're trying to replace is from the same variant as the one we're trying to deploy
const currentVariant = this.currentToolkitInfo.variant;
const newVariant = bootstrapVariantFromTemplate(template);
if (currentVariant !== newVariant) {
await this.ioHelper.notify(IO.DEFAULT_TOOLKIT_WARN.msg(
`Bootstrap stack already exists, containing '${currentVariant}'. Not overwriting it with a template containing '${newVariant}' (use --force if you intend to overwrite)`,
));
return abortResponse;
}
// Validate that we're not downgrading the bootstrap stack
const newVersion = bootstrapVersionFromTemplate(template);
const currentVersion = this.currentToolkitInfo.version;
if (newVersion < currentVersion) {
await this.ioHelper.notify(IO.DEFAULT_TOOLKIT_WARN.msg(
`Bootstrap stack already at version ${currentVersion}. Not downgrading it to version ${newVersion} (use --force if you intend to downgrade)`,
));
if (newVersion === 0) {
// A downgrade with 0 as target version means we probably have a new-style bootstrap in the account,
// and an old-style bootstrap as current target, which means the user probably forgot to put this flag in.
await this.ioHelper.notify(IO.DEFAULT_TOOLKIT_WARN.msg(
"(Did you set the '@aws-cdk/core:newStyleStackSynthesis' feature flag in cdk.json?)",
));
}
return abortResponse;
}
}
const outdir = await fs.mkdtemp(path.join(os.tmpdir(), 'cdk-bootstrap'));
const builder = new CloudAssemblyBuilder(outdir);
const templateFile = `${this.toolkitStackName}.template.json`;
await fs.writeJson(path.join(builder.outdir, templateFile), template, {
spaces: 2,
});
builder.addArtifact(this.toolkitStackName, {
type: ArtifactType.AWS_CLOUDFORMATION_STACK,
environment: EnvironmentUtils.format(this.resolvedEnvironment.account, this.resolvedEnvironment.region),
properties: {
templateFile,
terminationProtection: options.terminationProtection ?? false,
},
});
const assembly = builder.buildAssembly();
const ret = await deployStack({
stack: assembly.getStackByName(this.toolkitStackName),
resolvedEnvironment: this.resolvedEnvironment,
sdk: this.sdk,
sdkProvider: this.sdkProvider,
forceDeployment: options.forceDeployment,
roleArn: options.roleArn,
tags: options.tags,
deploymentMethod: { method: 'change-set', execute: options.execute },
parameters,
usePreviousParameters: options.usePreviousParameters ?? true,
// Obviously we can't need a bootstrap stack to deploy a bootstrap stack
envResources: new NoBootstrapStackEnvironmentResources(this.resolvedEnvironment, this.sdk, this.ioHelper),
}, this.ioHelper);
assertIsSuccessfulDeployStackResult(ret);
return ret;
}