-
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(ecs): support secret environment variables #2994
Changes from 11 commits
146f13e
5384d55
bf91871
a0bb714
2a5155b
d697273
d1c31bf
3c75145
a242dca
67b0abe
f8d0efc
f3cb37a
39909d7
43f8244
3a6a374
f300b28
bcc350a
17e0964
d629929
80d4495
199de19
037f9e4
6cca252
aedbbb8
410cfd5
5f5cf12
6298b4d
865d7f2
a2032a6
f27f8c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,7 @@ export interface QueueProcessingServiceBaseProps { | |
* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this really the default or will it always be passed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part is not mine, it seems that it's always passed, I can update the doc. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, that would be nice |
||
* @default 'QUEUE_NAME: queue.queueName' | ||
*/ | ||
readonly environment?: { [key: string]: string }; | ||
readonly environment?: { [key: string]: ecs.EnvironmentValue }; | ||
|
||
/** | ||
* A queue for which to process items from. | ||
|
@@ -88,7 +88,7 @@ export abstract class QueueProcessingServiceBase extends cdk.Construct { | |
/** | ||
* Environment variables that will include the queue name | ||
*/ | ||
public readonly environment: { [key: string]: string }; | ||
public readonly environment: { [key: string]: ecs.EnvironmentValue }; | ||
/** | ||
* The minimum number of tasks to run | ||
*/ | ||
|
@@ -121,7 +121,7 @@ export abstract class QueueProcessingServiceBase extends cdk.Construct { | |
this.logDriver = enableLogging ? this.createAWSLogDriver(this.node.id) : undefined; | ||
|
||
// Add the queue name to environment variables | ||
this.environment = { ...(props.environment || {}), QUEUE_NAME: this.sqsQueue.queueName }; | ||
this.environment = { ...(props.environment || {}), QUEUE_NAME: ecs.EnvironmentValue.fromString(this.sqsQueue.queueName) }; | ||
|
||
// Determine the desired task count (minimum) and maximum scaling capacity | ||
this.desiredCount = props.desiredTaskCount || 1; | ||
|
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.
I feel like we might want to use some token magic here.
FWIW, we should have Tokenized representations of secret values already. Can we not use those in some way?
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.
For the
Secrets
property, CF expects the ARN of the secret/ssm param, the container will pull that value at startup and set it as env var avoiding passing secrets in clear text. Secret env vars are retrieved at runtime (always up to date), this is not the case with simple env vars (fixed at deploy time)The class
EnvironmentValue
will feed eitherenvironment
orsecrets
based on the type. This gives a better user experience (higher level of abstraction) than having to specifyenvironment
and/orsecrets
manually (both will become env vars in the running container at the end).https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ecs-taskdefinition-containerdefinitions.html#cfn-ecs-taskdefinition-containerdefinition-environment
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ecs-taskdefinition-secret.html
The support for the
Secrets
property was added in the latest release of CF (https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/ReleaseHistory.html).https://docs.aws.amazon.com/AmazonECS/latest/developerguide/specifying-sensitive-data.html