Skip to content

Commit

Permalink
Merge branch 'master' into update-cfnspec
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Dec 13, 2021
2 parents 3929a95 + 93fafc5 commit 6d4d112
Show file tree
Hide file tree
Showing 26 changed files with 1,611 additions and 118 deletions.
16 changes: 12 additions & 4 deletions .mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ pull_request_rules:
queue:
name: default
method: squash
commit_message: title+body
commit_message_template: |-
{{ title }} (#{{ number }})
{{ body }}
conditions:
- base!=release
- -title~=(WIP|wip)
Expand All @@ -40,7 +42,9 @@ pull_request_rules:
queue:
name: default
method: squash
commit_message: title+body
commit_message_template: |-
{{ title }} (#{{ number }})
{{ body }}
conditions:
- base!=release
- -title~=(WIP|wip)
Expand All @@ -62,7 +66,9 @@ pull_request_rules:
queue:
name: default
method: merge
commit_message: title+body
commit_message_template: |-
{{ title }} (#{{ number }})
{{ body }}
conditions:
- -title~=(WIP|wip)
- -label~=(blocked|do-not-merge)
Expand Down Expand Up @@ -106,7 +112,9 @@ pull_request_rules:
queue:
name: default
method: squash
commit_message: title+body
commit_message_template: |-
{{ title }} (#{{ number }})
{{ body }}
conditions:
- -title~=(WIP|wip)
- -label~=(blocked|do-not-merge)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class EdgeFunction extends Resource implements lambda.IVersion {
public readonly permissionsNode: ConstructNode;
public readonly role?: iam.IRole;
public readonly version: string;
public readonly architecture: lambda.Architecture;

private readonly _edgeFunction: lambda.Function;

Expand All @@ -66,6 +67,7 @@ export class EdgeFunction extends Resource implements lambda.IVersion {
this.grantPrincipal = this._edgeFunction.role!;
this.permissionsNode = this._edgeFunction.permissionsNode;
this.version = lambda.extractQualifierFromArn(this.functionArn);
this.architecture = this._edgeFunction.architecture;

this.node.defaultChild = this._edgeFunction;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-ecs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ declare const parameter: ssm.StringParameter;
declare const taskDefinition: ecs.TaskDefinition;
declare const s3Bucket: s3.Bucket;

taskDefinition.addContainer('container', {
const newContainer = taskDefinition.addContainer('container', {
image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
memoryLimitMiB: 1024,
environment: { // clear text, not for sensitive data
Expand All @@ -421,6 +421,7 @@ taskDefinition.addContainer('container', {
PARAMETER: ecs.Secret.fromSsmParameter(parameter),
},
});
newContainer.addEnvironment('QUEUE_NAME', 'MyQueue');
```

The task execution role is automatically granted read permissions on the secrets/parameters. Support for environment
Expand Down
17 changes: 16 additions & 1 deletion packages/@aws-cdk/aws-ecs/lib/container-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ export class ContainerDefinition extends CoreConstruct {

private readonly secrets?: CfnTaskDefinition.SecretProperty[];

private readonly environment: { [key: string]: string };

/**
* Constructs a new instance of the ContainerDefinition class.
*/
Expand Down Expand Up @@ -457,6 +459,12 @@ export class ContainerDefinition extends CoreConstruct {
}
}

if (props.environment) {
this.environment = { ...props.environment };
} else {
this.environment = {};
}

if (props.environmentFiles) {
this.environmentFiles = [];

Expand Down Expand Up @@ -547,6 +555,13 @@ export class ContainerDefinition extends CoreConstruct {
}));
}

/**
* This method adds an environment variable to the container.
*/
public addEnvironment(name: string, value: string) {
this.environment[name] = value;
}

/**
* This method adds one or more resources to the container.
*/
Expand Down Expand Up @@ -669,7 +684,7 @@ export class ContainerDefinition extends CoreConstruct {
volumesFrom: cdk.Lazy.any({ produce: () => this.volumesFrom.map(renderVolumeFrom) }, { omitEmptyArray: true }),
workingDirectory: this.props.workingDirectory,
logConfiguration: this.logDriverConfig,
environment: this.props.environment && renderKV(this.props.environment, 'name', 'value'),
environment: this.environment && Object.keys(this.environment).length ? renderKV(this.environment, 'name', 'value') : undefined,
environmentFiles: this.environmentFiles && renderEnvironmentFiles(this.environmentFiles),
secrets: this.secrets,
extraHosts: this.props.extraHosts && renderKV(this.props.extraHosts, 'hostname', 'ipAddress'),
Expand Down
34 changes: 33 additions & 1 deletion packages/@aws-cdk/aws-ecs/test/container-definition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -690,13 +690,14 @@ describe('container definition', () => {
const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'TaskDef');

// WHEN
taskDefinition.addContainer('cont', {
const container = taskDefinition.addContainer('cont', {
image: ecs.ContainerImage.fromRegistry('test'),
memoryLimitMiB: 1024,
environment: {
TEST_ENVIRONMENT_VARIABLE: 'test environment variable value',
},
});
container.addEnvironment('SECOND_ENVIRONEMENT_VARIABLE', 'second test value');

// THEN
expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', {
Expand All @@ -705,6 +706,37 @@ describe('container definition', () => {
Environment: [{
Name: 'TEST_ENVIRONMENT_VARIABLE',
Value: 'test environment variable value',
},
{
Name: 'SECOND_ENVIRONEMENT_VARIABLE',
Value: 'second test value',
}],
},
],
});


});

test('can add environment variables to container definition with no environment', () => {
// GIVEN
const stack = new cdk.Stack();
const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'TaskDef');

// WHEN
const container = taskDefinition.addContainer('cont', {
image: ecs.ContainerImage.fromRegistry('test'),
memoryLimitMiB: 1024,
});
container.addEnvironment('SECOND_ENVIRONEMENT_VARIABLE', 'second test value');

// THEN
expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', {
ContainerDefinitions: [
{
Environment: [{
Name: 'SECOND_ENVIRONEMENT_VARIABLE',
Value: 'second test value',
}],
},
],
Expand Down
Loading

0 comments on commit 6d4d112

Please sign in to comment.