ContainerImage Class
Constructs for types of container images.
| Source | aws-ecs/lib/container-image.ts |
|---|---|
| Type last changed |
Example
ts
declare const myFileSystem: efs.IFileSystem;
declare const myJobRole: iam.Role;
myFileSystem.grantRead(myJobRole);
const jobDefn = new batch.EcsJobDefinition(this, 'JobDefn', {
container: new batch.EcsEc2ContainerDefinition(this, 'containerDefn', {
image: ecs.ContainerImage.fromRegistry('public.ecr.aws/amazonlinux/amazonlinux:latest'),
memory: cdk.Size.mebibytes(2048),
cpu: 256,
volumes: [batch.EcsVolume.efs({
name: 'myVolume',
fileSystem: myFileSystem,
containerPath: '/Volumes/myVolume',
useJobRole: true,
})],
jobRole: myJobRole,
}),
});
python
# 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
)
)
java
IFileSystem myFileSystem;
Role myJobRole;
myFileSystem.grantRead(myJobRole);
EcsJobDefinition jobDefn = EcsJobDefinition.Builder.create(this, "JobDefn")
.container(EcsEc2ContainerDefinition.Builder.create(this, "containerDefn")
.image(ContainerImage.fromRegistry("public.ecr.aws/amazonlinux/amazonlinux:latest"))
.memory(Size.mebibytes(2048))
.cpu(256)
.volumes(List.of(EcsVolume.efs(EfsVolumeOptions.builder()
.name("myVolume")
.fileSystem(myFileSystem)
.containerPath("/Volumes/myVolume")
.useJobRole(true)
.build())))
.jobRole(myJobRole)
.build())
.build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
IFileSystem myFileSystem;
Role myJobRole;
myFileSystem.GrantRead(myJobRole);
var jobDefn = new EcsJobDefinition(this, "JobDefn", new EcsJobDefinitionProps {
Container = new EcsEc2ContainerDefinition(this, "containerDefn", new EcsEc2ContainerDefinitionProps {
Image = ContainerImage.FromRegistry("public.ecr.aws/amazonlinux/amazonlinux:latest"),
Memory = Size.Mebibytes(2048),
Cpu = 256,
Volumes = new [] { EcsVolume.Efs(new EfsVolumeOptions {
Name = "myVolume",
FileSystem = myFileSystem,
ContainerPath = "/Volumes/myVolume",
UseJobRole = true
}) },
JobRole = myJobRole
})
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var myFileSystem IFileSystem
var myJobRole Role
myFileSystem.GrantRead(myJobRole)
jobDefn := batch.NewEcsJobDefinition(this, jsii.String("JobDefn"), &EcsJobDefinitionProps{
Container: batch.NewEcsEc2ContainerDefinition(this, jsii.String("containerDefn"), &EcsEc2ContainerDefinitionProps{
Image: ecs.ContainerImage_FromRegistry(jsii.String("public.ecr.aws/amazonlinux/amazonlinux:latest")),
Memory: cdk.Size_Mebibytes(jsii.Number(2048)),
Cpu: jsii.Number(256),
Volumes: []EcsVolume{
batch.EcsVolume_Efs(&EfsVolumeOptions{
Name: jsii.String("myVolume"),
FileSystem: myFileSystem,
ContainerPath: jsii.String("/Volumes/myVolume"),
UseJobRole: jsii.Boolean(true),
}),
},
JobRole: myJobRole,
}),
})
Initializer
ts
new ContainerImage()
python
ContainerImage()
java
new ContainerImage()
csharp
new ContainerImage()
go
NewContainerImage()
Methods
bind(scope: Construct, containerDefinition: ContainerDefinition): ContainerImageConfigdef bind(self, scope: Construct, container_definition: ContainerDefinition) -> ContainerImageConfigpublic ContainerImageConfig bind(Construct scope, ContainerDefinition containerDefinition)public ContainerImageConfig Bind(Construct scope, ContainerDefinition containerDefinition)func Bind(Scope Construct, ContainerDefinition ContainerDefinition) ContainerImageConfig #Called when the image is used by a ContainerDefinition.
fromAsset(directory: string, props?: AssetImageProps): AssetImage@staticmethod def from_asset(directory: str, props: typing.Optional[AssetImageProps] = None) -> AssetImagepublic static AssetImage fromAsset(String directory, AssetImageProps props)public static AssetImage FromAsset(string directory, AssetImageProps? props = null)func FromAsset(Directory *string, Props AssetImageProps) AssetImage static #Reference an image that's constructed directly from sources on disk.
If you already have a DockerImageAsset instance, you can use the ContainerImage.fromDockerImageAsset method instead.
1 parameter
Parameters
directorydirectorydirectorydirectoryDirectory— The directory containing the Dockerfile.
fromDockerImageAsset(asset: DockerImageAsset): ContainerImage // chainable@staticmethod def from_docker_image_asset(asset: DockerImageAsset) -> ContainerImagepublic static ContainerImage fromDockerImageAsset(DockerImageAsset asset)public static ContainerImage FromDockerImageAsset(DockerImageAsset asset)func FromDockerImageAsset(Asset DockerImageAsset) ContainerImage static #Use an existing `DockerImageAsset` for this container image.
1 parameter
Parameters
assetassetassetassetAsset— TheDockerImageAssetto use for this container definition.
fromEcrRepository(repository: IRepository, tag?: string): EcrImage@staticmethod def from_ecr_repository(repository: IRepository, tag: typing.Optional[str] = None) -> EcrImagepublic static EcrImage fromEcrRepository(IRepository repository, String tag)public static EcrImage FromEcrRepository(IRepository repository, string? tag = null)func FromEcrRepository(Repository IRepository, Tag *string) EcrImage static #Reference an image in an ECR repository.
1 parameter
Parameters
tagtagtagtagTag— If you don't specify this parameter,latestis used as default.
fromRegistry(name: string, props?: RepositoryImageProps): RepositoryImage@staticmethod def from_registry(name: str, props: typing.Optional[RepositoryImageProps] = None) -> RepositoryImagepublic static RepositoryImage fromRegistry(String name, RepositoryImageProps props)public static RepositoryImage FromRegistry(string name, RepositoryImageProps? props = null)func FromRegistry(Name *string, Props RepositoryImageProps) RepositoryImage static #Reference an image on DockerHub or another online registry.
fromTarball(tarballFile: string): ContainerImage // chainable@staticmethod def from_tarball(tarball_file: str) -> ContainerImagepublic static ContainerImage fromTarball(String tarballFile)public static ContainerImage FromTarball(string tarballFile)func FromTarball(TarballFile *string) ContainerImage static #Use an existing tarball for this container image.
Use this method if the container image has already been created by another process (e.g. jib) and you want to add it as a container image asset.
1 parameter
Parameters
tarballFiletarball_filetarballFiletarballFileTarballFile— Absolute path to the tarball.