Class TaskDefinition
- All Implemented Interfaces:
IResource
,ITaskDefinition
,software.amazon.jsii.JsiiSerializable
,software.constructs.IConstruct
,software.constructs.IDependable
- Direct Known Subclasses:
Ec2TaskDefinition
,ExternalTaskDefinition
,FargateTaskDefinition
Example:
Cluster cluster; TaskDefinition taskDefinition; Vpc vpc; FargateService service = FargateService.Builder.create(this, "Service").cluster(cluster).taskDefinition(taskDefinition).build(); ApplicationLoadBalancer lb = ApplicationLoadBalancer.Builder.create(this, "LB").vpc(vpc).internetFacing(true).build(); ApplicationListener listener = lb.addListener("Listener", BaseApplicationListenerProps.builder().port(80).build()); service.registerLoadBalancerTargets(EcsTarget.builder() .containerName("web") .containerPort(80) .newTargetGroupId("ECS") .listener(ListenerConfig.applicationListener(listener, AddApplicationTargetsProps.builder() .protocol(ApplicationProtocol.HTTPS) .build())) .build());
-
Nested Class Summary
Nested classes/interfaces inherited from class software.amazon.jsii.JsiiObject
software.amazon.jsii.JsiiObject.InitializationMode
Nested classes/interfaces inherited from interface software.constructs.IConstruct
software.constructs.IConstruct.Jsii$Default
Nested classes/interfaces inherited from interface software.amazon.awscdk.IResource
IResource.Jsii$Default
Nested classes/interfaces inherited from interface software.amazon.awscdk.services.ecs.ITaskDefinition
ITaskDefinition.Jsii$Default, ITaskDefinition.Jsii$Proxy
-
Constructor Summary
ModifierConstructorDescriptionprotected
TaskDefinition
(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) protected
TaskDefinition
(software.amazon.jsii.JsiiObjectRef objRef) TaskDefinition
(software.constructs.Construct scope, String id, TaskDefinitionProps props) Constructs a new instance of the TaskDefinition class. -
Method Summary
Modifier and TypeMethodDescriptionaddContainer
(String id, ContainerDefinitionOptions props) Adds a new container to the task definition.void
addExtension
(ITaskDefinitionExtension extension) Adds the specified extension to the task definition.Adds a firelens log router to the task definition.void
addInferenceAccelerator
(InferenceAccelerator inferenceAccelerator) Adds an inference accelerator to the task definition.void
addPlacementConstraint
(PlacementConstraint constraint) Adds the specified placement constraint to the task definition.void
addToExecutionRolePolicy
(PolicyStatement statement) Adds a policy statement to the task execution IAM role.void
addToTaskRolePolicy
(PolicyStatement statement) Adds a policy statement to the task IAM role.void
Adds a volume to the task definition.findContainer
(String containerName) Returns the container that match the provided containerName.findPortMappingByName
(String name) Determine the existing port mapping for the provided name.static ITaskDefinition
fromTaskDefinitionArn
(software.constructs.Construct scope, String id, String taskDefinitionArn) Imports a task definition from the specified task definition ARN.static ITaskDefinition
fromTaskDefinitionAttributes
(software.constructs.Construct scope, String id, TaskDefinitionAttributes attrs) Create a task definition from a task definition reference.The task launch type compatibility requirement.protected List<ContainerDefinition>
The container definitions.Default container for this task.The amount (in GiB) of ephemeral storage to be allocated to the task.Execution role for this task definition.The name of a family that this task definition is registered to.Public getter method to access list of inference accelerators attached to the instance.Return true if the task definition can be run on an EC2 cluster.Return true if the task definition can be run on a ECS anywhere cluster.Return true if the task definition can be run on a Fargate cluster.The networking mode to use for the containers in the task.The process namespace to use for the containers in the task.Whether this task definition has at least a container that references a specific JSON field of a secret stored in Secrets Manager.The full Amazon Resource Name (ARN) of the task definition.The name of the IAM role that grants containers in the task permission to call AWS APIs on your behalf.grantRun
(IGrantable grantee) Grants permissions to run this task definition.Creates the task execution IAM role if it doesn't already exist.void
Default container for this task.Methods inherited from class software.amazon.awscdk.Resource
applyRemovalPolicy, generatePhysicalName, getEnv, getPhysicalName, getResourceArnAttribute, getResourceNameAttribute, getStack, isOwnedResource, isResource
Methods inherited from class software.constructs.Construct
getNode, isConstruct, toString
Methods inherited from class software.amazon.jsii.JsiiObject
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSet
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface software.constructs.IConstruct
getNode
Methods inherited from interface software.amazon.awscdk.IResource
applyRemovalPolicy, getEnv, getStack
Methods inherited from interface software.amazon.jsii.JsiiSerializable
$jsii$toJson
-
Constructor Details
-
TaskDefinition
protected TaskDefinition(software.amazon.jsii.JsiiObjectRef objRef) -
TaskDefinition
protected TaskDefinition(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) -
TaskDefinition
@Stability(Stable) public TaskDefinition(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull TaskDefinitionProps props) Constructs a new instance of the TaskDefinition class.- Parameters:
scope
- This parameter is required.id
- This parameter is required.props
- This parameter is required.
-
-
Method Details
-
fromTaskDefinitionArn
@Stability(Stable) @NotNull public static ITaskDefinition fromTaskDefinitionArn(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull String taskDefinitionArn) Imports a task definition from the specified task definition ARN.The task will have a compatibility of EC2+Fargate.
- Parameters:
scope
- This parameter is required.id
- This parameter is required.taskDefinitionArn
- This parameter is required.
-
fromTaskDefinitionAttributes
@Stability(Stable) @NotNull public static ITaskDefinition fromTaskDefinitionAttributes(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull TaskDefinitionAttributes attrs) Create a task definition from a task definition reference.- Parameters:
scope
- This parameter is required.id
- This parameter is required.attrs
- This parameter is required.
-
addContainer
@Stability(Stable) @NotNull public ContainerDefinition addContainer(@NotNull String id, @NotNull ContainerDefinitionOptions props) Adds a new container to the task definition.- Parameters:
id
- This parameter is required.props
- This parameter is required.
-
addExtension
Adds the specified extension to the task definition.Extension can be used to apply a packaged modification to a task definition.
- Parameters:
extension
- This parameter is required.
-
addFirelensLogRouter
@Stability(Stable) @NotNull public FirelensLogRouter addFirelensLogRouter(@NotNull String id, @NotNull FirelensLogRouterDefinitionOptions props) Adds a firelens log router to the task definition.- Parameters:
id
- This parameter is required.props
- This parameter is required.
-
addInferenceAccelerator
@Stability(Stable) public void addInferenceAccelerator(@NotNull InferenceAccelerator inferenceAccelerator) Adds an inference accelerator to the task definition.- Parameters:
inferenceAccelerator
- This parameter is required.
-
addPlacementConstraint
Adds the specified placement constraint to the task definition.- Parameters:
constraint
- This parameter is required.
-
addToExecutionRolePolicy
Adds a policy statement to the task execution IAM role.- Parameters:
statement
- This parameter is required.
-
addToTaskRolePolicy
Adds a policy statement to the task IAM role.- Parameters:
statement
- This parameter is required.
-
addVolume
Adds a volume to the task definition.- Parameters:
volume
- This parameter is required.
-
findContainer
@Stability(Stable) @Nullable public ContainerDefinition findContainer(@NotNull String containerName) Returns the container that match the provided containerName.- Parameters:
containerName
- This parameter is required.
-
findPortMappingByName
Determine the existing port mapping for the provided name.- Parameters:
name
- : port mapping name. This parameter is required.- Returns:
- PortMapping for the provided name, if it exists.
-
grantRun
Grants permissions to run this task definition.This will grant the following permissions:
- ecs:RunTask
- iam:PassRole
- Parameters:
grantee
- Principal to grant consume rights to. This parameter is required.
-
obtainExecutionRole
Creates the task execution IAM role if it doesn't already exist. -
getCompatibility
The task launch type compatibility requirement.- Specified by:
getCompatibility
in interfaceITaskDefinition
-
getContainers
The container definitions. -
getFamily
The name of a family that this task definition is registered to.A family groups multiple versions of a task definition.
-
getInferenceAccelerators
Public getter method to access list of inference accelerators attached to the instance. -
getIsEc2Compatible
Return true if the task definition can be run on an EC2 cluster.- Specified by:
getIsEc2Compatible
in interfaceITaskDefinition
-
getIsExternalCompatible
Return true if the task definition can be run on a ECS anywhere cluster.- Specified by:
getIsExternalCompatible
in interfaceITaskDefinition
-
getIsFargateCompatible
Return true if the task definition can be run on a Fargate cluster.- Specified by:
getIsFargateCompatible
in interfaceITaskDefinition
-
getNetworkMode
The networking mode to use for the containers in the task.- Specified by:
getNetworkMode
in interfaceITaskDefinition
-
getTaskDefinitionArn
The full Amazon Resource Name (ARN) of the task definition.- Specified by:
getTaskDefinitionArn
in interfaceITaskDefinition
-
getTaskRole
The name of the IAM role that grants containers in the task permission to call AWS APIs on your behalf.- Specified by:
getTaskRole
in interfaceITaskDefinition
-
getEphemeralStorageGiB
The amount (in GiB) of ephemeral storage to be allocated to the task.Only supported in Fargate platform version 1.4.0 or later.
-
getExecutionRole
Execution role for this task definition.- Specified by:
getExecutionRole
in interfaceITaskDefinition
-
getPidMode
The process namespace to use for the containers in the task.Only supported for tasks that are hosted on AWS Fargate if the tasks are using platform version 1.4.0 or later (Linux). Not supported in Windows containers. If pidMode is specified for a Fargate task, then runtimePlatform.operatingSystemFamily must also be specified. For more information, see Task Definition Parameters.
-
getReferencesSecretJsonField
Whether this task definition has at least a container that references a specific JSON field of a secret stored in Secrets Manager. -
getDefaultContainer
Default container for this task.Load balancers will send traffic to this container. The first essential container that is added to this task will become the default container.
-
setDefaultContainer
Default container for this task.Load balancers will send traffic to this container. The first essential container that is added to this task will become the default container.
-