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
- Provider Configuration: The AWS provider is configured to work in the
us-west-2
region. - ECS Task Definition Resource: The
aws_ecs_task_definition
resource defines the properties of the task. - Container Definitions: A container definition specifies the image, ports, and logging configurations.
- 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 upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.