Class TaskDefinition
The base class for all task definitions.
Inheritance
Inherited Members
Namespace: Amazon.CDK.AWS.ECS
Assembly: Amazon.CDK.AWS.ECS.dll
Syntax (csharp)
public class TaskDefinition : Resource, ITaskDefinition, IResource, IConstruct, IDependable
Syntax (vb)
Public Class TaskDefinition
Inherits Resource
Implements ITaskDefinition, IResource, IConstruct, IDependable
Remarks
ExampleMetadata: infused
Examples
Cluster cluster;
TaskDefinition taskDefinition;
Vpc vpc;
var service = new FargateService(this, "Service", new FargateServiceProps { Cluster = cluster, TaskDefinition = taskDefinition });
var lb = new ApplicationLoadBalancer(this, "LB", new ApplicationLoadBalancerProps { Vpc = vpc, InternetFacing = true });
var listener = lb.AddListener("Listener", new BaseApplicationListenerProps { Port = 80 });
service.RegisterLoadBalancerTargets(new EcsTarget {
ContainerName = "web",
ContainerPort = 80,
NewTargetGroupId = "ECS",
Listener = ListenerConfig.ApplicationListener(listener, new AddApplicationTargetsProps {
Protocol = ApplicationProtocol.HTTPS
})
});
Synopsis
Constructors
TaskDefinition(ByRefValue) | Used by jsii to construct an instance of this class from a Javascript-owned object reference |
TaskDefinition(DeputyBase.DeputyProps) | Used by jsii to construct an instance of this class from DeputyProps |
TaskDefinition(Construct, String, ITaskDefinitionProps) | Constructs a new instance of the TaskDefinition class. |
Properties
Compatibility | The task launch type compatibility requirement. |
Containers | The container definitions. |
DefaultContainer | Default container for this task. |
EphemeralStorageGiB | The amount (in GiB) of ephemeral storage to be allocated to the task. |
ExecutionRole | Execution role for this task definition. |
Family | The name of a family that this task definition is registered to. |
InferenceAccelerators | Public getter method to access list of inference accelerators attached to the instance. |
IsEc2Compatible | Return true if the task definition can be run on an EC2 cluster. |
IsExternalCompatible | Return true if the task definition can be run on a ECS anywhere cluster. |
IsFargateCompatible | Return true if the task definition can be run on a Fargate cluster. |
NetworkMode | The networking mode to use for the containers in the task. |
ReferencesSecretJsonField | Whether this task definition has at least a container that references a specific JSON field of a secret stored in Secrets Manager. |
TaskDefinitionArn | The full Amazon Resource Name (ARN) of the task definition. |
TaskRole | The name of the IAM role that grants containers in the task permission to call AWS APIs on your behalf. |
Methods
AddContainer(String, IContainerDefinitionOptions) | Adds a new container to the task definition. |
AddExtension(ITaskDefinitionExtension) | Adds the specified extension to the task definition. |
AddFirelensLogRouter(String, IFirelensLogRouterDefinitionOptions) | Adds a firelens log router to the task definition. |
AddInferenceAccelerator(IInferenceAccelerator) | Adds an inference accelerator to the task definition. |
AddPlacementConstraint(PlacementConstraint) | Adds the specified placement constraint to the task definition. |
AddToExecutionRolePolicy(PolicyStatement) | Adds a policy statement to the task execution IAM role. |
AddToTaskRolePolicy(PolicyStatement) | Adds a policy statement to the task IAM role. |
AddVolume(IVolume) | Adds a volume to the task definition. |
FindContainer(String) | Returns the container that match the provided containerName. |
FromTaskDefinitionArn(Construct, String, String) | Imports a task definition from the specified task definition ARN. |
FromTaskDefinitionAttributes(Construct, String, ITaskDefinitionAttributes) | Create a task definition from a task definition reference. |
ObtainExecutionRole() | Creates the task execution IAM role if it doesn't already exist. |
Validate() | Validates the task definition. |
Constructors
TaskDefinition(ByRefValue)
Used by jsii to construct an instance of this class from a Javascript-owned object reference
protected TaskDefinition(ByRefValue reference)
Parameters
- reference Amazon.JSII.Runtime.Deputy.ByRefValue
The Javascript-owned object reference
TaskDefinition(DeputyBase.DeputyProps)
Used by jsii to construct an instance of this class from DeputyProps
protected TaskDefinition(DeputyBase.DeputyProps props)
Parameters
- props Amazon.JSII.Runtime.Deputy.DeputyBase.DeputyProps
The deputy props
TaskDefinition(Construct, String, ITaskDefinitionProps)
Constructs a new instance of the TaskDefinition class.
public TaskDefinition(Construct scope, string id, ITaskDefinitionProps props)
Parameters
- scope Constructs.Construct
- id System.String
- props ITaskDefinitionProps
Properties
Compatibility
The task launch type compatibility requirement.
public virtual Compatibility Compatibility { get; }
Property Value
Containers
The container definitions.
protected virtual ContainerDefinition[] Containers { get; }
Property Value
DefaultContainer
Default container for this task.
public virtual ContainerDefinition DefaultContainer { get; set; }
Property Value
Remarks
Load balancers will send traffic to this container. The first essential container that is added to this task will become the default container.
EphemeralStorageGiB
The amount (in GiB) of ephemeral storage to be allocated to the task.
public virtual Nullable<double> EphemeralStorageGiB { get; }
Property Value
System.Nullable<System.Double>
Remarks
Only supported in Fargate platform version 1.4.0 or later.
ExecutionRole
Execution role for this task definition.
public virtual IRole ExecutionRole { get; }
Property Value
Family
The name of a family that this task definition is registered to.
public virtual string Family { get; }
Property Value
System.String
Remarks
A family groups multiple versions of a task definition.
InferenceAccelerators
Public getter method to access list of inference accelerators attached to the instance.
public virtual IInferenceAccelerator[] InferenceAccelerators { get; }
Property Value
IsEc2Compatible
Return true if the task definition can be run on an EC2 cluster.
public virtual bool IsEc2Compatible { get; }
Property Value
System.Boolean
IsExternalCompatible
Return true if the task definition can be run on a ECS anywhere cluster.
public virtual bool IsExternalCompatible { get; }
Property Value
System.Boolean
IsFargateCompatible
Return true if the task definition can be run on a Fargate cluster.
public virtual bool IsFargateCompatible { get; }
Property Value
System.Boolean
NetworkMode
The networking mode to use for the containers in the task.
public virtual NetworkMode NetworkMode { get; }
Property Value
ReferencesSecretJsonField
Whether this task definition has at least a container that references a specific JSON field of a secret stored in Secrets Manager.
public virtual Nullable<bool> ReferencesSecretJsonField { get; }
Property Value
System.Nullable<System.Boolean>
TaskDefinitionArn
The full Amazon Resource Name (ARN) of the task definition.
public virtual string TaskDefinitionArn { get; }
Property Value
System.String
Remarks
Attribute: true
TaskRole
The name of the IAM role that grants containers in the task permission to call AWS APIs on your behalf.
public virtual IRole TaskRole { get; }
Property Value
Methods
AddContainer(String, IContainerDefinitionOptions)
Adds a new container to the task definition.
public virtual ContainerDefinition AddContainer(string id, IContainerDefinitionOptions props)
Parameters
- id System.String
- props IContainerDefinitionOptions
Returns
AddExtension(ITaskDefinitionExtension)
Adds the specified extension to the task definition.
public virtual void AddExtension(ITaskDefinitionExtension extension)
Parameters
- extension ITaskDefinitionExtension
Remarks
Extension can be used to apply a packaged modification to a task definition.
AddFirelensLogRouter(String, IFirelensLogRouterDefinitionOptions)
Adds a firelens log router to the task definition.
public virtual FirelensLogRouter AddFirelensLogRouter(string id, IFirelensLogRouterDefinitionOptions props)
Parameters
- id System.String
- props IFirelensLogRouterDefinitionOptions
Returns
AddInferenceAccelerator(IInferenceAccelerator)
Adds an inference accelerator to the task definition.
public virtual void AddInferenceAccelerator(IInferenceAccelerator inferenceAccelerator)
Parameters
- inferenceAccelerator IInferenceAccelerator
AddPlacementConstraint(PlacementConstraint)
Adds the specified placement constraint to the task definition.
public virtual void AddPlacementConstraint(PlacementConstraint constraint)
Parameters
- constraint PlacementConstraint
AddToExecutionRolePolicy(PolicyStatement)
Adds a policy statement to the task execution IAM role.
public virtual void AddToExecutionRolePolicy(PolicyStatement statement)
Parameters
- statement PolicyStatement
AddToTaskRolePolicy(PolicyStatement)
Adds a policy statement to the task IAM role.
public virtual void AddToTaskRolePolicy(PolicyStatement statement)
Parameters
- statement PolicyStatement
AddVolume(IVolume)
Adds a volume to the task definition.
public virtual void AddVolume(IVolume volume)
Parameters
- volume IVolume
FindContainer(String)
Returns the container that match the provided containerName.
public virtual ContainerDefinition FindContainer(string containerName)
Parameters
- containerName System.String
Returns
FromTaskDefinitionArn(Construct, String, String)
Imports a task definition from the specified task definition ARN.
public static ITaskDefinition FromTaskDefinitionArn(Construct scope, string id, string taskDefinitionArn)
Parameters
- scope Constructs.Construct
- id System.String
- taskDefinitionArn System.String
Returns
Remarks
The task will have a compatibility of EC2+Fargate.
FromTaskDefinitionAttributes(Construct, String, ITaskDefinitionAttributes)
Create a task definition from a task definition reference.
public static ITaskDefinition FromTaskDefinitionAttributes(Construct scope, string id, ITaskDefinitionAttributes attrs)
Parameters
- scope Constructs.Construct
- id System.String
- attrs ITaskDefinitionAttributes
Returns
ObtainExecutionRole()
Creates the task execution IAM role if it doesn't already exist.
public virtual IRole ObtainExecutionRole()
Returns
Validate()
Validates the task definition.
protected override string[] Validate()
Returns
System.String[]