Skip to content

feat(cdk): forward awslogs driver options on addFargateService#8

Open
hyuntony wants to merge 2 commits intoshellscape:masterfrom
hyuntony:feat/cdk-fargate-awslogs-options
Open

feat(cdk): forward awslogs driver options on addFargateService#8
hyuntony wants to merge 2 commits intoshellscape:masterfrom
hyuntony:feat/cdk-fargate-awslogs-options

Conversation

@hyuntony
Copy link
Copy Markdown
Contributor

Summary

Adds an awslogs?: Partial<AwsLogDriverProps> option to addFargateService. The provided options are spread into the underlying LogDriver.awsLogs(...) call after the function-side defaults (streamPrefix: <serviceName>, logRetention: ONE_WEEK), so callers can override anything CDK exposes without losing the defaults.

Motivation

Currently the only path to tune awslogs driver options (most often mode: NON_BLOCKING and maxBufferSize for high-volume Node.js services where stdout backpressure can stall the event loop — see AWS's blog post) is to reach past addFargateService and call addPropertyOverride on the L1 CfnTaskDefinition. That's noisy, untyped, and breaks if the L2 internals change.

Usage

import { AwsLogDriverMode } from 'aws-cdk-lib/aws-ecs';
import { Size } from 'aws-cdk-lib';

addFargateService({
  // ...
  awslogs: {
    mode: AwsLogDriverMode.NON_BLOCKING,
    maxBufferSize: Size.mebibytes(4),
  },
});

Partial<AwsLogDriverProps> means callers can also tune multilinePattern, datetimeFormat, logRetention, etc., or override the function-side streamPrefix if they really want to.

Compatibility

Backwards compatible — awslogs is optional. Existing callers see no behavior change. CDK validates maxBufferSize requires mode: NON_BLOCKING at synth time, so misuse fails loudly.

Adds an `awslogs?: Partial<AwsLogDriverProps>` option that's spread into
the underlying `LogDriver.awsLogs(...)` call after the function-side
defaults (streamPrefix: serviceName, logRetention: ONE_WEEK).

Lets callers tune the awslogs driver — typically `mode` and
`maxBufferSize` for non-blocking delivery on high-volume Node services
where stdout backpressure can stall the event loop — without losing the
function's defaults and without reaching past the L2 via a property
override escape hatch on the task definition.
…p collision

Two follow-ups from review feedback:

- Rename `awslogs` → `awsLogs` to match the camelCase convention used by
  every other field in `AddServiceOptions`.
- Skip the function's default `logRetention: ONE_WEEK` when the caller
  supplies their own `logGroup`. CDK's `AwsLogDriver` constructor throws
  `Cannot specify both 'logGroup' and 'logRetentionDays'` at synth time,
  so previously a caller passing only `{ logGroup: myGroup }` would have
  silently hit that validation despite reasonable intent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant