Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(events-targets): launchType property for ECS task #29069

Merged
merged 6 commits into from
Feb 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/aws-cdk-lib/aws-events-targets/lib/ecs-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ export interface EcsTaskProps extends TargetBaseProps {
* @default - false
*/
readonly enableExecuteCommand?: boolean;

/**
* Specifies the launch type on which your task is running. The launch type that you specify here
* must match one of the launch type (compatibilities) of the target task.
*
* @default - 'EC2' if `isEc2Compatible` for the `taskDefinition` is true , otherwise 'FARGATE'
*/
readonly launchType?: ecs.LaunchType;
}

/**
Expand Down Expand Up @@ -156,6 +164,7 @@ export class EcsTask implements events.IRuleTarget {
private readonly propagateTags?: ecs.PropagatedTagSource;
private readonly tags?: Tag[];
private readonly enableExecuteCommand?: boolean;
private readonly launchType?: ecs.LaunchType;

constructor(private readonly props: EcsTaskProps) {
if (props.securityGroup !== undefined && props.securityGroups !== undefined) {
Expand All @@ -168,6 +177,7 @@ export class EcsTask implements events.IRuleTarget {
this.platformVersion = props.platformVersion;
this.assignPublicIp = props.assignPublicIp;
this.enableExecuteCommand = props.enableExecuteCommand;
this.launchType = props.launchType;

const propagateTagsValidValues = [ecs.PropagatedTagSource.TASK_DEFINITION, ecs.PropagatedTagSource.NONE];
if (props.propagateTags && !propagateTagsValidValues.includes(props.propagateTags)) {
Expand Down Expand Up @@ -229,7 +239,7 @@ export class EcsTask implements events.IRuleTarget {
}

const assignPublicIp = (this.assignPublicIp ?? subnetSelection.subnetType === ec2.SubnetType.PUBLIC) ? 'ENABLED' : 'DISABLED';
const launchType = this.taskDefinition.isEc2Compatible ? 'EC2' : 'FARGATE';
const launchType = this.launchType ?? this.taskDefinition.isEc2Compatible ? 'EC2' : 'FARGATE';
if (assignPublicIp === 'ENABLED' && launchType !== 'FARGATE') {
throw new Error('assignPublicIp is only supported for FARGATE tasks');
};
Expand Down
Loading