Use Pulumi Crosswalk to deploy a basic load balanced ECS service

Nathan Peck profile picture
Nathan Peck
Senior Developer Advocate at AWS

Pulumi is an infrastructure as code framework for software engineers. Instead of writing YAML to define your infrastructure you can use higher level SDK commands, in a familiar programming language, and Pulumi will create the necessary resources for you automatically.

  • TypeScript
  • Python
  • Go
  • Java
  • YAML
  • C#
File: load-balanced-ecs.tsLanguage: ts
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as awsx from "@pulumi/awsx";

const cluster = new aws.ecs.Cluster("cluster", {});
const lb = new awsx.lb.ApplicationLoadBalancer("lb", {});
const service = new awsx.ecs.FargateService("service", {
  cluster: cluster.arn,
  assignPublicIp: true,
  desiredCount: 2,
  taskDefinitionArgs: {
    container: {
      image: "nginx:latest",
      cpu: 512,
      memory: 128,
      essential: true,
      portMappings: [{
        targetGroup: lb.defaultTargetGroup,
      }],
    },
  },
});
export const url = lb.loadBalancer.dnsName;

Setup

  1. Ensure that you have Pulumi setup on your system and configured to connect to AWS.
  2. Start a new Pulumi project
  3. Copy the code above into your Pulumi project

Usage

Show a preview of resources to be deployed:

Language: sh
pulumi preview

Deploy the resources to your AWS account:

Language: sh
pulumi up

Print out the URL of the deployed ECS service's load balancer:

Language: sh
pulumi stack output url

Tear down the stack and all of its resources:

Language: sh
pulumi destroy