forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ecs): secret JSON key for environment variables
Amazon Elastic Container Service now supports reading AWS Secrets Manager secrets from a key within a JSON object. See https://aws.amazon.com/about-aws/whats-new/2020/02/amazon-ecs-now-supports-aws-secrets-manager-version-and-json-keys/ Closes aws#5665
- Loading branch information
Showing
4 changed files
with
196 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
117 changes: 117 additions & 0 deletions
117
packages/@aws-cdk/aws-ecs/test/fargate/integ.secret-json-key.expected.json
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
{ | ||
"Resources": { | ||
"SecretA720EF05": { | ||
"Type": "AWS::SecretsManager::Secret", | ||
"Properties": { | ||
"GenerateSecretString": { | ||
"GenerateStringKey": "password", | ||
"SecretStringTemplate": "{\"username\":\"user \"}" | ||
} | ||
} | ||
}, | ||
"TaskDefTaskRole1EDB4A67": { | ||
"Type": "AWS::IAM::Role", | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "ecs-tasks.amazonaws.com" | ||
} | ||
} | ||
], | ||
"Version": "2012-10-17" | ||
} | ||
} | ||
}, | ||
"TaskDef54694570": { | ||
"Type": "AWS::ECS::TaskDefinition", | ||
"Properties": { | ||
"ContainerDefinitions": [ | ||
{ | ||
"Essential": true, | ||
"Image": "amazon/amazon-ecs-sample", | ||
"Name": "web", | ||
"Secrets": [ | ||
{ | ||
"Name": "PASSWORD", | ||
"ValueFrom": { | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
{ | ||
"Ref": "SecretA720EF05" | ||
}, | ||
":password::" | ||
] | ||
] | ||
} | ||
} | ||
] | ||
} | ||
], | ||
"Cpu": "512", | ||
"ExecutionRoleArn": { | ||
"Fn::GetAtt": [ | ||
"TaskDefExecutionRoleB4775C97", | ||
"Arn" | ||
] | ||
}, | ||
"Family": "awsecsintegsecretjsonkeyTaskDefC01C0E99", | ||
"Memory": "1024", | ||
"NetworkMode": "awsvpc", | ||
"RequiresCompatibilities": [ | ||
"FARGATE" | ||
], | ||
"TaskRoleArn": { | ||
"Fn::GetAtt": [ | ||
"TaskDefTaskRole1EDB4A67", | ||
"Arn" | ||
] | ||
} | ||
} | ||
}, | ||
"TaskDefExecutionRoleB4775C97": { | ||
"Type": "AWS::IAM::Role", | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "ecs-tasks.amazonaws.com" | ||
} | ||
} | ||
], | ||
"Version": "2012-10-17" | ||
} | ||
} | ||
}, | ||
"TaskDefExecutionRoleDefaultPolicy0DBB737A": { | ||
"Type": "AWS::IAM::Policy", | ||
"Properties": { | ||
"PolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "secretsmanager:GetSecretValue", | ||
"Effect": "Allow", | ||
"Resource": { | ||
"Ref": "SecretA720EF05" | ||
} | ||
} | ||
], | ||
"Version": "2012-10-17" | ||
}, | ||
"PolicyName": "TaskDefExecutionRoleDefaultPolicy0DBB737A", | ||
"Roles": [ | ||
{ | ||
"Ref": "TaskDefExecutionRoleB4775C97" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/@aws-cdk/aws-ecs/test/fargate/integ.secret-json-key.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import * as secretsmanager from '@aws-cdk/aws-secretsmanager'; | ||
import * as cdk from '@aws-cdk/core'; | ||
import * as ecs from '../../lib'; | ||
|
||
const app = new cdk.App(); | ||
const stack = new cdk.Stack(app, 'aws-ecs-integ-secret-json-key'); | ||
|
||
const secret = new secretsmanager.Secret(stack, 'Secret', { | ||
generateSecretString: { | ||
generateStringKey: 'password', | ||
secretStringTemplate: JSON.stringify({ username: 'user '}) | ||
} | ||
}); | ||
|
||
const taskDefinition = new ecs.FargateTaskDefinition(stack, 'TaskDef', { | ||
memoryLimitMiB: 1024, | ||
cpu: 512 | ||
}); | ||
|
||
taskDefinition.addContainer('web', { | ||
image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), | ||
secrets: { | ||
PASSWORD: ecs.Secret.fromSecretsManager(secret, 'password') | ||
} | ||
}); | ||
|
||
app.synth(); |
This file contains 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