1. Answers
  2. Building an AWS ECS Task Definition with Pulumi

How do I build an AWS ECS taskdefinition with Pulumi?

In this guide, we are going to create an Amazon ECS (Elastic Container Service) Task Definition using Pulumi. An ECS Task Definition is like a blueprint for your application, describing one or more containers (like Docker) needed to be run as part of the task.

We’ll cover the essential elements, such as:

  • defining container properties
  • specifying the resources (CPU, memory) containers need
  • configuring logging options

Here’s the program, let’s dig in:

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const myTask = new aws.ecs.TaskDefinition("my_task", {
    family: "my-task-family",
    requiresCompatibilities: ["FARGATE"],
    networkMode: "awsvpc",
    cpu: "256",
    memory: "512",
    containerDefinitions: JSON.stringify([{
        name: "my-container",
        image: "amazon/amazon-ecs-sample",
        essential: true,
        portMappings: [{
            containerPort: 80,
            hostPort: 80,
        }],
        logConfiguration: {
            logDriver: "awslogs",
            options: {
                "awslogs-group": "/ecs/my-task",
                "awslogs-region": "us-west-2",
                "awslogs-stream-prefix": "ecs",
            },
        },
    }]),
});
export const taskDefinitionArn = myTask.arn;

Key Points

  1. Provider Configuration: The AWS provider is configured to work in the us-west-2 region.
  2. ECS Task Definition Resource: The aws_ecs_task_definition resource defines the properties of the task.
  3. Container Definitions: A container definition specifies the image, ports, and logging configurations.
  4. Logging Configuration: AWS CloudWatch is set up to capture logs from the container.

Summary

In this example, we’ve defined an ECS task with Fargate compatibility. We specified container properties such as the image to use, port mappings, and logging configurations.

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up