Skip to content
v2.276.0

TaskDefinitionAttributes Struct ​

A reference to an existing task definition.

Example ​

ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { aws_ecs as ecs } from 'aws-cdk-lib';
import { aws_iam as iam } from 'aws-cdk-lib';

declare const role: iam.Role;
const taskDefinitionAttributes: ecs.TaskDefinitionAttributes = {
  taskDefinitionArn: 'taskDefinitionArn',

  // the properties below are optional
  compatibility: ecs.Compatibility.EC2,
  executionRole: role,
  networkMode: ecs.NetworkMode.NONE,
  taskRole: role,
};
python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
from aws_cdk import aws_ecs as ecs
from aws_cdk import aws_iam as iam

# role: iam.Role

task_definition_attributes = ecs.TaskDefinitionAttributes(
    task_definition_arn="taskDefinitionArn",

    # the properties below are optional
    compatibility=ecs.Compatibility.EC2,
    execution_role=role,
    network_mode=ecs.NetworkMode.NONE,
    task_role=role
)
java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.services.ecs.*;
import software.amazon.awscdk.services.iam.*;

Role role;

TaskDefinitionAttributes taskDefinitionAttributes = TaskDefinitionAttributes.builder()
        .taskDefinitionArn("taskDefinitionArn")

        // the properties below are optional
        .compatibility(Compatibility.EC2)
        .executionRole(role)
        .networkMode(NetworkMode.NONE)
        .taskRole(role)
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK.AWS.ECS;
using Amazon.CDK.AWS.IAM;

Role role;

var taskDefinitionAttributes = new TaskDefinitionAttributes {
    TaskDefinitionArn = "taskDefinitionArn",

    // the properties below are optional
    Compatibility = Compatibility.EC2,
    ExecutionRole = role,
    NetworkMode = NetworkMode.NONE,
    TaskRole = role
};
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"

var role Role

taskDefinitionAttributes := &TaskDefinitionAttributes{
	TaskDefinitionArn: jsii.String("taskDefinitionArn"),

	// the properties below are optional
	Compatibility: awscdk.Aws_ecs.Compatibility_EC2,
	ExecutionRole: role,
	NetworkMode: awscdk.*Aws_ecs.NetworkMode_NONE,
	TaskRole: role,
}

Properties ​

compatibilityoptionalCompatibilitycompatibilityoptionalCompatibilitycompatibilityoptionalCompatibilityCompatibilityoptionalCompatibilityCompatibilityoptionalCompatibility= Compatibility.EC2_AND_FARGATE#
What launch types this task definition should be compatible with.
executionRoleoptionalIRoleexecution_roleoptionalIRoleexecutionRoleoptionalIRoleExecutionRoleoptionalIRoleExecutionRoleoptionalIRole= undefined#
The IAM role that grants containers and Fargate agents permission to make AWS API calls on your behalf.

Some tasks do not have an execution role.

networkModeoptionalNetworkModenetwork_modeoptionalNetworkModenetworkModeoptionalNetworkModeNetworkModeoptionalNetworkModeNetworkModeoptionalNetworkMode#
The networking mode to use for the containers in the task.

Default: Network mode cannot be provided to the imported task.

taskDefinitionArnstringtask_definition_arnstrtaskDefinitionArnStringTaskDefinitionArnstringTaskDefinitionArn*stringrequired#
The arn of the task definition.
taskRoleoptionalIRoletask_roleoptionalIRoletaskRoleoptionalIRoleTaskRoleoptionalIRoleTaskRoleoptionalIRole#
The name of the IAM role that grants containers in the task permission to call AWS APIs on your behalf.

Default: Permissions cannot be granted to the imported task.