Skip to content

feat(ecs): add L2 support for service monitoring configuration - #38402

Open
kawaaaas wants to merge 3 commits into
aws:mainfrom
kawaaaas:feat/add-ecs-monitoring-configuration
Open

feat(ecs): add L2 support for service monitoring configuration#38402
kawaaaas wants to merge 3 commits into
aws:mainfrom
kawaaaas:feat/add-ecs-monitoring-configuration

Conversation

@kawaaaas

@kawaaaas kawaaaas commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Issue # (if applicable)

N/A

Reason for this change

AWS::ECS::Service recently added a Monitoring property that lets a service publish its CPUUtilization and MemoryUtilization CloudWatch metrics at 20-second resolution instead of the default 60 seconds, enabling faster-reacting auto scaling. The L1 (CfnService.monitoring) was already generated, but there was no L2 surface for it, so users had no typed way to configure this.

Description of changes

Added monitoring to BaseServiceOptions (available on both Ec2Service and FargateService), backed by two new strongly-typed constructs instead of exposing the raw CFN shape directly:

  • ServiceMetricName (enum)
    CPU_UTILIZATION | MEMORY_UTILIZATION — mirrors the CFN MetricNames allowed values.

  • MetricResolution (enum-like class)
    TWENTY_SECONDS | SIXTY_SECONDS — mirrors the CFN ResolutionSeconds allowed values (20 | 60). A Duration-based API was considered and rejected because it would accept arbitrary values that only fail at deploy time; the enum-like class rejects invalid values at compile time instead.

  • ServiceMetricConfiguration / ServiceMonitoringConfiguration (structs)
    Group these into the same one-resolution-to-many-metric-names shape CFN uses.

Validation added. Cross-referencing the ECS API reference and the high-resolution metrics guide surfaced constraints not captured in the generated L1 types, so synth-time ValidationErrors were added:

  • metricNames must have 1–5 entries (the API requires at least one).
  • metricConfigurations must have at most 5 entries.
  • High-resolution (TWENTY_SECONDS) monitoring is not supported with the CODE_DEPLOY or EXTERNAL deployment controller (documented AWS limitation) — mirrors the existing isEcsDeploymentController check already used for deploymentAlarms.
  • An empty metricConfigurations array is normalized to undefined (omits Monitoring from the template entirely), for consistency with how loadBalancers handles empty arrays elsewhere in this file.

Confirmed with AWS documentation that service-level monitoring metrics (and this configuration) are supported on both EC2 and Fargate launch types.

Describe any new or updated permissions being added

None

Description of how you validated changes

Add both unit and integ tests

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@aws-cdk-automation
aws-cdk-automation requested a review from a team July 25, 2026 08:54
@github-actions github-actions Bot added repeat-contributor [Pilot] contributed between 3-5 PRs to the CDK p2 labels Jul 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

👋 It looks like your PR description follows the template but is missing a valid issue number in the first section.

PRs without a linked issue will receive lower priority for review and merging. Please update the description to include a reference like Closes #123. If no existing issue matches your change, create one first.

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jul 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p2 pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. repeat-contributor [Pilot] contributed between 3-5 PRs to the CDK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants