Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(lambda): Retain Existing Lambda Aliases When Adding an Alias to Version

See original GitHub issue

Would 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
           .fromVersionArn(...get function version...)
           .addAlias( <aliasName>, {

                        description: CDK_CONFIG.DATETIME_ISO
                       retentionPolicy: cdkLambda.Alias.RentionPolicy.RETAIN_OTHER_ALIASES


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: {

if ( updateAliasToThisVersion ) {
                    .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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

snowe2010commented, May 11, 2022

It seems like (alias.node.defaultChild as CfnResource).applyRemovalPolicy(RemovalPolicy.RETAIN); might work for our use case.

snowe2010commented, May 9, 2022

@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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found