How do I update Lambda environment variables without hardcoding a new function version into my application?

Last updated: 2021-06-29

I want to update my AWS Lambda function's environment variables without changing the Lambda Qualified Amazon Resource Name (Lambda Version ARN) in my client-side application. How do I avoid hardcoding a specific Lambda function version into my application each time I update my function's environment variables?

Short description

You can't change the environment variables or function code in a published Lambda function version. You can change only the current, unpublished function version ($LATEST). To avoid hardcoding a specific Lambda function version into your application, you can configure a Lambda alias ARN into your application instead. Each Lambda alias has a unique ARN and can be reconfigured once created to point to new versions of your function.

Resolution

Note: If you receive errors when running AWS Command Line Interface (AWS CLI) commands, make sure that you’re using the most recent AWS CLI version.

Update the environment variables in your unpublished Lambda function version

To use the Lambda console

Follow the instructions in Using AWS Lambda environment variables.

To use the update-function-configuration AWS CLI command

Follow the instructions in update-function-configuration (AWS CLI command reference).

To use the Lambda API calls in the AWS SDKs

Follow the instructions in Configuring environment variables with the API.

Publish a new Lambda function version that includes the updated environment variables

Follow the instructions in Creating function versions.

Create a new Lambda function alias (or use an existing alias) to point to your updated function version and configure it into your application

Note: Lambda aliases can point only to a function version, not to another alias.

To create a new function alias

Follow the instructions in Creating a function alias (Console). Then, point the alias to your updated function version by following the instructions in Alias routing configuration.

To use an existing function alias

Follow the instructions in Alias routing configuration.

Important: Make sure that you configure the Lambda alias's ARN into your client-side application, not the ARN of your new function version.

Invoke your updated function version manually

Follow the instructions in the Invoke the Lambda function section of Create a Lambda function with the console.

Your Lambda function alias now points to the latest function version that's configured with the environment variables that you want to use.


Did this article help?


Do you need billing or technical support?