diff --git a/packages/@aws-cdk/aws-ecs/README.md b/packages/@aws-cdk/aws-ecs/README.md index 06b37fd118b70..0c34e9dfe8f2e 100644 --- a/packages/@aws-cdk/aws-ecs/README.md +++ b/packages/@aws-cdk/aws-ecs/README.md @@ -525,7 +525,7 @@ const taskDefinition = new ecs.Ec2TaskDefinition(this, 'TaskDef'); taskDefinition.addContainer('TheContainer', { image: ecs.ContainerImage.fromAsset(path.resolve(__dirname, '..', 'eventhandler-image')), memoryLimitMiB: 256, - logging: new ecs.AwsLogDriver({ streamPrefix: 'EventDemo' }) + logging: new ecs.AwsLogDriver({ streamPrefix: 'EventDemo', mode: AwsLogDriverMode.NON_BLOCKING }) }); // An Rule that describes the event trigger (in this case a scheduled run) diff --git a/packages/@aws-cdk/aws-ecs/lib/log-drivers/aws-log-driver.ts b/packages/@aws-cdk/aws-ecs/lib/log-drivers/aws-log-driver.ts index 705c4ed7fcb72..e6da02b29797e 100644 --- a/packages/@aws-cdk/aws-ecs/lib/log-drivers/aws-log-driver.ts +++ b/packages/@aws-cdk/aws-ecs/lib/log-drivers/aws-log-driver.ts @@ -8,6 +8,23 @@ import { removeEmpty } from './utils'; // eslint-disable-next-line import { Construct as CoreConstruct } from '@aws-cdk/core'; +/** + * awslogs provides two modes for delivering messages from the container to the log driver + */ +export enum AwsLogDriverMode { + + /** + * (default) direct, blocking delivery from container to driver. + */ + BLOCKING = 'blocking', + + /** + * The non-blocking message delivery mode prevents applications from blocking due to logging back pressure. + * Applications are likely to fail in unexpected ways when STDERR or STDOUT streams block. + */ + NON_BLOCKING = 'non-blocking' +} + /** * Specifies the awslogs log driver configuration options. */ @@ -62,6 +79,13 @@ export interface AwsLogDriverProps { * @default - No multiline matching. */ readonly multilinePattern?: string; + + /** + * The delivery mode of log messages from the container to awslogs. + * + * @default - AwsLogDriverMode.BLOCKING + */ + readonly mode?: AwsLogDriverMode; } /** @@ -106,6 +130,7 @@ export class AwsLogDriver extends LogDriver { 'awslogs-region': Stack.of(containerDefinition).region, 'awslogs-datetime-format': this.props.datetimeFormat, 'awslogs-multiline-pattern': this.props.multilinePattern, + 'mode': this.props.mode, }), }; } diff --git a/packages/@aws-cdk/aws-ecs/test/aws-log-driver.test.ts b/packages/@aws-cdk/aws-ecs/test/aws-log-driver.test.ts index d0aec83a2e36d..8a802ac72014b 100644 --- a/packages/@aws-cdk/aws-ecs/test/aws-log-driver.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/aws-log-driver.test.ts @@ -25,6 +25,7 @@ nodeunitShim({ logRetention: logs.RetentionDays.ONE_MONTH, multilinePattern: 'pattern', streamPrefix: 'hello', + mode: ecs.AwsLogDriverMode.NON_BLOCKING, }), }); @@ -44,6 +45,7 @@ nodeunitShim({ 'awslogs-region': { Ref: 'AWS::Region' }, 'awslogs-datetime-format': 'format', 'awslogs-multiline-pattern': 'pattern', + 'mode': 'non-blocking', }, }, },