Skip to content

Conversation

@newlinedeveloper
Copy link

Description

Fixes an issue where the launchType property (including EXTERNAL) was being silently dropped from the CloudFormation template when creating an ECS event target with non-AWS_VPC network modes.

Root Cause

The EcsTask construct only included launchType in the EcsParameters when the task definition used AWS_VPC network mode. For other network modes (like BRIDGE, HOST, NONE), the launchType was omitted entirely from the generated CloudFormation template, causing EventBridge to use default launch type logic instead of the specified launch type.

This was particularly problematic for EXTERNAL launch type, which requires ECS Anywhere infrastructure. When the launch type was dropped, the scheduled task would fail to run because it would try to use EC2 or Fargate launch types instead of EXTERNAL.

Solution

Modified the bind() method in ecs-task.ts to always include launchType in baseEcsParameters, regardless of network mode. The launchType is now included in the CloudFormation template for all network modes, not just AWS_VPC.

Changes:

  • Moved launchType from the conditional AWS_VPC branch into baseEcsParameters
  • Ensures launchType is always included when specified (or computed from task definition compatibility)
  • Network configuration (networkConfiguration) remains only for AWS_VPC network mode, as required by CloudFormation

Testing

  • Added unit test launch type EXTERNAL is included for non-AWS_VPC network mode to verify the fix
  • Added integration test integ.event-external-task.ts to verify the stack synthesizes correctly
  • All existing unit tests continue to pass
  • Verified that LaunchType: 'EXTERNAL' appears in the CloudFormation template for BRIDGE network mode

Related Issue

Fixes #35877

Verification

The fix was verified by:

  1. Running unit tests to ensure LaunchType: 'EXTERNAL' is included in the CloudFormation template
  2. Generating integration test snapshot to verify the stack synthesizes correctly
  3. Confirming that existing tests for EC2 and Fargate launch types continue to pass
  4. The change aligns with AWS CloudFormation documentation which supports LaunchType for all network modes

CloudFormation Template Change

Before:
"EcsParameters": {
"TaskCount": 1,
"TaskDefinitionArn": { "Ref": "TaskDef" }
}
After:
"EcsParameters": {
"TaskCount": 1,
"TaskDefinitionArn": { "Ref": "TaskDef" },
"LaunchType": "EXTERNAL"
}---

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 November 8, 2025 13:14
@github-actions github-actions bot added bug This issue is a bug. effort/medium Medium work item – several days of effort p2 beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK labels Nov 8, 2025
@newlinedeveloper newlinedeveloper force-pushed the fix/ecs-external-launch-type branch from 5472f26 to 73c8304 Compare November 8, 2025 13:26
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 bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(aws_events_targets): Creating an ECS target with launchType EXTERNAL does not work

1 participant