1. Packages
  2. AWS
  3. API Docs
  4. ecs
  5. getTaskDefinition
Viewing docs for AWS v5.43.0 (Older version)
published on Tuesday, Mar 10, 2026 by Pulumi
aws logo
Viewing docs for AWS v5.43.0 (Older version)
published on Tuesday, Mar 10, 2026 by Pulumi

    The ECS task definition data source allows access to details of a specific AWS ECS task definition.

    Example Usage

    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(() => 
    {
        var mongoTaskDefinition = Aws.Ecs.GetTaskDefinition.Invoke(new()
        {
            TaskDefinition = mongoEcs / taskDefinitionTaskDefinition.Family,
        });
    
        var foo = new Aws.Ecs.Cluster("foo");
    
        var mongoEcs_taskDefinitionTaskDefinition = new Aws.Ecs.TaskDefinition("mongoEcs/taskDefinitionTaskDefinition", new()
        {
            Family = "mongodb",
            ContainerDefinitions = @"[
      {
        ""cpu"": 128,
        ""environment"": [{
          ""name"": ""SECRET"",
          ""value"": ""KEY""
        }],
        ""essential"": true,
        ""image"": ""mongo:latest"",
        ""memory"": 128,
        ""memoryReservation"": 64,
        ""name"": ""mongodb""
      }
    ]
    ",
        });
    
        var mongoService = new Aws.Ecs.Service("mongoService", new()
        {
            Cluster = foo.Id,
            DesiredCount = 2,
            TaskDefinition = mongoTaskDefinition.Apply(getTaskDefinitionResult => getTaskDefinitionResult.Arn),
        });
    
    });
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/ecs"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		mongoTaskDefinition, err := ecs.LookupTaskDefinition(ctx, &ecs.LookupTaskDefinitionArgs{
    			TaskDefinition: mongoEcs / taskDefinitionTaskDefinition.Family,
    		}, nil)
    		if err != nil {
    			return err
    		}
    		foo, err := ecs.NewCluster(ctx, "foo", nil)
    		if err != nil {
    			return err
    		}
    		_, err = ecs.NewTaskDefinition(ctx, "mongoEcs/taskDefinitionTaskDefinition", &ecs.TaskDefinitionArgs{
    			Family: pulumi.String("mongodb"),
    			ContainerDefinitions: pulumi.String(`[
      {
        "cpu": 128,
        "environment": [{
          "name": "SECRET",
          "value": "KEY"
        }],
        "essential": true,
        "image": "mongo:latest",
        "memory": 128,
        "memoryReservation": 64,
        "name": "mongodb"
      }
    ]
    `),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = ecs.NewService(ctx, "mongoService", &ecs.ServiceArgs{
    			Cluster:        foo.ID(),
    			DesiredCount:   pulumi.Int(2),
    			TaskDefinition: *pulumi.String(mongoTaskDefinition.Arn),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.aws.ecs.EcsFunctions;
    import com.pulumi.aws.ecs.inputs.GetTaskDefinitionArgs;
    import com.pulumi.aws.ecs.Cluster;
    import com.pulumi.aws.ecs.TaskDefinition;
    import com.pulumi.aws.ecs.TaskDefinitionArgs;
    import com.pulumi.aws.ecs.Service;
    import com.pulumi.aws.ecs.ServiceArgs;
    import java.util.List;
    import java.util.ArrayList;
    import java.util.Map;
    import java.io.File;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    
    public class App {
        public static void main(String[] args) {
            Pulumi.run(App::stack);
        }
    
        public static void stack(Context ctx) {
            final var mongoTaskDefinition = EcsFunctions.getTaskDefinition(GetTaskDefinitionArgs.builder()
                .taskDefinition(mongoEcs / taskDefinitionTaskDefinition.family())
                .build());
    
            var foo = new Cluster("foo");
    
            var mongoEcs_taskDefinitionTaskDefinition = new TaskDefinition("mongoEcs/taskDefinitionTaskDefinition", TaskDefinitionArgs.builder()        
                .family("mongodb")
                .containerDefinitions("""
    [
      {
        "cpu": 128,
        "environment": [{
          "name": "SECRET",
          "value": "KEY"
        }],
        "essential": true,
        "image": "mongo:latest",
        "memory": 128,
        "memoryReservation": 64,
        "name": "mongodb"
      }
    ]
                """)
                .build());
    
            var mongoService = new Service("mongoService", ServiceArgs.builder()        
                .cluster(foo.id())
                .desiredCount(2)
                .taskDefinition(mongoTaskDefinition.applyValue(getTaskDefinitionResult -> getTaskDefinitionResult.arn()))
                .build());
    
        }
    }
    
    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    
    const mongoTaskDefinition = aws.ecs.getTaskDefinition({
        taskDefinition: mongoEcs / taskDefinitionTaskDefinition.family,
    });
    const foo = new aws.ecs.Cluster("foo", {});
    const mongoEcs_taskDefinitionTaskDefinition = new aws.ecs.TaskDefinition("mongoEcs/taskDefinitionTaskDefinition", {
        family: "mongodb",
        containerDefinitions: `[
      {
        "cpu": 128,
        "environment": [{
          "name": "SECRET",
          "value": "KEY"
        }],
        "essential": true,
        "image": "mongo:latest",
        "memory": 128,
        "memoryReservation": 64,
        "name": "mongodb"
      }
    ]
    `,
    });
    const mongoService = new aws.ecs.Service("mongoService", {
        cluster: foo.id,
        desiredCount: 2,
        taskDefinition: mongoTaskDefinition.then(mongoTaskDefinition => mongoTaskDefinition.arn),
    });
    
    import pulumi
    import pulumi_aws as aws
    
    mongo_task_definition = aws.ecs.get_task_definition(task_definition=mongo_ecs / task_definition_task_definition["family"])
    foo = aws.ecs.Cluster("foo")
    mongo_ecs_task_definition_task_definition = aws.ecs.TaskDefinition("mongoEcs/taskDefinitionTaskDefinition",
        family="mongodb",
        container_definitions="""[
      {
        "cpu": 128,
        "environment": [{
          "name": "SECRET",
          "value": "KEY"
        }],
        "essential": true,
        "image": "mongo:latest",
        "memory": 128,
        "memoryReservation": 64,
        "name": "mongodb"
      }
    ]
    """)
    mongo_service = aws.ecs.Service("mongoService",
        cluster=foo.id,
        desired_count=2,
        task_definition=mongo_task_definition.arn)
    

    Example coming soon!

    Using getTaskDefinition

    Two invocation forms are available. The direct form accepts plain arguments and either blocks until the result value is available, or returns a Promise-wrapped result. The output form accepts Input-wrapped arguments and returns an Output-wrapped result.

    function getTaskDefinition(args: GetTaskDefinitionArgs, opts?: InvokeOptions): Promise<GetTaskDefinitionResult>
    function getTaskDefinitionOutput(args: GetTaskDefinitionOutputArgs, opts?: InvokeOptions): Output<GetTaskDefinitionResult>
    def get_task_definition(task_definition: Optional[str] = None,
                            opts: Optional[InvokeOptions] = None) -> GetTaskDefinitionResult
    def get_task_definition_output(task_definition: Optional[pulumi.Input[str]] = None,
                            opts: Optional[InvokeOptions] = None) -> Output[GetTaskDefinitionResult]
    func LookupTaskDefinition(ctx *Context, args *LookupTaskDefinitionArgs, opts ...InvokeOption) (*LookupTaskDefinitionResult, error)
    func LookupTaskDefinitionOutput(ctx *Context, args *LookupTaskDefinitionOutputArgs, opts ...InvokeOption) LookupTaskDefinitionResultOutput

    > Note: This function is named LookupTaskDefinition in the Go SDK.

    public static class GetTaskDefinition 
    {
        public static Task<GetTaskDefinitionResult> InvokeAsync(GetTaskDefinitionArgs args, InvokeOptions? opts = null)
        public static Output<GetTaskDefinitionResult> Invoke(GetTaskDefinitionInvokeArgs args, InvokeOptions? opts = null)
    }
    public static CompletableFuture<GetTaskDefinitionResult> getTaskDefinition(GetTaskDefinitionArgs args, InvokeOptions options)
    public static Output<GetTaskDefinitionResult> getTaskDefinition(GetTaskDefinitionArgs args, InvokeOptions options)
    
    fn::invoke:
      function: aws:ecs/getTaskDefinition:getTaskDefinition
      arguments:
        # arguments dictionary

    The following arguments are supported:

    TaskDefinition string
    Family for the latest ACTIVE revision, family and revision (family:revision) for a specific revision in the family, the ARN of the task definition to access to.
    TaskDefinition string
    Family for the latest ACTIVE revision, family and revision (family:revision) for a specific revision in the family, the ARN of the task definition to access to.
    taskDefinition String
    Family for the latest ACTIVE revision, family and revision (family:revision) for a specific revision in the family, the ARN of the task definition to access to.
    taskDefinition string
    Family for the latest ACTIVE revision, family and revision (family:revision) for a specific revision in the family, the ARN of the task definition to access to.
    task_definition str
    Family for the latest ACTIVE revision, family and revision (family:revision) for a specific revision in the family, the ARN of the task definition to access to.
    taskDefinition String
    Family for the latest ACTIVE revision, family and revision (family:revision) for a specific revision in the family, the ARN of the task definition to access to.

    getTaskDefinition Result

    The following output properties are available:

    Arn string
    ARN of the task definition.
    ArnWithoutRevision string
    ARN of the Task Definition with the trailing revision removed. This may be useful for situations where the latest task definition is always desired. If a revision isn't specified, the latest ACTIVE revision is used. See the AWS documentation for details.
    ExecutionRoleArn string
    ARN of the task execution role that the Amazon ECS container agent and the Docker.
    Family string
    Family of this task definition.
    Id string
    The provider-assigned unique ID for this managed resource.
    NetworkMode string
    Docker networking mode to use for the containers in this task.
    Revision int
    Revision of this task definition.
    Status string
    Status of this task definition.
    TaskDefinition string
    TaskRoleArn string
    ARN of the IAM role that containers in this task can assume.
    Arn string
    ARN of the task definition.
    ArnWithoutRevision string
    ARN of the Task Definition with the trailing revision removed. This may be useful for situations where the latest task definition is always desired. If a revision isn't specified, the latest ACTIVE revision is used. See the AWS documentation for details.
    ExecutionRoleArn string
    ARN of the task execution role that the Amazon ECS container agent and the Docker.
    Family string
    Family of this task definition.
    Id string
    The provider-assigned unique ID for this managed resource.
    NetworkMode string
    Docker networking mode to use for the containers in this task.
    Revision int
    Revision of this task definition.
    Status string
    Status of this task definition.
    TaskDefinition string
    TaskRoleArn string
    ARN of the IAM role that containers in this task can assume.
    arn String
    ARN of the task definition.
    arnWithoutRevision String
    ARN of the Task Definition with the trailing revision removed. This may be useful for situations where the latest task definition is always desired. If a revision isn't specified, the latest ACTIVE revision is used. See the AWS documentation for details.
    executionRoleArn String
    ARN of the task execution role that the Amazon ECS container agent and the Docker.
    family String
    Family of this task definition.
    id String
    The provider-assigned unique ID for this managed resource.
    networkMode String
    Docker networking mode to use for the containers in this task.
    revision Integer
    Revision of this task definition.
    status String
    Status of this task definition.
    taskDefinition String
    taskRoleArn String
    ARN of the IAM role that containers in this task can assume.
    arn string
    ARN of the task definition.
    arnWithoutRevision string
    ARN of the Task Definition with the trailing revision removed. This may be useful for situations where the latest task definition is always desired. If a revision isn't specified, the latest ACTIVE revision is used. See the AWS documentation for details.
    executionRoleArn string
    ARN of the task execution role that the Amazon ECS container agent and the Docker.
    family string
    Family of this task definition.
    id string
    The provider-assigned unique ID for this managed resource.
    networkMode string
    Docker networking mode to use for the containers in this task.
    revision number
    Revision of this task definition.
    status string
    Status of this task definition.
    taskDefinition string
    taskRoleArn string
    ARN of the IAM role that containers in this task can assume.
    arn str
    ARN of the task definition.
    arn_without_revision str
    ARN of the Task Definition with the trailing revision removed. This may be useful for situations where the latest task definition is always desired. If a revision isn't specified, the latest ACTIVE revision is used. See the AWS documentation for details.
    execution_role_arn str
    ARN of the task execution role that the Amazon ECS container agent and the Docker.
    family str
    Family of this task definition.
    id str
    The provider-assigned unique ID for this managed resource.
    network_mode str
    Docker networking mode to use for the containers in this task.
    revision int
    Revision of this task definition.
    status str
    Status of this task definition.
    task_definition str
    task_role_arn str
    ARN of the IAM role that containers in this task can assume.
    arn String
    ARN of the task definition.
    arnWithoutRevision String
    ARN of the Task Definition with the trailing revision removed. This may be useful for situations where the latest task definition is always desired. If a revision isn't specified, the latest ACTIVE revision is used. See the AWS documentation for details.
    executionRoleArn String
    ARN of the task execution role that the Amazon ECS container agent and the Docker.
    family String
    Family of this task definition.
    id String
    The provider-assigned unique ID for this managed resource.
    networkMode String
    Docker networking mode to use for the containers in this task.
    revision Number
    Revision of this task definition.
    status String
    Status of this task definition.
    taskDefinition String
    taskRoleArn String
    ARN of the IAM role that containers in this task can assume.

    Package Details

    Repository
    AWS Classic pulumi/pulumi-aws
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the aws Terraform Provider.
    aws logo
    Viewing docs for AWS v5.43.0 (Older version)
    published on Tuesday, Mar 10, 2026 by Pulumi
      Try Pulumi Cloud free. Your team will thank you.