FG
💻 Software☁️ Cloud & DevOpsAmazon

Environment variables not updating in new lambda function version

Fresh3 days ago
Mar 14, 20260 views
Confidence Score79%
79%

Problem

This is a Bug Report Description For bug reports: What went wrong? New environment variables are not deploying to new function version for AWS Lambda. I've verified that the new variables are properly set inside the CloudFormation stack template. I've also ran every variation of deploy (with `-p`, with `-f`, with `--force`, with `--update-config`, and with code changes). My base use case is to `sls package` first, then deploy with `-p` What did you expect should have happened? Changing or adding environment variables in serverless.yml should update environment variables in lambda console for the corresponding function version when deployed. What was the config you used? [code block] What stacktrace or error message from your provider did you see? No error message. Package and Deploy were successful. Similar or dependent issues: https://github.com/HyperBrain/serverless-aws-alias/issues/91 Additional Data Serverless Framework Version you're using: 1.25.0 Operating System: Mac High Sierra locally and Ubuntu in CircleCI Stack Trace: None Provider Error messages*: None

Error Output

error message from your provider did you see?

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Update Environment Variables in Lambda Function Version

Medium Risk

The issue arises because the Serverless Framework does not automatically update environment variables for existing Lambda function versions when deploying. This is often due to the way AWS Lambda handles versions and aliases, where changes to environment variables need to be explicitly defined in the deployment process.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Update serverless.yml with Environment Variables

    Ensure that your environment variables are correctly defined in the serverless.yml file under the 'environment' section of the function configuration.

    yaml
    environment:
      MY_ENV_VAR: 'new_value'
  2. 2

    Deploy with Versioning

    Use the Serverless Framework to deploy your function with versioning enabled. This ensures that the new environment variables are applied to the new version of the function.

    bash
    sls deploy --stage <your-stage> --region <your-region>
  3. 3

    Verify the Deployment

    Check the AWS Lambda console to confirm that the new version of the function has the updated environment variables. Navigate to the function, select the latest version, and review the environment variables section.

  4. 4

    Clear Cached Versions

    If the environment variables are still not updated, clear any cached versions by using the command: `sls remove` followed by `sls deploy`. This ensures that all previous versions are removed and the new deployment is clean.

    bash
    sls remove && sls deploy
  5. 5

    Use AWS CLI to Confirm

    As an additional verification step, use the AWS CLI to list the environment variables for the specific Lambda function version to ensure they are correctly set.

    bash
    aws lambda get-function-configuration --function-name <your-function-name> --query 'Environment.Variables'

Validation

Confirm that the environment variables are correctly set in the AWS Lambda console for the latest function version. Additionally, use the AWS CLI command provided to ensure the variables match what is defined in your serverless.yml.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

serverlesslambdaawsbughelp-wantedcat/lambda