Skip to content
22K
Console

Cluster

Reference doc for the `sst.aws.Cluster` component.

The Cluster component lets you create a cluster of containers to your app. It uses Amazon ECS.

Create a Cluster

sst.config.ts
const vpc = new sst.aws.Vpc("MyVpc");
const cluster = new sst.aws.Cluster("MyCluster", { vpc });

Once created, you can add the following to your cluster:

  • Services: These are containers that are always running, like web or application servers. They automatically restart if they fail.
  • Tasks: These are containers that are used for long running asynchronous work, like data processing.

Constructor

new Cluster(name, args, opts?)

Parameters

ClusterArgs

transform?

Type Object

Transform how this component creates its underlying resources.

transform.cluster?

Type ClusterArgs | (args: ClusterArgs, opts: ComponentResourceOptions, name: string) => void

Transform the ECS Cluster resource.

vpc

Type Vpc | Input<Object>

The VPC to use for the cluster.

Create a Vpc component.

sst.config.ts
const myVpc = new sst.aws.Vpc("MyVpc");

And pass it in.

{
vpc: myVpc
}

By default, both the load balancer and the services are deployed in public subnets. The above is equivalent to:

{
vpc: {
id: myVpc.id,
securityGroups: myVpc.securityGroups,
containerSubnets: myVpc.publicSubnets,
loadBalancerSubnets: myVpc.publicSubnets,
cloudmapNamespaceId: myVpc.nodes.cloudmapNamespace.id,
cloudmapNamespaceName: myVpc.nodes.cloudmapNamespace.name
}
}

vpc.cloudmapNamespaceId

Type Input<string>

The ID of the Cloud Map namespace to use for the service.

vpc.cloudmapNamespaceName

Type Input<string>

The name of the Cloud Map namespace to use for the service.

vpc.containerSubnets?

Type Input<Input<string>[]>

A list of subnet IDs in the VPC to place the containers in.

vpc.id

Type Input<string>

The ID of the VPC.

vpc.loadBalancerSubnets

Type Input<Input<string>[]>

A list of subnet IDs in the VPC to place the load balancer in.

vpc.securityGroups

Type Input<Input<string>[]>

A list of VPC security group IDs for the service.

Properties

id

Type Output<string>

The cluster ID.

nodes

Type Object

The underlying resources this component creates.

nodes.cluster

Type Output<Cluster>

The Amazon ECS Cluster.

Methods

static get

Cluster.get(name, args, opts?)

Parameters

Returns Cluster

Reference an existing ECS Cluster with the given ID. This is useful when you create a cluster in one stage and want to share it in another. It avoids having to create a new cluster in the other stage.

Imagine you create a cluster in the dev stage. And in your personal stage frank, instead of creating a new cluster, you want to share the same cluster from dev.

sst.config.ts
const cluster = $app.stage === "frank"
? sst.aws.Cluster.get("MyCluster", {
id: "arn:aws:ecs:us-east-1:123456789012:cluster/app-dev-MyCluster",
vpc,
})
: new sst.aws.Cluster("MyCluster", { vpc });

Here arn:aws:ecs:us-east-1:123456789012:cluster/app-dev-MyCluster is the ID of the cluster created in the dev stage. You can find these by outputting the cluster ID in the dev stage.

sst.config.ts
return {
id: cluster.id,
};

ClusterGetArgs

id

Type Input<string>

The ID of the cluster.

vpc

vpc.cloudmapNamespaceId

Type Input<string>

The ID of the Cloud Map namespace to use for the service.

vpc.cloudmapNamespaceName

Type Input<string>

The name of the Cloud Map namespace to use for the service.

vpc.containerSubnets?

Type Input<Input<string>[]>

A list of subnet IDs in the VPC to place the containers in.

vpc.id

Type Input<string>

The ID of the VPC.

vpc.loadBalancerSubnets

Type Input<Input<string>[]>

A list of subnet IDs in the VPC to place the load balancer in.

vpc.securityGroups

Type Input<Input<string>[]>

A list of VPC security group IDs for the service.