Skip to content
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

chore(release): 1.124.0 #16581

Merged
merged 60 commits into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
fc74110
feat(glue): Job construct (#12506)
humanzz Sep 8, 2021
a4791d3
Merge branch 'master' into merge-back/1.122.0
mergify[bot] Sep 8, 2021
87f62b7
chore(merge-back): 1.122.0 (#16420)
mergify[bot] Sep 9, 2021
1e247d8
fix(apigatewayv2): ApiMapping does not depend on DomainName (#16201)
Sep 9, 2021
f3fc1d5
chore: add breaking changes entry to 1.122.0 release (#16430)
Sep 9, 2021
430f50a
feat(ec2/ecs): `cacheInContext` properties for machine images (#16021)
rix0rrr Sep 9, 2021
cc74f92
feat(assertions): capture matching value (#16426)
Sep 9, 2021
36ff738
fix(core): asset hash of symlinked dir is wrong (#16429)
rix0rrr Sep 9, 2021
38426c9
fix(cloudformation-diff): cdk diff not picking up differences if old/…
vincent-turato Sep 9, 2021
18aff6b
feat(sns): adding support for firehose subscription protocol (#15764)
david-doyle-as24 Sep 10, 2021
deaac4a
feat(neptune): add engine version 1.0.5.0 (#16394)
jumic Sep 10, 2021
3e9f04d
fix(logs): log retention fails with OperationAbortedException (#16083)
ddl-denis-parnovskiy Sep 10, 2021
7229ad2
docs(pipelines): CLI not compatible with the library used by your app…
rix0rrr Sep 12, 2021
a732078
docs(assets): tarball path should be absolute (#15750)
Sep 12, 2021
066bcb1
feat(batch): fargate support for jobs (#15848)
DDynamic Sep 12, 2021
367a24a
chore(deps): bump version of `conventional-commits-parser` (#16470)
rix0rrr Sep 13, 2021
c68d059
chore(deps): bump axios from 0.21.1 to 0.21.4 (#16421)
dependabot[bot] Sep 13, 2021
1df0e1b
chore(deps): bump `proxy-agent` to `5.0.0` (#16469)
rix0rrr Sep 13, 2021
5835c2d
chore(deps): Bump tar from 4.4.16 to 4.4.19 (#16304)
dependabot[bot] Sep 13, 2021
fed30fc
feat(assertions): match into serialized json (#16456)
Sep 13, 2021
d5dd2d0
chore(rds): add MariaDB ver 10.5.12, 10.4.21, 10.3.31, 10.2.40 and Au…
jumic Sep 13, 2021
a9d5118
feat(redshift): manage database users and tables via cdk (#15931)
BenChaimberg Sep 13, 2021
b3eafc2
feat(lambda): configure workdir for docker image based functions (#16…
blaenk Sep 14, 2021
9bbfd18
feat(lambda): use bundling docker image from ECR public for dotnet an…
jogold Sep 14, 2021
23d9b6a
fix(config): the IGW mapping to correct resource type (#16464)
Pandafriendd Sep 14, 2021
d5a68cd
chore: update autolabeler to fork
peterwoodworth Sep 14, 2021
8e311b2
chore: update autolabeler to fork
peterwoodworth Sep 14, 2021
c890dd0
chore: update autolabeler to fork
peterwoodworth Sep 14, 2021
15a3db8
chore: update autolabeler to fork
peterwoodworth Sep 14, 2021
cfbcfda
chore: update autolabeler to fork
peterwoodworth Sep 14, 2021
2737119
feat(s3-deployment): enable efs support for handling large files in l…
keshav0891 Sep 15, 2021
7d3b90b
feat(stepfunctions-tasks): support Associate Workflow Executions on S…
kaizencc Sep 15, 2021
950e875
fix(SSM API docs): Typo `SecretString` -> `SecureString` and note how…
ryparker Sep 15, 2021
33cce1f
Merge branch 'master' into master
NGL321 Sep 15, 2021
28875f9
feat(cfnspec): cloudformation spec v41.1.0 (#16472)
aws-cdk-automation Sep 16, 2021
ae4aa95
chore: migrate more modules to jest (#16494)
Sep 16, 2021
532a72b
feat(assertions): findXxx() APIs now includes the logical id as part …
kaizencc Sep 16, 2021
baa863b
Merge branch 'master' into master
peterwoodworth Sep 16, 2021
015e0c8
Merge pull request #16516 from peterwoodworth/master
peterwoodworth Sep 16, 2021
0e6a6a3
chore: update autolabeler config
peterwoodworth Sep 17, 2021
40333f7
Merge branch 'master' into merge-back/1.123.0
mergify[bot] Sep 17, 2021
327c6b2
chore(merge-back): 1.123.0 (#16521)
mergify[bot] Sep 17, 2021
cafe825
chore: migrate even more modules to jest (#16504)
kaizencc Sep 17, 2021
124a7a1
feat(cfnspec): cloudformation spec v41.1.0 (#16524)
aws-cdk-automation Sep 17, 2021
c6c5941
feat(ecs-service-extensions): Publish Extension (#16326)
upparekh Sep 17, 2021
8307164
Merge branch 'master' into master
peterwoodworth Sep 17, 2021
b449f14
Merge pull request #16520 from peterwoodworth/master
peterwoodworth Sep 17, 2021
efe5112
docs(pipelines): typo on formatting (#16534)
iOnline247 Sep 17, 2021
e047bd8
feat(cfnspec): cloudformation spec v41.2.0 (#16550)
aws-cdk-automation Sep 20, 2021
68fb63e
chore(rds): add Aurora MySQL engine 2.10.0 (#16548)
kimxogus Sep 20, 2021
1e9d8be
feat(rds): region replication for generated secrets (#16497)
jogold Sep 20, 2021
2a629dd
feat(pipeline): allow enabling KMS key rotation for cross-region Stac…
pboeder Sep 20, 2021
ca29584
docs(pipelines): fix small issues in README (#16526)
rix0rrr Sep 21, 2021
e6a104c
docs(aws-ecr-assets): correct reference from AWS ECR to Amazon ECR (#…
SathyaBhat Sep 21, 2021
3a486c4
chore: migrate more modules to jest (#16533)
kaizencc Sep 21, 2021
ac503cb
chore(ec2): deprecate security group name accessor (#16116)
mprencipe Sep 21, 2021
cdbd65d
fix(ec2): set proper role for --role argument of cfn-init (#16503)
maafk Sep 21, 2021
643e5ee
fix(route53resolver): FirewallDomainList throws with wildcard domains…
jogold Sep 21, 2021
ef3b6d0
chore: transfer BenChaimberg ownership over to kaizen3031593 and comc…
kaizencc Sep 21, 2021
299ed15
chore(release): 1.124.0
Sep 21, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
417 changes: 209 additions & 208 deletions .github/workflows/issue-label-assign.yml

Large diffs are not rendered by default.

50 changes: 50 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,49 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [1.124.0](https://github.com/aws/aws-cdk/compare/v1.123.0...v1.124.0) (2021-09-21)


### ⚠ BREAKING CHANGES TO EXPERIMENTAL FEATURES

* **assertions:** the `findResources()` API previously returned a list of resources, but now returns a map of logical id to resource.
* **assertions:** the `findOutputs()` API previously returned a list of outputs, but now returns a map of logical id to output.
* **assertions:** the `findMappings()` API previously returned a list of mappings, but now returns a map of logical id to mapping.

### Features

* **assertions:** capture matching value ([#16426](https://github.com/aws/aws-cdk/issues/16426)) ([cc74f92](https://github.com/aws/aws-cdk/commit/cc74f92f275a338cb53caa7d6f124ab0dd960f0b))
* **assertions:** findXxx() APIs now includes the logical id as part of its result ([#16454](https://github.com/aws/aws-cdk/issues/16454)) ([532a72b](https://github.com/aws/aws-cdk/commit/532a72b133e6ebd0c7b8b7c65b273bb0e6f3293c))
* **assertions:** match into serialized json ([#16456](https://github.com/aws/aws-cdk/issues/16456)) ([fed30fc](https://github.com/aws/aws-cdk/commit/fed30fc815bac1006003524ac6232778f3c3babe))
* **batch:** fargate support for jobs ([#15848](https://github.com/aws/aws-cdk/issues/15848)) ([066bcb1](https://github.com/aws/aws-cdk/commit/066bcb1e5d53192bd465190c8a4f81c5838987f4)), closes [#13591](https://github.com/aws/aws-cdk/issues/13591) [#13590](https://github.com/aws/aws-cdk/issues/13590) [#13591](https://github.com/aws/aws-cdk/issues/13591)
* **cfnspec:** cloudformation spec v41.1.0 ([#16472](https://github.com/aws/aws-cdk/issues/16472)) ([28875f9](https://github.com/aws/aws-cdk/commit/28875f9dda4911d3a2fcfcdc6e6d8358bee7c689))
* **cfnspec:** cloudformation spec v41.1.0 ([#16524](https://github.com/aws/aws-cdk/issues/16524)) ([124a7a1](https://github.com/aws/aws-cdk/commit/124a7a1c20981c72bfdce0c857c87c46c6cb5f51))
* **cfnspec:** cloudformation spec v41.2.0 ([#16550](https://github.com/aws/aws-cdk/issues/16550)) ([e047bd8](https://github.com/aws/aws-cdk/commit/e047bd80ab08f49a22408eb8c5401f4306747eff))
* **ec2/ecs:** `cacheInContext` properties for machine images ([#16021](https://github.com/aws/aws-cdk/issues/16021)) ([430f50a](https://github.com/aws/aws-cdk/commit/430f50a546e9c575f8cdbd259367e440d985e68f)), closes [#12484](https://github.com/aws/aws-cdk/issues/12484)
* **ecs-service-extensions:** Publish Extension ([#16326](https://github.com/aws/aws-cdk/issues/16326)) ([c6c5941](https://github.com/aws/aws-cdk/commit/c6c594159c7fbda66f40fe8666f70b6806bb2d5e))
* **glue:** Job construct ([#12506](https://github.com/aws/aws-cdk/issues/12506)) ([fc74110](https://github.com/aws/aws-cdk/commit/fc74110ff7eae544d9cfc11b2f6779169f17d145)), closes [#12443](https://github.com/aws/aws-cdk/issues/12443)
* **lambda:** configure workdir for docker image based functions ([#16111](https://github.com/aws/aws-cdk/issues/16111)) ([b3eafc2](https://github.com/aws/aws-cdk/commit/b3eafc2dc61ed69de20196fa08a4df3c29ecc894))
* **lambda:** use bundling docker image from ECR public for dotnet and go runtimes ([#16281](https://github.com/aws/aws-cdk/issues/16281)) ([9bbfd18](https://github.com/aws/aws-cdk/commit/9bbfd185c2383612e2be7317a091b72cc5e7a120))
* **neptune:** add engine version 1.0.5.0 ([#16394](https://github.com/aws/aws-cdk/issues/16394)) ([deaac4a](https://github.com/aws/aws-cdk/commit/deaac4a16e957bd046f24a6c26d735fc4cf980bd)), closes [#16388](https://github.com/aws/aws-cdk/issues/16388)
* **pipeline:** allow enabling KMS key rotation for cross-region Stacks ([#16468](https://github.com/aws/aws-cdk/issues/16468)) ([2a629dd](https://github.com/aws/aws-cdk/commit/2a629dd7a86cc36c3a503bfc5957880c9edd4d49)), closes [#14381](https://github.com/aws/aws-cdk/issues/14381)
* **rds:** region replication for generated secrets ([#16497](https://github.com/aws/aws-cdk/issues/16497)) ([1e9d8be](https://github.com/aws/aws-cdk/commit/1e9d8be0a81e1f875bf8b31c701e1069bb98728e)), closes [#16480](https://github.com/aws/aws-cdk/issues/16480)
* **redshift:** manage database users and tables via cdk ([#15931](https://github.com/aws/aws-cdk/issues/15931)) ([a9d5118](https://github.com/aws/aws-cdk/commit/a9d51185a144cd4962c85227ae5b904510399fa4)), closes [#9815](https://github.com/aws/aws-cdk/issues/9815)
* **s3-deployment:** enable efs support for handling large files in lambda ([#15220](https://github.com/aws/aws-cdk/issues/15220)) ([2737119](https://github.com/aws/aws-cdk/commit/27371197a24ce6c9212fc99e120c5d77fa08065e))
* **sns:** adding support for firehose subscription protocol ([#15764](https://github.com/aws/aws-cdk/issues/15764)) ([18aff6b](https://github.com/aws/aws-cdk/commit/18aff6b4c0a5e17c64685ac384b243c16cd910f1))
* **stepfunctions-tasks:** support Associate Workflow Executions on StepFunctionsStartExecution via associateWithParent property ([#16475](https://github.com/aws/aws-cdk/issues/16475)) ([7d3b90b](https://github.com/aws/aws-cdk/commit/7d3b90b2097aa9b7170a77befcee5822d5d0c3e7)), closes [#14778](https://github.com/aws/aws-cdk/issues/14778)


### Bug Fixes

* **apigatewayv2:** ApiMapping does not depend on DomainName ([#16201](https://github.com/aws/aws-cdk/issues/16201)) ([1e247d8](https://github.com/aws/aws-cdk/commit/1e247d89adbc09ff79b87753fcd78b238a6752e8)), closes [#15464](https://github.com/aws/aws-cdk/issues/15464)
* **cloudformation-diff:** cdk diff not picking up differences if old/new value is in format n.n.n ([#16050](https://github.com/aws/aws-cdk/issues/16050)) ([38426c9](https://github.com/aws/aws-cdk/commit/38426c985d5e0713bbbf14fa639520eca6294124)), closes [#15935](https://github.com/aws/aws-cdk/issues/15935)
* **config:** the IGW mapping to correct resource type ([#16464](https://github.com/aws/aws-cdk/issues/16464)) ([23d9b6a](https://github.com/aws/aws-cdk/commit/23d9b6a7d5b213e4a1ba4a71984e8e19e3657bd7)), closes [#16463](https://github.com/aws/aws-cdk/issues/16463)
* **core:** asset hash of symlinked dir is wrong ([#16429](https://github.com/aws/aws-cdk/issues/16429)) ([36ff738](https://github.com/aws/aws-cdk/commit/36ff73809a37998e15176cb8815c118e7ea0c295))
* **ec2:** set proper role for --role argument of cfn-init ([#16503](https://github.com/aws/aws-cdk/issues/16503)) ([cdbd65d](https://github.com/aws/aws-cdk/commit/cdbd65dc525147810650b4c32d48664a38abede1)), closes [#16501](https://github.com/aws/aws-cdk/issues/16501)
* **logs:** log retention fails with OperationAbortedException ([#16083](https://github.com/aws/aws-cdk/issues/16083)) ([3e9f04d](https://github.com/aws/aws-cdk/commit/3e9f04dbbd7aadb8ab4394fefd6281f1d6d30fe0)), closes [aws#15709](https://github.com/aws/aws/issues/15709)
* **route53resolver:** FirewallDomainList throws with wildcard domains ([#16538](https://github.com/aws/aws-cdk/issues/16538)) ([643e5ee](https://github.com/aws/aws-cdk/commit/643e5ee519095968a758942220f1e3a6c20f54b3)), closes [#16527](https://github.com/aws/aws-cdk/issues/16527)
* **SSM API docs:** Typo `SecretString` -> `SecureString` and note how SecureStrings cannot be created via CDK ([#16228](https://github.com/aws/aws-cdk/issues/16228)) ([950e875](https://github.com/aws/aws-cdk/commit/950e875bfb431c051b5ee2fd405aaf7f2b47bfeb))

## [1.123.0](https://github.com/aws/aws-cdk/compare/v1.122.0...v1.123.0) (2021-09-16)


Expand All @@ -11,6 +54,12 @@ All notable changes to this project will be documented in this file. See [standa

## [1.122.0](https://github.com/aws/aws-cdk/compare/v1.121.0...v1.122.0) (2021-09-08)

### ⚠ BREAKING CHANGES TO EXPERIMENTAL FEATURES

* **assertions:** `hasOutput(props: any)` becomes `hasOutput(logicalId: string, props: any)`
* **assertions:** `findOutputs(props: any = {})` becomes `findOutputs(logicalId: string, props: any = {})`
* **assertions:** `hasMapping(props: any)` becomes `hasMapping(logicalId: string, props: any)`
* **assertions:** `findMappings(props: any = {})` becomes `findMappings(logicalId: string, props: any = {})`

### Features

Expand All @@ -31,6 +80,7 @@ All notable changes to this project will be documented in this file. See [standa
### Bug Fixes

* **apigatewayv2:** some methods of the `defaultStage` are not available without casting it to `IHttpStage` ([#15607](https://github.com/aws/aws-cdk/issues/15607)) ([27a0113](https://github.com/aws/aws-cdk/commit/27a0113ac68a05360faa22fa8897609f2f90b764))
* **assertions:** output and mapping assertions do not accept logical id ([#16329](https://github.com/aws/aws-cdk/issues/16329)), closes [#16242](https://github.com/aws/aws-cdk/issues/16242)
* **assets:** run executable command of container assets in cloud assembly root directory ([#16094](https://github.com/aws/aws-cdk/issues/16094)) ([c2852c9](https://github.com/aws/aws-cdk/commit/c2852c9c524a639a312bf296f7f23b0e3b112f6b)), closes [#15721](https://github.com/aws/aws-cdk/issues/15721)
* **autoscaling:** EbsDeviceVolumeType.IO2 is not a valid CloudFormation value ([#16028](https://github.com/aws/aws-cdk/issues/16028)) ([492d33b](https://github.com/aws/aws-cdk/commit/492d33b27bc5b935e3da75f0bddd875bb6f9c15d)), closes [#16027](https://github.com/aws/aws-cdk/issues/16027)
* **cli:** 'deploy' and 'diff' silently does nothing when given unknown stack name ([#16150](https://github.com/aws/aws-cdk/issues/16150)) ([74776f3](https://github.com/aws/aws-cdk/commit/74776f393462f7e7d23cb1953ef786a823adc896)), closes [#15866](https://github.com/aws/aws-cdk/issues/15866)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ nyc.config.js
!.eslintrc.js

junit.xml

!jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ tsconfig.json
**/cdk.out
junit.xml

test/
test/
jest.config.js
78 changes: 76 additions & 2 deletions packages/@aws-cdk-containers/ecs-service-extensions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ The `Service` construct provided by this module can be extended with optional `S
- [AWS AppMesh](https://aws.amazon.com/app-mesh/) for adding your application to a service mesh
- [Application Load Balancer](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html), for exposing your service to the public
- [AWS FireLens](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_firelens.html), for filtering and routing application logs
- Queue to allow your service to consume messages from an SQS Queue which is populated by one or more SNS Topics that it is subscribed to
- [Injecter Extension](#injecter-extension), for allowing your service connect to other AWS services by granting permission and injecting environment variables
- [Queue Extension](#queue-extension), for allowing your service to consume messages from an SQS Queue which can be populated by one or more SNS Topics that it is subscribed to
- [Community Extensions](#community-extensions), providing support for advanced use cases

The `ServiceExtension` class is an abstract class which you can also implement in
Expand Down Expand Up @@ -322,9 +323,28 @@ const environment = Environment.fromEnvironmentAttributes(stack, 'Environment',

```

## Injecter Extension

This service extension accepts a list of `Injectable` resources. It grants access to these resources and adds the necessary environment variables to the tasks that are part of the service.

For example, an `InjectableTopic` is an SNS Topic that grants permission to the task role and adds the topic ARN as an environment variable to the task definition.

### Publishing to SNS Topics

You can use this extension to set up publishing permissions for SNS Topics.

```ts
nameDescription.add(new InjecterExtension({
injectables: [new InjectableTopic({
// SNS Topic the service will publish to
topic: new sns.Topic(stack, 'my-topic'),
})],
}));
```

## Queue Extension

This service extension creates a default SQS Queue `eventsQueue` for the service (if not provided) and accepts a list of `ISubscribable` objects that the `eventsQueue` can subscribe to. The service extension creates the subscriptions and sets up permissions for the service to consume messages from the SQS Queue.
This service extension creates a default SQS Queue `eventsQueue` for the service (if not provided) and optionally also accepts list of `ISubscribable` objects that the `eventsQueue` can subscribe to. The service extension creates the subscriptions and sets up permissions for the service to consume messages from the SQS Queue.

### Setting up SNS Topic Subscriptions for SQS Queues

Expand Down Expand Up @@ -356,6 +376,60 @@ nameDescription.add(new QueueExtension({
}));
```

## Publish/Subscribe Service Pattern

The [Publish/Subscribe Service Pattern](https://aws.amazon.com/pub-sub-messaging/) is used for implementing asynchronous communication between services. It involves 'publisher' services emitting events to SNS Topics, which are passed to subscribed SQS queues and then consumed by 'worker' services.

The following example adds the `InjecterExtension` to a `Publisher` Service which can publish events to an SNS Topic and adds the `QueueExtension` to a `Worker` Service which can poll its `eventsQueue` to consume messages populated by the topic.

```ts
const environment = new Environment(stack, 'production');

const pubServiceDescription = new ServiceDescription();
pubServiceDescription.add(new Container({
cpu: 256,
memoryMiB: 512,
trafficPort: 80,
image: ecs.ContainerImage.fromRegistry('sns-publish'),
}));

const myTopic = new sns.Topic(stack, 'myTopic');

// Add the `InjecterExtension` to the service description to allow publishing events to `myTopic`
pubServiceDescription.add(new InjecterExtension({
injectables: [new InjectableTopic({
topic: myTopic,
}],
}));

// Create the `Publisher` Service
new Service(stack, 'Publisher', {
environment: environment,
serviceDescription: pubServiceDescription,
});

const subServiceDescription = new ServiceDescription();
subServiceDescription.add(new Container({
cpu: 256,
memoryMiB: 512,
trafficPort: 80,
image: ecs.ContainerImage.fromRegistry('sqs-reader'),
}));

// Add the `QueueExtension` to the service description to subscribe to `myTopic`
subServiceDescription.add(new QueueExtension({
subscriptions: [new TopicSubscription({
topic: myTopic,
}],
}));

// Create the `Worker` Service
new Service(stack, 'Worker', {
environment: environment,
serviceDescription: subServiceDescription,
});
```

## Community Extensions

We encourage the development of Community Service Extensions that support
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const baseConfig = require('../../../tools/cdk-build-tools/config/jest.config');
module.exports = {
...baseConfig,
coverageThreshold: {
global: {
branches: 70,
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export * from './cloudwatch-agent';
export * from './scale-on-cpu-utilization';
export * from './xray';
export * from './assign-public-ip';
export * from './queue';
export * from './queue';
export * from './injecter';
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
import * as ecs from '@aws-cdk/aws-ecs';
import * as sns from '@aws-cdk/aws-sns';
import { Service } from '../service';
import { Container } from './container';
import { ContainerMutatingHook, ServiceExtension } from './extension-interfaces';

// Keep this import separate from other imports to reduce chance for merge conflicts with v2-main
// eslint-disable-next-line no-duplicate-imports, import/order
import { Construct } from '@aws-cdk/core';

/**
* An interface that will be implemented by all the resources that can be published events or written data to.
*/
export interface Injectable {
environmentVariables(): { [key: string]: string };
}

/**
* An interface that will be implemented by all the injectable resources that need to grant permissions to the task role.
*/
export interface GrantInjectable extends Injectable {
grant(taskDefinition: ecs.TaskDefinition): void;
}

/**
* The settings for the `InjectableTopic` class.
*/
export interface InjectableTopicProps {
/**
* The SNS Topic to publish events to.
*/
readonly topic: sns.ITopic;
}

/**
* The `InjectableTopic` class represents SNS Topic resource that can be published events to by the parent service.
*/

export class InjectableTopic implements GrantInjectable {
public readonly topic: sns.ITopic;

constructor(props: InjectableTopicProps) {
this.topic = props.topic;
}

public grant(taskDefinition: ecs.TaskDefinition) {
this.topic.grantPublish(taskDefinition.taskRole);
}

public environmentVariables(): { [key: string]: string } {
let environment: { [key: string]: string } = {};
environment[`${this.topic.node.id.toUpperCase()}_TOPIC_ARN`] = this.topic.topicArn;
return environment;
}
}

/**
* The settings for the Injecter extension.
*/
export interface InjecterExtensionProps {
/**
* The list of injectable resources for this service.
*/
readonly injectables: Injectable[];
}

/**
* Settings for the hook which mutates the application container
* to add the injectable resource environment variables.
*/
interface ContainerMutatingProps {
/**
* The resource environment variables to be added to the container environment.
*/
readonly environment: { [key: string]: string };
}

/**
* This hook modifies the application container's environment to
* add the injectable resource environment variables.
*/
class InjecterExtensionMutatingHook extends ContainerMutatingHook {
private environment: { [key: string]: string };

constructor(props: ContainerMutatingProps) {
super();
this.environment = props.environment;
}

public mutateContainerDefinition(props: ecs.ContainerDefinitionOptions): ecs.ContainerDefinitionOptions {
return {
...props,

environment: { ...(props.environment || {}), ...this.environment },
} as ecs.ContainerDefinitionOptions;
}
}

/**
* This extension accepts a list of `Injectable` resources that the parent service can publish events or write data to.
* It sets up the corresponding permissions for the task role of the parent service.
*/
export class InjecterExtension extends ServiceExtension {
private props: InjecterExtensionProps;

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

constructor(props: InjecterExtensionProps) {
super('injecter');

this.props = props;
}

// @ts-ignore - Ignore unused params that are required for abstract class extend
public prehook(service: Service, scope: Construct) {
this.parentService = service;

for (const injectable of this.props.injectables) {
for (const [key, val] of Object.entries(injectable.environmentVariables())) {
this.environment[key] = val;
}
}
}

/**
* Add hooks to the main application extension so that it is modified to
* add the injectable resource environment variables to the container environment.
*/
public addHooks() {
const container = this.parentService.serviceDescription.get('service-container') as Container;

if (!container) {
throw new Error('Injecter Extension requires an application extension');
}

container.addContainerMutatingHook(new InjecterExtensionMutatingHook({
environment: this.environment,
}));
}

/**
* After the task definition has been created, this hook grants the required permissions to the task role for the
* parent service.
*
* @param taskDefinition The created task definition
*/
public useTaskDefinition(taskDefinition: ecs.TaskDefinition) {
for (const injectable of this.props.injectables) {
if ((injectable as GrantInjectable).grant !== undefined) {
(injectable as GrantInjectable).grant(taskDefinition);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@
"organization": true
},
"license": "Apache-2.0",
"cdk-build": {
"jest": true
},
"devDependencies": {
"@types/nodeunit": "^0.0.32",
"@types/jest": "^26.0.24",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"cfn2ts": "0.0.0",
"jest": "^26.6.3",
"nodeunit": "^0.11.3",
"pkglint": "0.0.0",
"@aws-cdk/assert-internal": "0.0.0"
},
Expand Down
Loading