Repository navigation
refactor(commons): extract shared isRunningInLambda helper - #5424
Merged
Merged
Conversation
The heuristic for detecting a real AWS Lambda execution environment (read AWS_LAMBDA_INITIALIZATION_TYPE with an 'unknown' fallback, then check dev mode) was duplicated inline in getMetadata and about to be copied by other features. Extract it into a single isRunningInLambda() helper in envUtils, define the env var name once in constants, and reuse the constant in Utility#getInitializationType so future changes to the detection logic happen in one place. Fixes #5408
svozza
approved these changes
Jul 8, 2026
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Extracts the heuristic for detecting whether code is running inside a real AWS Lambda execution environment into a single shared
isRunningInLambda()helper, so all current and future call sites share one definition instead of maintaining verbatim copies that must be updated in lockstep.Changes
isRunningInLambda()topackages/commons/src/envUtils.ts, exported via@aws-lambda-powertools/commons/utils/env; it readsAWS_LAMBDA_INITIALIZATION_TYPEwith an'unknown'fallback and returnsfalsewhen the type is unknown or when running in dev mode (isDevMode())AWS_LAMBDA_INITIALIZATION_TYPE_ENV_VARinpackages/commons/src/constants.tsgetMetadatainpackages/commons/src/metadata.tsto use the new helper instead of its inline copyUtility#getInitializationTypeto read the env var via the shared constant (kept readingprocess.envdirectly to avoid pulling the@aws/lambda-invoke-storeside-effect import fromenvUtils.jsinto the package main entry)on-demand,provisioned-concurrency, unset variable, and dev-mode overrideNote: the second call site mentioned in the issue (
parameters/src/appconfig-agent/getConfig.ts) comes from #5399, which is still open — it can adopt the helper once both land.Issue number: closes #5408
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.