You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CdkFunction.environment is a lazily evaluated value which can be resolved to CfnFunction.EnvironmentProperty.
In TypeScript and Go, environment returns LazyAny and typeregistry.anonymousProxy respectively, both of which can then be resolved with stack.resolve(environment).
In Python, environment returns an actual EnvironmentProperty instead of a reference, with variables=None. This resolves to an empty dict.
Expected Behavior
I expected CfnFunction.environment to be an IResolvable value which could then be resolved with stack.resolve(environment).
Current Behavior
CfnFunction.environment is an empty EnvironmentProperty value with no reference, so it's not possible to get the environment variables from this value.
Note the extra request at the end of the Python logs. This is from the exact same line of code, cfnFunction.Environment() and cfn_function.environment respectively.
Reproduction Steps
Paste each block into the stack file in the project created by cdk init for that language, then run cdk ls.
The value returned from kernel.get() is an ObjRef, which is passed to _reference_map.resolve_reference() via the @_dereferenced decorator and _recursize_dereference().
The ref is something like Object@10047, so class_fqn is Object. The condition on line 104-106 below evaluates to True and it ends up creating and returning an EnvironmentProperty value with no data (because it hasn't been resolved with CDK yet).
My use case is to create a custom aspect which adds default environment variables to all Lambdas in a stack. The aspect shouldn't overwrite variables set directly on a function, so it needs to know which ones already exist, if any.
SDK version used
JSII 1.84.0, CDK lib and cli 2.84.0, Constructs 10.2.55
Environment details (OS name and version, etc.)
Windows 10.0.14393 Build 14393, Python 3.11.3
The text was updated successfully, but these errors were encountered:
Update: it's possible to work around this issue by calling internal JSII functions with the below code, but it feels fragile.
This works by essentially intercepting the output of jsii.get() before it goes through _recursize_dereference(), changing the type of the reference to IResolvable, and then dereferencing it.
Describe the bug
CdkFunction.environment is a lazily evaluated value which can be resolved to
CfnFunction.EnvironmentProperty
.In TypeScript and Go,
environment
returnsLazyAny
andtyperegistry.anonymousProxy
respectively, both of which can then be resolved withstack.resolve(environment)
.In Python,
environment
returns an actualEnvironmentProperty
instead of a reference, withvariables=None
. This resolves to an empty dict.Expected Behavior
I expected
CfnFunction.environment
to be anIResolvable
value which could then be resolved withstack.resolve(environment)
.Current Behavior
CfnFunction.environment
is an emptyEnvironmentProperty
value with no reference, so it's not possible to get the environment variables from this value.JSII_DEBUG output from Go:
From Python:
Note the extra request at the end of the Python logs. This is from the exact same line of code,
cfnFunction.Environment()
andcfn_function.environment
respectively.Reproduction Steps
Paste each block into the stack file in the project created by
cdk init
for that language, then runcdk ls
.Python:
Output:
TypeScript (working, for comparison):
Output:
Possible Solution
Here's what I've been able to figure out by stepping through with a debugger. Hopefully this helps.
CfnFunction.environment
is a property which callsjsii.get()
, akakernel.get()
.jsii/packages/@jsii/python-runtime/src/jsii/_kernel/__init__.py
Lines 358 to 366 in 14b5ed2
The value returned from
kernel.get()
is anObjRef
, which is passed to_reference_map.resolve_reference()
via the@_dereferenced
decorator and_recursize_dereference()
.jsii/packages/@jsii/python-runtime/src/jsii/_kernel/__init__.py
Lines 133 to 151 in 14b5ed2
The ref is something like
Object@10047
, soclass_fqn
isObject
. The condition on line 104-106 below evaluates to True and it ends up creating and returning anEnvironmentProperty
value with no data (because it hasn't been resolved with CDK yet).jsii/packages/@jsii/python-runtime/src/jsii/_reference_map.py
Lines 102 to 128 in 14b5ed2
Additional Information/Context
My use case is to create a custom aspect which adds default environment variables to all Lambdas in a stack. The aspect shouldn't overwrite variables set directly on a function, so it needs to know which ones already exist, if any.
SDK version used
JSII 1.84.0, CDK lib and cli 2.84.0, Constructs 10.2.55
Environment details (OS name and version, etc.)
Windows 10.0.14393 Build 14393, Python 3.11.3
The text was updated successfully, but these errors were encountered: