EcsEc2LaunchTarget

class aws_cdk.aws_stepfunctions_tasks.EcsEc2LaunchTarget(*, capacity_provider_options=None, placement_constraints=None, placement_strategies=None)

Bases: object

Configuration for running an ECS task on EC2.

See:

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

ExampleMetadata:

infused

Example:

vpc = ec2.Vpc.from_lookup(self, "Vpc",
    is_default=True
)

cluster = ecs.Cluster(self, "Ec2Cluster", vpc=vpc)
cluster.add_capacity("DefaultAutoScalingGroup",
    instance_type=ec2.InstanceType("t2.micro"),
    vpc_subnets=ec2.SubnetSelection(subnet_type=ec2.SubnetType.PUBLIC)
)

task_definition = ecs.TaskDefinition(self, "TD",
    compatibility=ecs.Compatibility.EC2
)

task_definition.add_container("TheContainer",
    image=ecs.ContainerImage.from_registry("foo/bar"),
    memory_limit_mi_b=256
)

run_task = tasks.EcsRunTask(self, "Run",
    integration_pattern=sfn.IntegrationPattern.RUN_JOB,
    cluster=cluster,
    task_definition=task_definition,
    launch_target=tasks.EcsEc2LaunchTarget(
        placement_strategies=[
            ecs.PlacementStrategy.spread_across_instances(),
            ecs.PlacementStrategy.packed_by_cpu(),
            ecs.PlacementStrategy.randomly()
        ],
        placement_constraints=[
            ecs.PlacementConstraint.member_of("blieptuut")
        ]
    ),
    propagated_tag_source=ecs.PropagatedTagSource.TASK_DEFINITION
)
Parameters:
  • capacity_provider_options (Optional[CapacityProviderOptions]) – The capacity provider options to use for the task. This property allows you to set the capacity provider strategy for the task. If you want to set the capacity provider strategy for the task, specify CapacityProviderOptions.custom(). If you want to use the cluster’s default capacity provider strategy, specify CapacityProviderOptions.default(). Default: - ‘EC2’ LaunchType running tasks on Amazon EC2 instances registered to your cluster is used without the capacity provider strategy.

  • placement_constraints (Optional[Sequence[PlacementConstraint]]) – Placement constraints. Default: - None

  • placement_strategies (Optional[Sequence[PlacementStrategy]]) – Placement strategies. Default: - None

Methods

bind(task, *, task_definition, cluster=None)

Called when the EC2 launch type is configured on RunTask.

Parameters:
  • task (EcsRunTask)

  • task_definition (ITaskDefinition) – Task definition to run Docker containers in Amazon ECS.

  • cluster (Optional[ICluster]) – A regional grouping of one or more container instances on which you can run tasks and services. Default: - No cluster

Return type:

EcsLaunchTargetConfig