-
Notifications
You must be signed in to change notification settings - Fork 4k
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
lambda.Function.addEnvironment appears to only accept string type values #3337
Comments
Your issue is mentioned in #744 It's not really a construct library gap, but a fairly common CloudFormation quirk. It gets even more frustrating with ECS, in which you have the Container const cpuReservation = 256;
const memoryReservation = 256;
const taskDefinition = new TaskDefinition(this, 'task', {
memoryMiB: memoryReservation.toString(),
cpu: cpuReservation.toString(),
compatibility: Compatibility.EC2,
});
const container = taskDefinition.addContainer('container', {
logging: LogDriver.awsLogs({streamPrefix: 'ecs'}),
image: ContainerImage.fromEcrRepository(ecr, 'latest'),
cpu: cpuReservation,
memoryLimitMiB: memoryReservation,
}); |
My issue is that the AWS CDK documentation doesn't mention that the value type needs to be a string. In https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ecs.TaskDefinition.html, the Whereas, https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html#add-environmentkey-value, has the value as Even easier suggested fixIf the AWS CDK documentation above was updated to |
I see, my bad. Your issue is that the
|
Yes, either the AWS CDK documentation (for the type of Going by the CDK docs, I wrongly assumed it would take care of any type conversions necessary. |
AWS Lambda requires that all environment variables will be strings but the API indicated `any` as the type of the value. If users would pass in a non-string value, they would see an error only during deployment. Fixes #3337
* fix(lambda): environment var values are strings AWS Lambda requires that all environment variables will be strings but the API indicated `any` as the type of the value. If users would pass in a non-string value, they would see an error only during deployment. Fixes #3337 * remove redundant null-check on this.environment * add breaking change excludes
Note: for support questions, please first reference our documentation, then use Stackoverflow. This repository's issues are intended for feature requests and bug reports.
I'm submitting a ...
What is the current behavior?
If the current behavior is a 🪲bug🪲: Please provide the steps to reproduce
attempting a
cdk synth
results in an error:What is the expected behavior (or behavior of feature suggested)?
TABLE_TTL
should be added as a Lambda environment variable as "300" (presumably Lambda env vars are only ever string type values)What is the motivation / use case for changing the behavior or adding this feature?
I had to do the following as a workaround:
the "hacky" string conversion is a bit (code-)smelly
Please tell us about your environment:
Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. associated pull-request, stackoverflow, gitter, etc)
I think
.addEnvironment
should handle the string conversion, as the value arg/param is documented asany
type. I think a number to string conversion should be an easy quick fix, without having to necessarily cater for more difficult type to string conversions.maybe that would be "good enough" to handle "any" (sane) values passed?
The text was updated successfully, but these errors were encountered: