Here is my CDK code:
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);
}
The first deployment succeeds, subsequent deployments fail. I'm assuming it's because CDK is attempting to create a new version of the Lambda function each time even when the source code has not been modified. How can I get it to stop doing this?
Reference the Lambda's currentVersion property:
new Alias(this, `${resourcePrefix}VersionAlias`, {
aliasName: 'current',
version: lmbda.currentVersion,
});
docs: The
fn.currentVersionproperty can be used to obtain alambda.Versionresource 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With