Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(lambda): ensure consistent environment variable management #33583

Closed
wants to merge 2 commits into from

Conversation

azarboon
Copy link
Contributor

This update improves the AWS Lambda documentation by introducing a single source of truth for environment variables using TypeScript. It addresses the common issue of environment variable inconsistencies between Lambda function code and AWS CDK infrastructure.

Key Improvements:

  • Defines environment variables in a shared env.ts module.
  • Ensures type safety and consistency across Lambda and CDK.
  • Reduces duplication and minimizes the risk of misconfigured environment variables.
  • Enhances maintainability and developer experience.

By implementing this approach, developers can catch errors at compile time, benefit from improved IDE support, and prevent mismatches between deployment and runtime environments.

Issue # (if applicable)

Closes #.

Reason for this change

Environment variables are often defined separately in Lambda function code and AWS CDK, leading to potential inconsistencies, deployment mismatches, and runtime failures. By centralizing env var definitions in a TypeScript module, this approach improves reliability, prevents human errors, and enforces stricter type safety. It also makes the codebase more maintainable by reducing duplication and ensuring that changes to environment variables propagate correctly across the application and infrastructure.

Description of changes

  • Added a new section to the AWS Lambda documentation explaining how to manage environment variables with a single source of truth in TypeScript.
  • Provided step-by-step instructions for defining, referencing, and using a shared env.ts module in both Lambda function code and AWS CDK infrastructure.
  • Included example code snippets demonstrating best practices for env var management.
  • Improved error handling considerations, ensuring that missing environment variables are properly managed.

Describe any new or updated permissions being added

Description of how you validated changes

I ran the provided code examples locally to ensure correctness and consistency between the Lambda function and AWS CDK infrastructure. The Lambda function successfully retrieved environment variables from the centralized env.ts module, and the AWS CDK deployment correctly passed the expected environment variables to the Lambda function. No runtime errors or deployment issues were encountered.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

This update improves the AWS Lambda documentation by introducing a single source of truth for environment variables using TypeScript. It addresses the common issue of environment variable inconsistencies between Lambda function code and AWS CDK infrastructure.

Key Improvements:
- Defines environment variables in a shared env.ts module.
- Ensures type safety and consistency across Lambda and CDK.
- Reduces duplication and minimizes the risk of misconfigured environment variables.
- Enhances maintainability and developer experience.

By implementing this approach, developers can catch errors at compile time, benefit from improved IDE support, and prevent mismatches between deployment and runtime environments.
@aws-cdk-automation aws-cdk-automation requested a review from a team February 26, 2025 03:54
@github-actions github-actions bot added p2 repeat-contributor [Pilot] contributed between 3-5 PRs to the CDK labels Feb 26, 2025
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This review is outdated)

@azarboon azarboon changed the title docs(aws-lambda): Ensure Consistent Environment Variable Management docs(lambda): ensure consistent environment variable management Feb 26, 2025
@aws-cdk-automation aws-cdk-automation dismissed their stale review February 26, 2025 03:58

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

Copy link

codecov bot commented Feb 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.21%. Comparing base (6df9bfe) to head (065c0b9).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #33583   +/-   ##
=======================================
  Coverage   82.21%   82.21%           
=======================================
  Files         119      119           
  Lines        6876     6876           
  Branches     1162     1162           
=======================================
  Hits         5653     5653           
  Misses       1120     1120           
  Partials      103      103           
Flag Coverage Δ
suite.unit 82.21% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
packages/aws-cdk ∅ <ø> (∅)
packages/aws-cdk-lib/core 82.21% <ø> (ø)

fixed some errors during build time
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 065c0b9
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@azarboon azarboon closed this Feb 26, 2025
Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 26, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p2 repeat-contributor [Pilot] contributed between 3-5 PRs to the CDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants