Skip to main content
In this tutorial, you’ll learn how to update AWS Lambda environment variables using the AWS CLI and automate the process in a Jenkins CI/CD pipeline. We’ll cover:
  • Updating Lambda configuration with aws lambda update-function-configuration
  • Integrating environment updates and code deployment in Jenkins
  • Handling OWASP Dependency Check failures
  • Verifying updates in the AWS Lambda console

Updating Lambda Configuration with AWS CLI

The AWS CLI’s update-function-configuration command lets you modify Lambda settings, including environment variables. For full details, see the AWS CLI Command Reference.
The image shows a webpage from the AWS CLI Command Reference, specifically detailing the "update-function-configuration" command for AWS Lambda. It includes sections like description, synopsis, options, and examples.

Key Parameters

Environment Syntax

When using inline JSON on the command line, wrap the JSON in single quotes to avoid shell parsing errors.

Example: Update and Confirm

Integrating with Jenkins

We’ll extend the Jenkinsfile to:
  1. Zip application code
  2. Upload the ZIP to S3
  3. Update Lambda environment variables
  4. Deploy new code to Lambda
Below is a sample pipeline and a breakdown of each stage.

Sample Jenkinsfile

Pipeline Stages Overview

Handling OWASP Dependency Check Failures

If the OWASP scan reports critical vulnerabilities, you can configure the publisher to continue the build:
Setting stopBuild: false allows the pipeline to proceed despite critical vulnerabilities. Be sure to review the detailed report and address issues in your next sprint.
Pipeline logs will show any OWASP failures and continue execution.
The image shows a Jenkins pipeline interface for a project named "solar-system," highlighting a failed step in the "Dependency Scanning" stage due to an OWASP Dependency Check error.
The image shows a dependency check report from Jenkins, listing various software dependencies, their vulnerability IDs, severity levels, and other related details. The report highlights a critical vulnerability in the "y18n" package.

Verifying on AWS Lambda Console

Once the pipeline succeeds, open the AWS Lambda console and navigate to the Configuration tab to confirm the new environment variables:
The image shows an AWS Lambda console with the "Configuration" tab open, displaying environment variables for a function, including keys and values for MongoDB connection details.

Testing the Application

Invoke your function’s endpoint or run a test to ensure it’s using the updated variables and code:
If you receive a 200 OK response with {"status":"live"}, your Lambda update was successful.

Watch Video