-
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
feat(aws-ecs): expose environment from containerDefinition #17889
Conversation
Title does not follow the guidelines of Conventional Commits. Please adjust title before merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great update. LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the whole point of exposing this member field publicly is, so that it can be mutated: sorry, no dice.
First of all, this will not work across jsii boundaries (as dictionaries are serialized by value and not by reference there), and reaching into the state of another class is not typically a recommended design choice. It happens to work for this case (by accident), but a strategy like this will not work for all cases. For example, it will not work if the ContainerDefinition
was directly represented as a resource in CloudFormation (try it on another class!).
The thing is: even though we don't have the mechanisms in place to enforce this, you are really really encouraged to treat those public members as readonly and immutable.
The better way to expose this feature is by providing an addEnvironment(key, value)
method, like a Lambda Function does: https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html#addwbrenvironmentkey-value-options
Also. You originally changed:
Into
Which I found confusing ( So in turn, I changed it to:
In order to preserve the original semantics of setting a single environment variable with a single value. However, now that I changed it, I'm getting the following build error:
And it turns out that indeed, its not a map of export interface ContainerOverride {
/**
* Variables to set in the container's environment
*/
readonly environment?: TaskEnvironmentVariable[];
}
/**
* An environment variable to be set in the container run as a task
*/
export interface TaskEnvironmentVariable {
/**
* Name for the environment variable
*
* Exactly one of `name` and `namePath` must be specified.
*/
readonly name: string;
/**
* Value of the environment variable
*
* Exactly one of `value` and `valuePath` must be specified.
*/
readonly value: string;
} So I don't know why you didn't get an error for the original change (you should have), but the original code was correct, and all of our modifications are incorrect. |
Thanks - nice object lesson for everyone to wait for AWS to comment on the original issue before writing code :-). I will update (rewrite) and resubmit based on a simplified version of how Lambda handles the issue (Lambda has more complexity due to deployments at edge and extra CDK created environment variables). |
I will leave the doc and example as they are as requested, but I think your example from ContainerOverride doesn't represent ContainerDefintionProps. Here's ContainerOverride:
Where environment is a list of
My intention (unless you request differently beforehand or upon review) is to have the signature of addEnvironmentVariables follow this paradigm. I'm not a fan of using attributes to represent a list (I like []), but it seems like addEnvironmentVariables should be consistent with how they are specified in props. (I also need to dive into ContainerOverride, I'm not familiar with that and don't know if that should figure into my implementation) Edited - I see what you mean now, the doc I changed in README was for ContainerOverride, not ContainerDefintion. |
Yes exactly. The reason it's different for Events's |
FWIW - rixOrrr approved this, but before it merge it drifted from Master and refreshing it instigated the need for another approval (no change was made on my end besides the merge). I'm a first time contributor, so the workflows are not enabled yet. |
Pull request has been modified.
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Closes aws#17867 * Assigned props.environment to a public readonly member * Added integration test that confirms the environment can be appended after the task is instantiated Made 2 cosmetic, but no obvious changes. Environment values are specified: name: value name2: value But in the test and the README.md files the sample values were: name: something value: something else This is using the string 'value" as a key - which, as someone reading the code for the first time, was confusing. So I changed the sample values to more clearly display what's a key and what's a value. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Closes #17867
Made 2 cosmetic, but no obvious changes. Environment values are specified:
name: value
name2: value
But in the test and the README.md files the sample values were:
name: something
value: something else
This is using the string 'value" as a key - which, as someone reading the code for the first time, was confusing. So I changed the sample values to more clearly display what's a key and what's a value.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license