Skip to content

fix(ecs): validate environment variable limit in container definitions - #38228

Open
sanyamk23 wants to merge 3 commits into
aws:mainfrom
sanyamk23:fix/ecs-env-var-limit-validation
Open

fix(ecs): validate environment variable limit in container definitions#38228
sanyamk23 wants to merge 3 commits into
aws:mainfrom
sanyamk23:fix/ecs-env-var-limit-validation

Conversation

@sanyamk23

@sanyamk23 sanyamk23 commented Jul 1, 2026

Copy link
Copy Markdown

Motivation

Fixes #38225

ECS task definitions silently fail when a container has more than 100 environment variables. CloudFormation creates the task definition with an empty environment array instead of failing with an error, which causes deployments to "succeed" while the application fails at runtime due to missing configuration.

Solution

Add synth-time validation in both the ContainerDefinition constructor and the addEnvironment() method to fail fast with a clear error message when the 100 environment variable limit is exceeded.

This follows the pattern used for other validations in the same file (for example, memory limit checks and port mapping validation) and uses ValidationError with a descriptive error code.

Testing

Added 3 unit tests:

  • Throws when the constructor receives more than 100 environment variables via props
  • Throws when addEnvironment() exceeds 100 variables
  • Does not throw when a container has exactly 100 variables

All 109 existing tests pass, confirming no regressions.

Considerations

This validation was added without a feature flag because input with more than 100 environment variables was never actually accepted by ECS at deploy time. CloudFormation silently creates an empty environment array. This is fail-fast synth-time validation for previously broken input, not a breaking change to working behavior.

@github-actions github-actions Bot added bug This issue is a bug. p2 beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK labels Jul 1, 2026
@aws-cdk-automation
aws-cdk-automation requested a review from a team July 1, 2026 15:15

@aws-cdk-automation aws-cdk-automation left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This review is outdated)

@aws-cdk-automation
aws-cdk-automation dismissed their stale review July 2, 2026 13:47

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@sanyamk23 sanyamk23 left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

@github-actions github-actions Bot added effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. and removed bug This issue is a bug. labels Jul 16, 2026
@sanyamk23

Copy link
Copy Markdown
Author

Full CI including build is green. Ready for review.

@sanyamk23

sanyamk23 commented Aug 11, 2026

Copy link
Copy Markdown
Author

Hi @otaviomacedo, I added validation for the ECS environment variable limit so deployments do not fail silently. Would appreciate a review.

…ross-repo PRs

When the GitHub API returns a 404 for the list reviews endpoint (which
can happen for cross-repo PRs from forks or when the PROJEN_GITHUB_TOKEN
lacks access to the source repository), treat it as no existing reviews
rather than crashing the entire validate-pr job.

Previously, the 404 error would propagate up to run().catch() in index.ts,
causing the process to exit with code 1 and failing the workflow.
ECS task definitions silently fail when a container has more than 100
environment variables — CloudFormation creates the task definition with
an empty environment array instead of failing with an error.

This adds synth-time validation in both the ContainerDefinition
constructor and the addEnvironment() method to fail fast with a clear
error message when the 100 environment variable limit is exceeded.

Fixes aws#38225
Add integration test verifying that exactly 100 environment variables
can be added to a container definition without errors, and that the
synthesized CloudFormation template correctly includes all variables.

Also fix lint error (extra blank line) in unit test file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2 pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@aws-cdk/aws-ecs : Silent failure: ECS environment arrays empty when >100 variables

5 participants