AWS Typescript CDK:存在此 Lambda 函数的版本 (1)。修改函数创建新版本
AWS Typescript CDK: A version for this Lambda function exists ( 1 ). Modify the function to create a new version
这是我的 CDK 代码:
const addVersion = (resourcePrefix: string, lambda: NodejsFunction) => {
const version = new Version(this, `${resourcePrefix}Version`, {
lambda,
});
const alias = new Alias(this, `${resourcePrefix}VersionAlias`, {
aliasName: 'current',
version,
});
alias.node.addDependency(version);
}
第一次部署成功,后续部署失败。我假设这是因为 CDK 每次都试图创建一个新版本的 Lambda 函数,即使源代码没有被修改。我怎样才能让它停止这样做?
参考 Lambda 的 currentVersion
属性:
new Alias(this, `${resourcePrefix}VersionAlias`, {
aliasName: 'current',
version: lmbda.currentVersion,
});
docs: The fn.currentVersion
property can be used to obtain a lambda.Version
resource that represents the AWS Lambda function defined in your application. Any change to your function's code or configuration will result in the creation of a new version resource. You can specify options for this version through the currentVersionOptions property.
这是我的 CDK 代码:
const addVersion = (resourcePrefix: string, lambda: NodejsFunction) => {
const version = new Version(this, `${resourcePrefix}Version`, {
lambda,
});
const alias = new Alias(this, `${resourcePrefix}VersionAlias`, {
aliasName: 'current',
version,
});
alias.node.addDependency(version);
}
第一次部署成功,后续部署失败。我假设这是因为 CDK 每次都试图创建一个新版本的 Lambda 函数,即使源代码没有被修改。我怎样才能让它停止这样做?
参考 Lambda 的 currentVersion
属性:
new Alias(this, `${resourcePrefix}VersionAlias`, {
aliasName: 'current',
version: lmbda.currentVersion,
});
docs: The
fn.currentVersion
property can be used to obtain alambda.Version
resource that represents the AWS Lambda function defined in your application. Any change to your function's code or configuration will result in the creation of a new version resource. You can specify options for this version through the currentVersionOptions property.