Service
Reference doc for the `sst.aws.Service` component.
The Service
component is internally used by the Cluster
component to deploy services to
Amazon ECS. It uses AWS Fargate.
This component is returned by the addService
method of the Cluster
component.
Constructor
Parameters
-
name
string
-
args
ServiceArgs
-
opts?
ComponentResourceOptions
ServiceArgs
architecture?
Type Input
<
“
x86_64
”
|
“
arm64
”
>
Default “x86_64”
The CPU architecture of the container in this service.
cluster
cluster.arn
Type Input
<
string
>
The ARN of the cluster.
cluster.name
Type Input
<
string
>
The name of the cluster.
command?
Type Input
<
string
[]
>
The command to override the default command in the container.
containers?
Type Input
<
Object
>
[]
The containers to run in the service.
By default this starts a single container. To add multiple containers in the service, pass in an array of containers args.
If you sepcify containers
, you cannot list the above args at the top-level. For example,
you cannot pass in image
at the top level.
You will need to pass in image
as a part of the containers
.
containers[].command?
Type Input
<
string
[]
>
The command to override the default command in the container. Same as the top-level
command
.
containers[].dev?
Type Object
Configure how this container works in sst dev
. Same as the top-level
dev
.
containers[].dev.autostart?
Type Input
<
boolean
>
Configure if you want to automatically start this when sst dev
starts. Same as the
top-level dev.autostart
.
containers[].dev.command?
Type Input
<
string
>
The command that sst dev
runs to start this in dev mode. Same as the top-level
dev.command
.
containers[].dev.directory?
Type Input
<
string
>
Change the directory from where the command
is run. Same as the top-level
dev.directory
.
containers[].entrypoint?
Type Input
<
string
[]
>
The entrypoint to override the default entrypoint in the container. Same as the top-level
entrypoint
.
containers[].environment?
Type Input
<
Record
<
string
, Input
<
string
>
>
>
Key-value pairs of values that are set as container environment variables. Same as the
top-level environment
.
containers[].image?
Type Input
<
string
|
Object
>
Configure the Docker image for the container. Same as the top-level image
.
containers[].image.args?
Type Input
<
Record
<
string
, Input
<
string
>
>
>
Key-value pairs of build args. Same as the top-level image.args
.
containers[].image.context?
Type Input
<
string
>
The path to the Docker build context. Same as the top-level
image.context
.
containers[].image.dockerfile?
Type Input
<
string
>
The path to the Dockerfile. Same as the top-level
image.dockerfile
.
containers[].logging?
Type Input
<
Object
>
Configure the service’s logs in CloudWatch. Same as the top-level logging
.
containers[].logging.retention?
Type Input
<
“
1 day
”
|
“
3 days
”
|
“
5 days
”
|
“
1 week
”
|
“
2 weeks
”
|
“
1 month
”
|
“
2 months
”
|
“
3 months
”
|
“
4 months
”
|
“
5 months
”
|
“
6 months
”
|
“
1 year
”
|
“
13 months
”
|
“
18 months
”
|
“
2 years
”
|
“
3 years
”
|
“
5 years
”
|
“
6 years
”
|
“
7 years
”
|
“
8 years
”
|
“
9 years
”
|
“
10 years
”
|
“
forever
”
>
The duration the logs are kept in CloudWatch. Same as the top-level
logging.retention
.
containers[].name
Type Input
<
string
>
The name of the container.
This is used as the --name
option in the Docker run command.
cpu?
Type “
0.25 vCPU
”
|
“
0.5 vCPU
”
|
“
1 vCPU
”
|
“
2 vCPU
”
|
“
4 vCPU
”
|
“
8 vCPU
”
|
“
16 vCPU
”
Default “0.25 vCPU”
The amount of CPU allocated to the container in this service.
dev?
Type false
|
Object
Configure how this component works in sst dev
.
Instead of deploying your service, this starts it locally. It’s run
as a separate process in the sst dev
multiplexer. Read more about
sst dev
.
To disable dev mode, pass in false
.
dev.autostart?
Type Input
<
boolean
>
Default true
Configure if you want to automatically start this when sst dev
starts. You can still
start it manually later.
dev.command?
Type Input
<
string
>
The command that sst dev
runs to start this in dev mode. This is the command you run
when you want to run your service locally.
dev.directory?
Type Input
<
string
>
Default Uses the image.dockerfile
path
Change the directory from where the command
is run.
dev.url?
Type Input
<
string
>
Default “http://url-unavailable-in-dev.mode”
The url
when this is running in dev mode.
Since this component is not deployed in sst dev
, there is no real URL. But if you are
using this component’s url
or linking to this component’s url
, it can be useful to
have a placeholder URL. It avoids having to handle it being undefined
.
entrypoint?
Type Input
<
string
[]
>
The entrypoint to override the default entrypoint in the container.
environment?
Type Input
<
Record
<
string
, Input
<
string
>
>
>
Key-value pairs of values that are set as container environment variables. The keys need to:
- Start with a letter
- Be at least 2 characters long
- Contain only letters, numbers, or underscores
image?
Type Input
<
string
|
Object
>
Default Build a Docker image from the Dockerfile in the root directory.
Configure the Docker build command for building the image or specify a pre-built image.
Building a Docker image.
Prior to building the image, SST will automatically add the .sst
directory
to the .dockerignore
if not already present.
Alternatively, you can pass in a pre-built image.
image.args?
Type Input
<
Record
<
string
, Input
<
string
>
>
>
Key-value pairs of build args to pass to the Docker build command.
image.context?
Type Input
<
string
>
Default ”.”
The path to the Docker build context. The path is relative to your project’s sst.config.ts
.
To change where the Docker build context is located.
image.dockerfile?
Type Input
<
string
>
Default “Dockerfile”
The path to the Dockerfile.
The path is relative to the build context
.
To use a different Dockerfile.
link?
Type Input
<
any
[]
>
Link resources to your service. This will:
- Grant the permissions needed to access the resources.
- Allow you to access it in your app using the SDK.
Takes a list of components to link to the service.
logging?
Type Input
<
Object
>
Default { retention: “forever” }
Configure the service’s logs in CloudWatch.
logging.retention?
Type Input
<
“
1 day
”
|
“
3 days
”
|
“
5 days
”
|
“
1 week
”
|
“
2 weeks
”
|
“
1 month
”
|
“
2 months
”
|
“
3 months
”
|
“
4 months
”
|
“
5 months
”
|
“
6 months
”
|
“
1 year
”
|
“
13 months
”
|
“
18 months
”
|
“
2 years
”
|
“
3 years
”
|
“
5 years
”
|
“
6 years
”
|
“
7 years
”
|
“
8 years
”
|
“
9 years
”
|
“
10 years
”
|
“
forever
”
>
Default “forever”
The duration the logs are kept in CloudWatch.
memory?
Type “
${number} GB
”
Default “0.5 GB”
The amount of memory allocated to the container in this service.
permissions?
Type Input
<
Object
[]
>
Permissions and the resources that the service needs to access. These permissions are used to create the service’s task role.
Allow the service to read and write to an S3 bucket called my-bucket
.
Allow the service to perform all actions on an S3 bucket called my-bucket
.
Granting the service permissions to access all resources.
permissions[].actions
Type string
[]
The IAM actions that can be performed.
permissions[].resources
Type Input
<
string
>
[]
The resourcess specified using the IAM ARN format.
public?
Type Input
<
Object
>
Configure a public endpoint for the service. When configured, a load balancer will be created to route traffic to the containers. By default, the endpoint is an autogenerated load balancer URL.
You can also add a custom domain for the public endpoint.
public.domain?
Type Input
<
string
|
Object
>
Set a custom domain for your public endpoint.
Automatically manages domains hosted on AWS Route 53, Cloudflare, and Vercel. For other
providers, you’ll need to pass in a cert
that validates domain ownership and add the
DNS records.
By default this assumes the domain is hosted on Route 53.
For domains hosted on Cloudflare.
public.domain.cert?
Type Input
<
string
>
The ARN of an ACM (AWS Certificate Manager) certificate that proves ownership of the domain. By default, a certificate is created and validated automatically.
To manually set up a domain on an unsupported provider, you’ll need to:
- Validate that you own the domain by creating an ACM certificate. You can either validate it by setting a DNS record or by verifying an email sent to the domain owner.
- Once validated, set the certificate ARN as the
cert
and setdns
tofalse
. - Add the DNS records in your provider to point to the load balancer endpoint.
public.domain.dns?
Type Input
<
false
|
sst.aws.dns
|
sst.cloudflare.dns
|
sst.vercel.dns
>
Default sst.aws.dns
The DNS provider to use for the domain. Defaults to the AWS.
Takes an adapter that can create the DNS records on the provider. This can automate validating the domain and setting up the DNS routing.
Supports Route 53, Cloudflare, and Vercel adapters. For other providers, you’ll need
to set dns
to false
and pass in a certificate validating ownership via cert
.
Specify the hosted zone ID for the Route 53 domain.
Use a domain hosted on Cloudflare, needs the Cloudflare provider.
Use a domain hosted on Vercel, needs the Vercel provider.
public.domain.name
Type Input
<
string
>
The custom domain you want to use.
Can also include subdomains based on the current stage.
public.ports
Type Input
<
Object
[]
>
Configure the mapping for the ports the public endpoint listens to and forwards to the service. This supports two types of protocols:
- Application Layer Protocols:
http
andhttps
. This’ll create an Application Load Balancer. - Network Layer Protocols:
tcp
,udp
,tcp_udp
, andtls
. This’ll create a Network Load Balancer.
You can not configure both application and network layer protocols for the same service.
Here we are listening on port 80
and forwarding it to the service on port 8080
.
The forward
port and protocol defaults to the listen
port and protocol. So in this
case both are 80/http
.
If multiple containers are configured via the containers
argument, you need to
specify which container the traffic should be forwarded to.
public.ports[].container?
Type Input
<
string
>
Default The container name when there is only one container.
The name of the container to forward the traffic to.
If there is only one container, this is not needed. The traffic is automatically forwarded to the container.
If there is more than one container, this is required.
public.ports[].forward?
Type Input
<
“
${number}/https
”
|
“
${number}/http
”
|
“
${number}/tcp
”
|
“
${number}/udp
”
|
“
${number}/tcp_udp
”
|
“
${number}/tls
”
>
Default The same port and protocol as listen
.
The port and protocol of the container the service forwards the traffic to. Uses the
format {port}/{protocol}
.
public.ports[].listen
Type Input
<
“
${number}/https
”
|
“
${number}/http
”
|
“
${number}/tcp
”
|
“
${number}/udp
”
|
“
${number}/tcp_udp
”
|
“
${number}/tls
”
>
The port and protocol the service listens on. Uses the format {port}/{protocol}
.
scaling?
Type Input
<
Object
>
Default { min: 1, max: 1 }
Configure the service to automatically scale up or down based on the CPU or memory utilization of a container. By default, scaling is disabled and the service will run in a single container.
scaling.cpuUtilization?
Type Input
<
number
>
Default 70
The target CPU utilization percentage to scale up or down. It’ll scale up when the CPU utilization is above the target and scale down when it’s below the target.
scaling.max?
Type Input
<
number
>
Default 1
The maximum number of containers to scale up to.
scaling.memoryUtilization?
Type Input
<
number
>
Default 70
The target memory utilization percentage to scale up or down. It’ll scale up when the memory utilization is above the target and scale down when it’s below the target.
scaling.min?
Type Input
<
number
>
Default 1
The minimum number of containers to scale down to.
storage?
Type “
${number} GB
”
Default “21 GB”
The amount of ephemeral storage (in GB) allocated to a container in this service.
transform?
Type Object
Transform how this component creates its underlying resources.
transform.image?
Type ImageArgs
|
(
args
:
ImageArgs
,
opts
:
ComponentResourceOptions
,
name
:
string
)
=>
void
Transform the Docker Image resource.
transform.listener?
Type ListenerArgs
|
(
args
:
ListenerArgs
,
opts
:
ComponentResourceOptions
,
name
:
string
)
=>
void
Transform the AWS Load Balancer listener resource.
transform.loadBalancer?
Type LoadBalancerArgs
|
(
args
:
LoadBalancerArgs
,
opts
:
ComponentResourceOptions
,
name
:
string
)
=>
void
Transform the AWS Load Balancer resource.
transform.loadBalancerSecurityGroup?
Type SecurityGroupArgs
|
(
args
:
SecurityGroupArgs
,
opts
:
ComponentResourceOptions
,
name
:
string
)
=>
void
Transform the AWS Security Group resource for the Load Balancer.
transform.logGroup?
Type LogGroupArgs
|
(
args
:
LogGroupArgs
,
opts
:
ComponentResourceOptions
,
name
:
string
)
=>
void
Transform the CloudWatch log group resource.
transform.service?
Type ServiceArgs
|
(
args
:
ServiceArgs
,
opts
:
ComponentResourceOptions
,
name
:
string
)
=>
void
Transform the ECS Service resource.
transform.target?
Type TargetGroupArgs
|
(
args
:
TargetGroupArgs
,
opts
:
ComponentResourceOptions
,
name
:
string
)
=>
void
Transform the AWS Load Balancer target group resource.
transform.taskDefinition?
Type TaskDefinitionArgs
|
(
args
:
TaskDefinitionArgs
,
opts
:
ComponentResourceOptions
,
name
:
string
)
=>
void
Transform the ECS Task Definition resource.
transform.taskRole?
Type RoleArgs
|
(
args
:
RoleArgs
,
opts
:
ComponentResourceOptions
,
name
:
string
)
=>
void
Transform the ECS Task IAM Role resource.
vpc
Type Vpc
|
Input
<
Object
>
The VPC to use 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.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.
vpc.serviceSubnets
Type Input
<
Input
<
string
>
[]
>
A list of private subnet IDs in the VPC to place the services in.
Properties
nodes
Type Object
The underlying resources this component creates.
nodes.loadBalancer
Type LoadBalancer
The Amazon Elastic Load Balancer.
nodes.service
Type Output
<
string
>
The Amazon ECS Service.
nodes.taskDefinition
Type TaskDefinition
The Amazon ECS Task Definition.
nodes.taskRole
Type Role
The Amazon ECS Task Role.
service
Type Output
<
string
>
The name of the Cloud Map service.
url
Type Output
<
string
>
The URL of the service.
If public.domain
is set, this is the URL with the custom domain.
Otherwise, it’s the autogenerated load balancer URL.
SDK
Use the SDK in your runtime to interact with your infrastructure.
Links
This is accessible through the Resource
object in the SDK.
-
service
string
The name of the Cloud Map service.
-
url
undefined
|
string
The URL of the service.
If
public.domain
is set, this is the URL with the custom domain. Otherwise, it’s the autogenerated load balancer URL.