aws-cdk-lib.aws_stepfunctions_tasks.EcsEc2LaunchTarget

class EcsEc2LaunchTarget

LanguageType name
.NETAmazon.CDK.AWS.StepFunctions.Tasks.EcsEc2LaunchTarget
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awsstepfunctionstasks#EcsEc2LaunchTarget
Javasoftware.amazon.awscdk.services.stepfunctions.tasks.EcsEc2LaunchTarget
Pythonaws_cdk.aws_stepfunctions_tasks.EcsEc2LaunchTarget
TypeScript (source)aws-cdk-lib » aws_stepfunctions_tasks » EcsEc2LaunchTarget

Implements IEcsLaunchTarget

Configuration for running an ECS task on EC2.

See also: https://docs.aws.amazon.com/AmazonECS/latest/userguide/launch_types.html#launch-type-ec2

Example

const vpc = ec2.Vpc.fromLookup(this, 'Vpc', {
  isDefault: true,
});

const cluster = new ecs.Cluster(this, 'Ec2Cluster', { vpc });
cluster.addCapacity('DefaultAutoScalingGroup', {
  instanceType: new ec2.InstanceType('t2.micro'),
  vpcSubnets: { subnetType: ec2.SubnetType.PUBLIC },
});

const taskDefinition = new ecs.TaskDefinition(this, 'TD', {
  compatibility: ecs.Compatibility.EC2,
});

taskDefinition.addContainer('TheContainer', {
  image: ecs.ContainerImage.fromRegistry('foo/bar'),
  memoryLimitMiB: 256,
});

const runTask = new tasks.EcsRunTask(this, 'Run', {
  integrationPattern: sfn.IntegrationPattern.RUN_JOB,
  cluster,
  taskDefinition,
  launchTarget: new tasks.EcsEc2LaunchTarget({
    placementStrategies: [
      ecs.PlacementStrategy.spreadAcrossInstances(),
      ecs.PlacementStrategy.packedByCpu(),
      ecs.PlacementStrategy.randomly(),
    ],
    placementConstraints: [
      ecs.PlacementConstraint.memberOf('blieptuut'),
    ],
  }),
  propagatedTagSource: ecs.PropagatedTagSource.TASK_DEFINITION,
});

Initializer

new EcsEc2LaunchTarget(options?: EcsEc2LaunchTargetOptions)

Parameters

  • options EcsEc2LaunchTargetOptions

Methods

NameDescription
bind(_task, launchTargetOptions)Called when the EC2 launch type is configured on RunTask.

bind(_task, launchTargetOptions)

public bind(_task: EcsRunTask, launchTargetOptions: LaunchTargetBindOptions): EcsLaunchTargetConfig

Parameters

  • _task EcsRunTask
  • launchTargetOptions LaunchTargetBindOptions

Returns

  • EcsLaunchTargetConfig

Called when the EC2 launch type is configured on RunTask.