fix: prevent TypeError in setGitEnvironmentVariables with CDK 2.253+#597
Closed
hari-euka wants to merge 1 commit into
Closed
fix: prevent TypeError in setGitEnvironmentVariables with CDK 2.253+#597hari-euka wants to merge 1 commit into
hari-euka wants to merge 1 commit into
Conversation
setGitEnvironmentVariables() crashes with 'Cannot read properties of undefined (reading "value")' when used with aws-cdk-lib >= 2.253.0. The issue is on line 71 where lam.environment[DD_TAGS].value is accessed unconditionally after the else branch calls addEnvironment(). In CDK 2.253, the internal .environment property structure changed, so .value may not exist after addEnvironment(). Fix: use addEnvironment() consistently via the public API instead of directly mutating the internal .environment property. This also simplifies the code by building the full git tags string upfront and using optional chaining for the existing value check. Fixes DataDog#596
3 tasks
Contributor
|
Unfortunately this doesn't actually fix the underlying issue that you can't actually access environment variables anymore: aws/aws-cdk#37773 |
10 tasks
Contributor
|
Thanks for opening this PR, this was ultimately resolved with #601 and https://github.com/DataDog/datadog-cdk-constructs/releases/tag/v2-4.0.0 |
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
Fixes #596 —
DatadogLambda.addLambdaFunctions()crashes withTypeError: Cannot read properties of undefined (reading 'value')when used withaws-cdk-lib >= 2.253.0.Root Cause
In
src/env.ts,setGitEnvironmentVariables()accesses the internallam.environment[DD_TAGS].valueproperty unconditionally on line 71, after theelsebranch callslam.addEnvironment():In
aws-cdk-lib@2.253.0, the internalenvironmentproperty structure on Lambda functions changed. After callingaddEnvironment(),lam.environment[DD_TAGS]may not have a.valueproperty, causing the TypeError.Fix
Use
addEnvironment()via the public API consistently instead of directly mutating the internal.environmentproperty:Key changes:
?.value) to safely read existing valuegit.commit.shaandgit.repository_url)addEnvironment()for all writes — never directly mutates.valueTests
All 240 existing tests pass, including the 4
DD_TAGStests that verify:git.commit.shaandgit.repository_urlare set by defaultDD_TAGSvalues are preserved when adding git metadataWorkaround
For users who need an immediate fix before this is released: