-
Notifications
You must be signed in to change notification settings - Fork 4.3k
feat(scheduler-targets): EcsRunTask scheduler target #33697
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
Changes from 1 commit
65e6293
7604171
a60e30c
863b23d
6519994
08fc170
66721c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -155,20 +155,6 @@ export interface Ec2TaskProps extends EcsRunTaskBaseProps { | |
| * Schedule an ECS Task using AWS EventBridge Scheduler. | ||
| */ | ||
| export abstract class EcsRunTask extends ScheduleTargetBase implements IScheduleTarget { | ||
| /** | ||
| * Schedule an ECS Task on Fargate using AWS EventBridge Scheduler. | ||
| */ | ||
| public static onFargate(cluster: ecs.ICluster, props: FargateTaskProps): IScheduleTarget { | ||
| return new FargateTask(cluster, props); | ||
| } | ||
|
|
||
| /** | ||
| * Schedule an ECS Task on EC2 using AWS EventBridge Scheduler. | ||
| */ | ||
| public static onEc2(cluster: ecs.ICluster, props: Ec2TaskProps): IScheduleTarget { | ||
| return new Ec2Task(cluster, props); | ||
| } | ||
|
|
||
| constructor( | ||
| protected readonly cluster: ecs.ICluster, | ||
| protected readonly props: EcsRunTaskBaseProps, | ||
|
|
@@ -207,9 +193,11 @@ export abstract class EcsRunTask extends ScheduleTargetBase implements ISchedule | |
| } | ||
| } | ||
|
|
||
| class FargateTask extends EcsRunTask { | ||
| /** | ||
| * Schedule an ECS Task on Fargate using AWS EventBridge Scheduler. | ||
| */ | ||
| export class EcsRunFargateTask extends EcsRunTask { | ||
| private readonly subnetSelection?: ec2.SubnetSelection; | ||
| private readonly securityGroups?: ec2.ISecurityGroup[]; | ||
| private readonly assignPublicIp?: boolean; | ||
| private readonly platformVersion?: string; | ||
| private readonly capacityProviderStrategies?: ecs.CapacityProviderStrategy[]; | ||
|
|
@@ -220,7 +208,6 @@ class FargateTask extends EcsRunTask { | |
| ) { | ||
| super(cluster, props); | ||
| this.subnetSelection = props.vpcSubnets; | ||
| this.securityGroups = props.securityGroups; | ||
| this.assignPublicIp = props.assignPublicIp; | ||
| this.platformVersion = props.platformVersion; | ||
| this.capacityProviderStrategies = props.capacityProviderStrategies; | ||
|
|
@@ -258,14 +245,21 @@ class FargateTask extends EcsRunTask { | |
| awsvpcConfiguration: { | ||
| assignPublicIp, | ||
| subnets: this.cluster.vpc.selectSubnets(subnetSelection).subnetIds, | ||
| securityGroups: this.securityGroups?.map((sg) => sg.securityGroupId), | ||
| securityGroups: (this.props.securityGroups && this.props.securityGroups.length > 0) | ||
| ? | ||
| this.props.securityGroups?.map((sg) => sg.securityGroupId) | ||
| : undefined, | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
| } | ||
| } | ||
| class Ec2Task extends EcsRunTask { | ||
|
|
||
| /** | ||
| * Schedule an ECS Task on EC2 using AWS EventBridge Scheduler. | ||
| */ | ||
| export class EcsRunEc2Task extends EcsRunTask { | ||
| private readonly capacityProviderStrategies?: ecs.CapacityProviderStrategy[]; | ||
| private readonly placementConstraints?: ecs.PlacementConstraint[]; | ||
| private readonly placementStrategies?: ecs.PlacementStrategy[]; | ||
|
|
@@ -289,12 +283,18 @@ class Ec2Task extends EcsRunTask { | |
| // See https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_RunTask.html#ECS-RunTask-request-launchType | ||
| const launchType = this.capacityProviderStrategies ? undefined : ecs.LaunchType.EC2; | ||
|
|
||
| const taskDefinitionUsesAwsVpc = this.props.taskDefinition.networkMode === ecs.NetworkMode.AWS_VPC; | ||
|
|
||
| // Security groups are only configurable with the "awsvpc" network mode. | ||
| // See https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_RunTask.html#ECS-RunTask-request-networkConfiguration | ||
| if (this.props.taskDefinition.networkMode !== ecs.NetworkMode.AWS_VPC && (this.props.securityGroups || this.props.vpcSubnets)) { | ||
| if (!taskDefinitionUsesAwsVpc && (this.props.securityGroups || this.props.vpcSubnets)) { | ||
| throw new ValidationError('Security groups and subnets can only be used with awsvpc network mode', _schedule); | ||
| } | ||
|
|
||
| const subnetSelection = | ||
| taskDefinitionUsesAwsVpc ? this.props.vpcSubnets || { subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS } | ||
| : undefined; | ||
|
|
||
| const bindBaseTargetConfigParameters = super.bindBaseTargetConfig(_schedule).ecsParameters!; | ||
|
|
||
| return { | ||
|
|
@@ -317,11 +317,14 @@ class Ec2Task extends EcsRunTask { | |
| : undefined; | ||
| }, | ||
| }, { omitEmptyArray: true }), | ||
| ... (this.props.taskDefinition.networkMode === ecs.NetworkMode.AWS_VPC && { | ||
| ... (taskDefinitionUsesAwsVpc && { | ||
| networkConfiguration: { | ||
| awsvpcConfiguration: { | ||
| subnets: this.cluster.vpc.selectSubnets(this.props.vpcSubnets).subnetIds, | ||
| securityGroups: this.props.securityGroups?.map((sg) => sg.securityGroupId), | ||
| subnets: this.cluster.vpc.selectSubnets(subnetSelection).subnetIds, | ||
| securityGroups: (this.props.securityGroups && this.props.securityGroups.length > 0) | ||
| ? | ||
| this.props.securityGroups.map((sg) => sg.securityGroupId) | ||
| : undefined, | ||
| }, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. qq: For my understanding, is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I based the implementation on the CloudFormation docs for AWS::Scheduler::Schedule AwsVpcConfiguration, it says under There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the clarification. |
||
| }, | ||
| }), | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.