(lambda): Retain Existing Lambda Aliases When Adding an Alias to Version
See original GitHub issueWould like to manage multiple Lambda Alias from CDK deploy. We want to update an Alias to point to a specific version without deleting existing Aliases.
Whenever we try to add an alias to a Lambda Version, it deletes existing Aliases:
lambdaFunction.currentVersion.addAlias( <alias name>,{
description: DATETIME_ISO
})
Use Case
We want to manage multiple aliases for a single lambda. We will deploy multiple versions, but when we “release” we will point the alias(es) to a specific version.
example of what we want: versions deployed 29 28 <- QA 27 26 25 <- DEV 24
Proposed solution
Add an Alias removal policy
a removal policy when adding an alias
cdkLambda.Version
.fromVersionArn(...get function version...)
.addAlias( <aliasName>, {
description: CDK_CONFIG.DATETIME_ISO
...
retentionPolicy: cdkLambda.Alias.RentionPolicy.RETAIN_OTHER_ALIASES
})
Other
Example of my cdk code to deploy lambda:
const lambda = require("@aws-cdk/aws-lambda");
const lambdaFunction = new lambda.Function(this, `lambda-${CDK_CONFIG.ENV_LOWER}`, {
functionName: `${CDK_CONFIG.FUNCTION_NAME}`,
runtime: lambda.Runtime.NODEJS_12_X,
code: lambda.Code.fromAsset(`../${CDK_CONFIG.FUNCTION_NAME}.zip`),
handler: "src/index.handler",
description: CDK_CONFIG.DATETIME_ISO,
currentVersionOptions: {
removalPolicy: cdk.RemovalPolicy.RETAIN,
// codeSha256:
},
timeout: CDK_CONFIG.LAMBDA_TIMEOUT,
memorySize: CDK_CONFIG.LAMBDA_MEMORY_SIZE,
vpc: lambdaVpc,
vpcSubnets: {
subnets: [
{subnetId: cdk.Fn.importValue("k8s-subnet-a-lambda")},
{subnetId: cdk.Fn.importValue("k8s-subnet-b-lambda")},
]
},
securityGroups: [
{securityGroupId: "a"},
{securityGroupId: "b"},
{securityGroupId: "c"},
],
environment: {
ENVIRONMENT: CDK_CONFIG.ENV_UPPER,
LOG_LEVEL: CDK_CONFIG.LOG_LEVEL
},
});
if ( updateAliasToThisVersion ) {
lambdaFunction
.currentVersion
.addAlias(CDK_CONFIG.ENV_UPPER ,{
description: CDK_CONFIG.DATETIME_ISO
})
}
- 👋 I may be able to implement this feature request
- ⚠️ This feature might incur a breaking change
This is a 🚀 Feature Request
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:11 (3 by maintainers)
Top Results From Across the Web
Lambda function aliases
You can create one or more aliases for your Lambda function. A Lambda alias is like a pointer to a specific function version....
Read more >AWS Lambda Versioning and Aliases
The alias is simply a pointer to a specific Lambda function version. Each alias also has a unique ARN. One key difference between...
Read more >Lambda Versions and Aliases #27 #HowTo - YouTube
In this video, we cover a very interesting topic of lambda versions and aliases. #aws #awscertifed #learning #freevideos #awscommunity ...
Read more >AWS Lambda Versions and Aliases Explained - YouTube
AWS Lambda versions and aliases are two concepts easily confused, in this video I explain how to use it and enable blue-green deployments....
Read more >AWS Lambda Function Version Alias
The only difference when invoking the Lambda Function version versus the alias one is that in the Amazon ARN value you provide to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It seems like
(alias.node.defaultChild as CfnResource).applyRemovalPolicy(RemovalPolicy.RETAIN);
might work for our use case.@rix0rrr Our team’s account manager (A. Langford) had said that the cdk team was working on this issue. Our problem is not solved with separate stacks. We want to retain an alias for every version that we deploy (we deploy hundreds of versions for a single stack, never updating old versions). Are you saying that setting the retention policy will be enough to accomplish that?