1. Packages
  2. AWS Classic
  3. API Docs
  4. ecs
  5. getTaskDefinition

Try AWS Native preview for resources not in the classic version.

AWS Classic v6.42.0 published on Wednesday, Jun 26, 2024 by Pulumi

aws.ecs.getTaskDefinition

Explore with Pulumi AI

aws logo

Try AWS Native preview for resources not in the classic version.

AWS Classic v6.42.0 published on Wednesday, Jun 26, 2024 by Pulumi

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

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    
    const mongoTaskDefinition = new aws.ecs.TaskDefinition("mongo", {
        family: "mongodb",
        containerDefinitions: `[
      {
        "cpu": 128,
        "environment": [{
          "name": "SECRET",
          "value": "KEY"
        }],
        "essential": true,
        "image": "mongo:latest",
        "memory": 128,
        "memoryReservation": 64,
        "name": "mongodb"
      }
    ]
    `,
    });
    // Simply specify the family to find the latest ACTIVE revision in that family.
    const mongo = aws.ecs.getTaskDefinitionOutput({
        taskDefinition: mongoTaskDefinition.family,
    });
    const foo = new aws.ecs.Cluster("foo", {name: "foo"});
    const mongoService = new aws.ecs.Service("mongo", {
        name: "mongo",
        cluster: foo.id,
        desiredCount: 2,
        taskDefinition: mongo.apply(mongo => mongo.arn),
    });
    
    import pulumi
    import pulumi_aws as aws
    
    mongo_task_definition = aws.ecs.TaskDefinition("mongo",
        family="mongodb",
        container_definitions="""[
      {
        "cpu": 128,
        "environment": [{
          "name": "SECRET",
          "value": "KEY"
        }],
        "essential": true,
        "image": "mongo:latest",
        "memory": 128,
        "memoryReservation": 64,
        "name": "mongodb"
      }
    ]
    """)
    # Simply specify the family to find the latest ACTIVE revision in that family.
    mongo = aws.ecs.get_task_definition_output(task_definition=mongo_task_definition.family)
    foo = aws.ecs.Cluster("foo", name="foo")
    mongo_service = aws.ecs.Service("mongo",
        name="mongo",
        cluster=foo.id,
        desired_count=2,
        task_definition=mongo.arn)
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ecs"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		mongoTaskDefinition, err := ecs.NewTaskDefinition(ctx, "mongo", &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
    		}
    		// Simply specify the family to find the latest ACTIVE revision in that family.
    		mongo := ecs.LookupTaskDefinitionOutput(ctx, ecs.GetTaskDefinitionOutputArgs{
    			TaskDefinition: mongoTaskDefinition.Family,
    		}, nil)
    		foo, err := ecs.NewCluster(ctx, "foo", &ecs.ClusterArgs{
    			Name: pulumi.String("foo"),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = ecs.NewService(ctx, "mongo", &ecs.ServiceArgs{
    			Name:         pulumi.String("mongo"),
    			Cluster:      foo.ID(),
    			DesiredCount: pulumi.Int(2),
    			TaskDefinition: mongo.ApplyT(func(mongo ecs.GetTaskDefinitionResult) (*string, error) {
    				return &mongo.Arn, nil
    			}).(pulumi.StringPtrOutput),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(() => 
    {
        var mongoTaskDefinition = new Aws.Ecs.TaskDefinition("mongo", new()
        {
            Family = "mongodb",
            ContainerDefinitions = @"[
      {
        ""cpu"": 128,
        ""environment"": [{
          ""name"": ""SECRET"",
          ""value"": ""KEY""
        }],
        ""essential"": true,
        ""image"": ""mongo:latest"",
        ""memory"": 128,
        ""memoryReservation"": 64,
        ""name"": ""mongodb""
      }
    ]
    ",
        });
    
        // Simply specify the family to find the latest ACTIVE revision in that family.
        var mongo = Aws.Ecs.GetTaskDefinition.Invoke(new()
        {
            TaskDefinition = mongoTaskDefinition.Family,
        });
    
        var foo = new Aws.Ecs.Cluster("foo", new()
        {
            Name = "foo",
        });
    
        var mongoService = new Aws.Ecs.Service("mongo", new()
        {
            Name = "mongo",
            Cluster = foo.Id,
            DesiredCount = 2,
            TaskDefinition = mongo.Apply(getTaskDefinitionResult => getTaskDefinitionResult.Arn),
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.aws.ecs.TaskDefinition;
    import com.pulumi.aws.ecs.TaskDefinitionArgs;
    import com.pulumi.aws.ecs.EcsFunctions;
    import com.pulumi.aws.ecs.inputs.GetTaskDefinitionArgs;
    import com.pulumi.aws.ecs.Cluster;
    import com.pulumi.aws.ecs.ClusterArgs;
    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) {
            var mongoTaskDefinition = new TaskDefinition("mongoTaskDefinition", TaskDefinitionArgs.builder()
                .family("mongodb")
                .containerDefinitions("""
    [
      {
        "cpu": 128,
        "environment": [{
          "name": "SECRET",
          "value": "KEY"
        }],
        "essential": true,
        "image": "mongo:latest",
        "memory": 128,
        "memoryReservation": 64,
        "name": "mongodb"
      }
    ]
                """)
                .build());
    
            // Simply specify the family to find the latest ACTIVE revision in that family.
            final var mongo = EcsFunctions.getTaskDefinition(GetTaskDefinitionArgs.builder()
                .taskDefinition(mongoTaskDefinition.family())
                .build());
    
            var foo = new Cluster("foo", ClusterArgs.builder()
                .name("foo")
                .build());
    
            var mongoService = new Service("mongoService", ServiceArgs.builder()
                .name("mongo")
                .cluster(foo.id())
                .desiredCount(2)
                .taskDefinition(mongo.applyValue(getTaskDefinitionResult -> getTaskDefinitionResult).applyValue(mongo -> mongo.applyValue(getTaskDefinitionResult -> getTaskDefinitionResult.arn())))
                .build());
    
        }
    }
    
    resources:
      foo:
        type: aws:ecs:Cluster
        properties:
          name: foo
      mongoTaskDefinition:
        type: aws:ecs:TaskDefinition
        name: mongo
        properties:
          family: mongodb
          containerDefinitions: |
            [
              {
                "cpu": 128,
                "environment": [{
                  "name": "SECRET",
                  "value": "KEY"
                }],
                "essential": true,
                "image": "mongo:latest",
                "memory": 128,
                "memoryReservation": 64,
                "name": "mongodb"
              }
            ]        
      mongoService:
        type: aws:ecs:Service
        name: mongo
        properties:
          name: mongo
          cluster: ${foo.id}
          desiredCount: 2 # Track the latest ACTIVE revision
          taskDefinition: ${mongo.arn}
    variables:
      # Simply specify the family to find the latest ACTIVE revision in that family.
      mongo:
        fn::invoke:
          Function: aws:ecs:getTaskDefinition
          Arguments:
            taskDefinition: ${mongoTaskDefinition.family}
    

    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)
    // Output-based functions aren't available in Java yet
    
    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

    Try AWS Native preview for resources not in the classic version.

    AWS Classic v6.42.0 published on Wednesday, Jun 26, 2024 by Pulumi