Cluster
The Cluster component lets you create an ECS cluster for your app.
add Service and Task components to it.
const vpc = new sst.aws.Vpc("MyVpc");const cluster = new sst.aws.Cluster("MyCluster", { vpc });Once created, you can add the following to it:
Service: These are containers that are always running, like web or application servers. They automatically restart if they fail.Task: These are containers that are used for long running asynchronous work, like data processing.
Constructor
new Cluster(name, args, opts?)Parameters
-
namestring -
argsClusterArgs -
opts?ComponentResourceOptions
ClusterArgs
transform?
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.
const myVpc = new sst.aws.Vpc("MyVpc");Or reference an existing VPC.
const myVpc = sst.aws.Vpc.get("MyVpc", { id: "vpc-12345678901234567"});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
nodes.cluster
Type Output<Cluster>
The Amazon ECS Cluster.
Methods
static get
Cluster.get(name, args, opts?)Parameters
The name of the component.namestring
The arguments to get the cluster.argsClusterGetArgs-
opts?ComponentResourceOptions
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.
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.
return { id: cluster.id,};ClusterGetArgs
id
Type Input<string>
The ID of the cluster.
vpc
Type Vpc | Input<Object>
The VPC used for the cluster.
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.