Skip to content

Commit

Permalink
feat(ecs): ability to access tag parameter value of TagParameterConta…
Browse files Browse the repository at this point in the history
…inerImage

Allows you to use the tag elsewhere within the container definition (e.g. to inform monitoring services of the release version).

fixes: aws#13202
  • Loading branch information
alastair-watts-avrios committed Mar 2, 2021
1 parent aaec660 commit b6af47b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,20 @@ export class TagParameterContainerImage extends ContainerImage {
},
});
}

/**
* Returns the value of the CloudFormation Parameter that represents the tag of the image
* in the ECR repository.
*/
public get tagParameterValue(): string {
return cdk.Lazy.string({
produce: () => {
if (this.imageTagParameter) {
return this.imageTagParameter.writeAsString;
} else {
throw new Error('TagParameterContainerImage must be used in a container definition when using tagParameterValue');
}
},
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ nodeunitShim({
SynthUtils.synthesize(stack);
}, /TagParameterContainerImage must be used in a container definition when using tagParameterName/);

test.done();
},
'throws an error when tagParameterValue() is used without binding the image'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const repository = new ecr.Repository(stack, 'Repository');
const tagParameterContainerImage = new ecs.TagParameterContainerImage(repository);
new cdk.CfnOutput(stack, 'Output', {
value: tagParameterContainerImage.tagParameterValue,
});

test.throws(() => {
SynthUtils.synthesize(stack);
}, /TagParameterContainerImage must be used in a container definition when using tagParameterValue/);

test.done();
},
},
Expand Down

0 comments on commit b6af47b

Please sign in to comment.