EcsEc2ContainerDefinition

class aws_cdk.aws_batch.EcsEc2ContainerDefinition(scope, id, *, gpu=None, privileged=None, ulimits=None, cpu, image, memory, command=None, environment=None, execution_role=None, job_role=None, linux_parameters=None, logging=None, readonly_root_filesystem=None, secrets=None, user=None, volumes=None)

Bases: Construct

A container orchestrated by ECS that uses EC2 resources.

ExampleMetadata:

infused

Example:

# vpc: ec2.IVpc


ecs_job = batch.EcsJobDefinition(self, "JobDefn",
    container=batch.EcsEc2ContainerDefinition(self, "containerDefn",
        image=ecs.ContainerImage.from_registry("public.ecr.aws/amazonlinux/amazonlinux:latest"),
        memory=cdk.Size.mebibytes(2048),
        cpu=256
    )
)

queue = batch.JobQueue(self, "JobQueue",
    compute_environments=[batch.OrderedComputeEnvironment(
        compute_environment=batch.ManagedEc2EcsComputeEnvironment(self, "managedEc2CE",
            vpc=vpc
        ),
        order=1
    )],
    priority=10
)

user = iam.User(self, "MyUser")
ecs_job.grant_submit_job(user, queue)
Parameters:
  • scope (Construct) –

  • id (str) –

  • gpu (Union[int, float, None]) – The number of physical GPUs to reserve for the container. Make sure that the number of GPUs reserved for all containers in a job doesn’t exceed the number of available GPUs on the compute resource that the job is launched on. Default: - no gpus

  • privileged (Optional[bool]) – When this parameter is true, the container is given elevated permissions on the host container instance (similar to the root user). Default: false

  • ulimits (Optional[Sequence[Union[Ulimit, Dict[str, Any]]]]) – Limits to set for the user this docker container will run as. Default: - no ulimits

  • cpu (Union[int, float]) – The number of vCPUs reserved for the container. Each vCPU is equivalent to 1,024 CPU shares. For containers running on EC2 resources, you must specify at least one vCPU.

  • image (ContainerImage) – The image that this container will run.

  • memory (Size) – The memory hard limit present to the container. If your container attempts to exceed the memory specified, the container is terminated. You must specify at least 4 MiB of memory for a job.

  • command (Optional[Sequence[str]]) – The command that’s passed to the container. Default: - no command

  • environment (Optional[Mapping[str, str]]) – The environment variables to pass to a container. Cannot start with AWS_BATCH. We don’t recommend using plaintext environment variables for sensitive information, such as credential data. Default: - no environment variables

  • execution_role (Optional[IRole]) – The role used by Amazon ECS container and AWS Fargate agents to make AWS API calls on your behalf. Default: - a Role will be created

  • job_role (Optional[IRole]) – The role that the container can assume. Default: - no job role

  • linux_parameters (Optional[LinuxParameters]) – Linux-specific modifications that are applied to the container, such as details for device mappings. Default: none

  • logging (Optional[LogDriver]) – The loging configuration for this Job. Default: - the log configuration of the Docker daemon

  • readonly_root_filesystem (Optional[bool]) – Gives the container readonly access to its root filesystem. Default: false

  • secrets (Optional[Mapping[str, Secret]]) – A map from environment variable names to the secrets for the container. Allows your job definitions to reference the secret by the environment variable name defined in this property. Default: - no secrets

  • user (Optional[str]) – The user name to use inside the container. Default: - no user

  • volumes (Optional[Sequence[EcsVolume]]) – The volumes to mount to this container. Automatically added to the job definition. Default: - no volumes

Methods

add_ulimit(*, hard_limit, name, soft_limit)

Add a ulimit to this container.

Parameters:
  • hard_limit (Union[int, float]) – The hard limit for this resource. The container will be terminated if it exceeds this limit.

  • name (UlimitName) – The resource to limit.

  • soft_limit (Union[int, float]) – The reservation for this resource. The container will not be terminated if it exceeds this limit.

Return type:

None

add_volume(volume)

Add a Volume to this container.

Parameters:

volume (EcsVolume) –

Return type:

None

to_string()

Returns a string representation of this construct.

Return type:

str

Attributes

command

The command that’s passed to the container.

cpu

The number of vCPUs reserved for the container.

Each vCPU is equivalent to 1,024 CPU shares. For containers running on EC2 resources, you must specify at least one vCPU.

environment

The environment variables to pass to a container.

Cannot start with AWS_BATCH. We don’t recommend using plaintext environment variables for sensitive information, such as credential data.

execution_role

The role used by Amazon ECS container and AWS Fargate agents to make AWS API calls on your behalf.

gpu

The number of physical GPUs to reserve for the container.

Make sure that the number of GPUs reserved for all containers in a job doesn’t exceed the number of available GPUs on the compute resource that the job is launched on.

image

The image that this container will run.

job_role

The role that the container can assume.

linux_parameters

Linux-specific modifications that are applied to the container, such as details for device mappings.

log_driver_config

The configuration of the log driver.

memory

The memory hard limit present to the container.

If your container attempts to exceed the memory specified, the container is terminated. You must specify at least 4 MiB of memory for a job.

node

The tree node.

privileged

When this parameter is true, the container is given elevated permissions on the host container instance (similar to the root user).

readonly_root_filesystem

Gives the container readonly access to its root filesystem.

secrets

A map from environment variable names to the secrets for the container.

Allows your job definitions to reference the secret by the environment variable name defined in this property.

ulimits

Limits to set for the user this docker container will run as.

user

The user name to use inside the container.

volumes

The volumes to mount to this container.

Automatically added to the job definition.

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.