> ## Documentation Index
> Fetch the complete documentation index at: https://docs.formae.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploy an ECS service

> An AWS infrastructure pattern, deployed with formae.

A load-balanced containerized service on ECS, with its own networking. One forma
provisions the VPC and public subnets, the security groups, an ECS cluster and
task definition, an Application Load Balancer with a listener and target group,
and the ECS service behind it.

```mermaid theme={"languages":{"custom":["/languages/pkl.json"]}}
flowchart LR
  target["aws-target"]:::tgt

  subgraph stack["ecs-hello-world"]
    direction LR
    vpc["VPC"]:::res
    igw["Internet gateway"]:::res
    subnet1["Public subnet 1"]:::res
    subnet2["Public subnet 2"]:::res
    albSg["ALB security group"]:::res
    taskSg["Task security group"]:::res
    cluster["ECS cluster"]:::res
    taskDef["Task definition"]:::res
    alb["Load balancer"]:::res
    tg["Target group"]:::res
    listener["Listener"]:::res
    service["ECS service"]:::res

    vpc --> igw
    vpc --> subnet1
    vpc --> subnet2
    vpc --> albSg
    vpc --> taskSg
    subnet1 --> alb
    subnet2 --> alb
    albSg --> alb
    alb --> listener
    tg --> listener
    cluster --> service
    taskDef --> service
    tg --> service
    taskSg --> service
    subnet1 --> service
    subnet2 --> service
  end

  target --> stack

  classDef tgt fill:#FF8201,stroke:#B25900,color:#ffffff
  classDef res fill:#FFF3E6,stroke:#FF8201,color:#02024B
  style stack fill:#ffffff,stroke:#02024B,stroke-width:2px,stroke-dasharray:6 4,color:#02024B
```

**Deploy.** Apply the example forma. formae orders the resources by their
dependencies automatically, so the VPC comes up before the subnets, the load
balancer before the service, and so on:

```bash theme={"languages":{"custom":["/languages/pkl.json"]}}
formae apply --mode reconcile \
  /opt/pel/formae/examples/formae-plugin-aws/ecs-hello-world/ecs_hello_world.pkl
```

**Verify.** Once the command completes, the stack's resources are under
management:

```bash theme={"languages":{"custom":["/languages/pkl.json"]}}
formae inventory resources --query="type:AWS::ECS::Service"
```

**Tear down.** Remove everything the forma created:

```bash theme={"languages":{"custom":["/languages/pkl.json"]}}
formae destroy \
  /opt/pel/formae/examples/formae-plugin-aws/ecs-hello-world/ecs_hello_world.pkl
```

The full forma is in the
[ecs-hello-world example](https://github.com/platform-engineering-labs/formae-plugin-aws/tree/main/examples/ecs-hello-world).
