ScheduledEc2Task

class aws_cdk.aws_ecs_patterns.ScheduledEc2Task(scope, id, *, scheduled_ec2_task_definition_options=None, scheduled_ec2_task_image_options=None, schedule, cluster=None, desired_task_count=None, enabled=None, propagate_tags=None, rule_name=None, security_groups=None, subnet_selection=None, tags=None, vpc=None)

Bases: ScheduledTaskBase

A scheduled EC2 task that will be initiated off of CloudWatch Events.

ExampleMetadata:

infused

Example:

# Instantiate an Amazon EC2 Task to run at a scheduled interval
# cluster: ecs.Cluster

ecs_scheduled_task = ecs_patterns.ScheduledEc2Task(self, "ScheduledTask",
    cluster=cluster,
    scheduled_ec2_task_image_options=ecsPatterns.ScheduledEc2TaskImageOptions(
        image=ecs.ContainerImage.from_registry("amazon/amazon-ecs-sample"),
        memory_limit_mi_b=256,
        environment={"name": "TRIGGER", "value": "CloudWatch Events"}
    ),
    schedule=appscaling.Schedule.expression("rate(1 minute)"),
    enabled=True,
    rule_name="sample-scheduled-task-rule"
)

Constructs a new instance of the ScheduledEc2Task class.

Parameters:
  • scope (Construct) –

  • id (str) –

  • scheduled_ec2_task_definition_options (Union[ScheduledEc2TaskDefinitionOptions, Dict[str, Any], None]) – The properties to define if using an existing TaskDefinition in this construct. ScheduledEc2TaskDefinitionOptions or ScheduledEc2TaskImageOptions must be defined, but not both. Default: none

  • scheduled_ec2_task_image_options (Union[ScheduledEc2TaskImageOptions, Dict[str, Any], None]) – The properties to define if the construct is to create a TaskDefinition. ScheduledEc2TaskDefinitionOptions or ScheduledEc2TaskImageOptions must be defined, but not both. Default: none

  • schedule (Schedule) – The schedule or rate (frequency) that determines when CloudWatch Events runs the rule. For more information, see Schedule Expression Syntax for Rules in the Amazon CloudWatch User Guide.

  • cluster (Optional[ICluster]) – The name of the cluster that hosts the service. If a cluster is specified, the vpc construct should be omitted. Alternatively, you can omit both cluster and vpc. Default: - create a new cluster; if both cluster and vpc are omitted, a new VPC will be created for you.

  • desired_task_count (Union[int, float, None]) – The desired number of instantiations of the task definition to keep running on the service. Default: 1

  • enabled (Optional[bool]) – Indicates whether the rule is enabled. Default: true

  • propagate_tags (Optional[PropagatedTagSource]) – Specifies whether to propagate the tags from the task definition to the task. If no value is specified, the tags are not propagated. Default: - Tags will not be propagated

  • rule_name (Optional[str]) – A name for the rule. Default: - AWS CloudFormation generates a unique physical ID and uses that ID for the rule name. For more information, see Name Type.

  • security_groups (Optional[Sequence[ISecurityGroup]]) – Existing security groups to use for your service. Default: - a new security group will be created.

  • subnet_selection (Union[SubnetSelection, Dict[str, Any], None]) – In what subnets to place the task’s ENIs. (Only applicable in case the TaskDefinition is configured for AwsVpc networking) Default: Private subnets

  • tags (Optional[Sequence[Union[Tag, Dict[str, Any]]]]) – The metadata that you apply to the task to help you categorize and organize them. Each tag consists of a key and an optional value, both of which you define. Default: - No tags are applied to the task

  • vpc (Optional[IVpc]) – The VPC where the container instances will be launched or the elastic network interfaces (ENIs) will be deployed. If a vpc is specified, the cluster construct should be omitted. Alternatively, you can omit both vpc and cluster. Default: - uses the VPC defined in the cluster or creates a new VPC.

Methods

to_string()

Returns a string representation of this construct.

Return type:

str

Attributes

cluster

The name of the cluster that hosts the service.

desired_task_count

The desired number of instantiations of the task definition to keep running on the service.

The minimum value is 1

event_rule

The CloudWatch Events rule for the service.

node

The tree node.

propagate_tags

Specifies whether to propagate the tags from the task definition to the task.

If no value is specified, the tags are not propagated.

Default:
  • Tags will not be propagated

subnet_selection

In what subnets to place the task’s ENIs.

(Only applicable in case the TaskDefinition is configured for AwsVpc networking)

Default:

Private subnets

tags

The metadata that you apply to the task to help you categorize and organize them.

Each tag consists of a key and an optional value, both of which you define.

Default:
  • No tags are applied to the task

task

The ECS task in this construct.

task_definition

The EC2 task definition in this construct.

Static Methods

classmethod is_construct(x)

Checks if x is a construct.

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

Parameters:

x (Any) – Any object.

Return type:

bool

Returns:

true if x is an object created from a class which extends Construct.