EcsVolume

class aws_cdk.aws_batch.EcsVolume(*, container_path, name, readonly=None)

Bases: object

Represents a Volume that can be mounted to a container that uses ECS.

ExampleMetadata:

infused

Example:

# my_file_system: efs.IFileSystem
# my_job_role: iam.Role

my_file_system.grant_read(my_job_role)

job_defn = 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,
        volumes=[batch.EcsVolume.efs(
            name="myVolume",
            file_system=my_file_system,
            container_path="/Volumes/myVolume",
            use_job_role=True
        )],
        job_role=my_job_role
    )
)
Parameters:
  • container_path (str) – the path on the container where this volume is mounted.

  • name (str) – the name of this volume.

  • readonly (Optional[bool]) – if set, the container will have readonly access to the volume. Default: false

Attributes

container_path

The path on the container that this volume will be mounted to.

name

The name of this volume.

readonly

Whether or not the container has readonly access to this volume.

Default:

false

Static Methods

classmethod efs(*, file_system, access_point_id=None, enable_transit_encryption=None, root_directory=None, transit_encryption_port=None, use_job_role=None, container_path, name, readonly=None)

Creates a Volume that uses an AWS Elastic File System (EFS);

this volume can grow and shrink as needed

Parameters:
  • file_system (IFileSystem) – The EFS File System that supports this volume.

  • access_point_id (Optional[str]) – The Amazon EFS access point ID to use. If an access point is specified, rootDirectory must either be omitted or set to / which enforces the path set on the EFS access point. If an access point is used, enableTransitEncryption must be true. Default: - no accessPointId

  • enable_transit_encryption (Optional[bool]) – Enables encryption for Amazon EFS data in transit between the Amazon ECS host and the Amazon EFS server. Default: false

  • root_directory (Optional[str]) – The directory within the Amazon EFS file system to mount as the root directory inside the host. If this parameter is omitted, the root of the Amazon EFS volume is used instead. Specifying / has the same effect as omitting this parameter. The maximum length is 4,096 characters. Default: - root of the EFS File System

  • transit_encryption_port (Union[int, float, None]) – The port to use when sending encrypted data between the Amazon ECS host and the Amazon EFS server. The value must be between 0 and 65,535. Default: - chosen by the EFS Mount Helper

  • use_job_role (Optional[bool]) – Whether or not to use the AWS Batch job IAM role defined in a job definition when mounting the Amazon EFS file system. If specified, enableTransitEncryption must be true. Default: false

  • container_path (str) – the path on the container where this volume is mounted.

  • name (str) – the name of this volume.

  • readonly (Optional[bool]) – if set, the container will have readonly access to the volume. Default: false

See:

https://docs.aws.amazon.com/batch/latest/userguide/efs-volumes.html

Return type:

EfsVolume

classmethod host(*, host_path=None, container_path, name, readonly=None)

Creates a Host volume.

This volume will persist on the host at the specified hostPath. If the hostPath is not specified, Docker will choose the host path. In this case, the data may not persist after the containers that use it stop running.

Parameters:
  • host_path (Optional[str]) – The path on the host machine this container will have access to. Default: - Docker will choose the host path. The data may not persist after the containers that use it stop running.

  • container_path (str) – the path on the container where this volume is mounted.

  • name (str) – the name of this volume.

  • readonly (Optional[bool]) – if set, the container will have readonly access to the volume. Default: false

Return type:

HostVolume