Task
Reference doc for the `sst.aws.Task` component.
The Task
component is internally used by the Cluster
component to deploy tasks to
Amazon ECS. It uses AWS Fargate.
This component is returned by the addTask
method of the Cluster
component.
Constructor
Parameters
-
name
string
-
args
TaskArgs
-
opts?
ComponentResourceOptions
TaskArgs
architecture?
Type Input
<
“
x86_64
”
|
“
arm64
”
>
Default “x86_64”
The CPU architecture of the container.
cluster
Type Cluster
The cluster to use for the task.
command?
Type Input
<
Input
<
string
>
[]
>
The command to override the default command in the container.
containers?
Type Input
<
Object
>
[]
The containers to run in the task.
By default this starts a single container. To add multiple containers in the task, pass in an array of containers args.
If you specify 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[].cpu?
Type “
${number} vCPU
”
The amount of CPU allocated to the container.
By default, a container can use up to all the CPU allocated to all the containers. If set, this container is capped at this allocation even if more idle CPU is available.
The sum of all the containers’ CPU must be less than or equal to the total available CPU.
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[].image.target?
Type Input
<
string
>
The stage to build up to. Same as the top-level image.target
.
containers[].logging?
Type Input
<
Object
>
Configure the 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[].memory?
Type “
${number} GB
”
The amount of memory allocated to the container.
By default, a container can use up to all the memory allocated to all the containers. If set, the container is capped at this allocation. If exceeded, the container will be killed even if there is idle memory available.
The sum of all the containers’ memory must be less than or equal to the total available memory.
containers[].name
Type Input
<
string
>
The name of the container.
This is used as the --name
option in the Docker run command.
containers[].ssm?
Type Input
<
Record
<
string
, Input
<
string
>
>
>
Key-value pairs of AWS Systems Manager Parameter Store parameter ARNs or AWS Secrets
Manager secret ARNs. The values will be loaded into the container as environment
variables. Same as the top-level ssm
.
containers[].volumes?
Type Input
<
Object
>
[]
Mount Amazon EFS file systems into the container. Same as the top-level
efs
.
containers[].volumes[].efs
Type Input
<
Efs
|
Object
>
The Amazon EFS file system to mount.
containers[].volumes[].efs.accessPoint
Type Input
<
string
>
The ID of the EFS access point.
containers[].volumes[].efs.fileSystem
Type Input
<
string
>
The ID of the EFS file system.
containers[].volumes[].path
Type Input
<
string
>
The path to mount the volume.
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. If there are multiple containers, this is the total amount of CPU shared across all the containers.
dev?
Type false
|
Object
Configure how this component works in sst dev
.
By default, your task in not deployed in sst dev
. Instead, you can set the dev.command
and it’ll run locally in a Tasks tab in the sst dev
multiplexer.
Here’s what happens when you run sst dev
:
- A stub version of your task is deployed. This is a minimal image that starts up faster.
- When your task is started through the SDK, the stub version is provisioned. This can take roughly 10 - 20 seconds.
- The stub version proxies the payload to your local machine using the same events system used by Live.
- The
dev.command
is called to run your task locally. Once complete, the stub version of your task is stopped as well.
The advantage with this approach is that you can test your task locally even it’s invoked remotely, or through a cron job.
Since the stub version runs while your task is running, you are charged for the time it takes to run. This is roughly $0.02 per hour.
To disable this and deploy your task in sst dev
, pass in false
. Read more about
Live and sst dev
.
dev.command?
Type Input
<
string
>
The command that sst dev
runs in dev mode.
dev.directory?
Type Input
<
string
>
Default Uses the image.dockerfile
path
Change the directory from where the command
is run.
entrypoint?
Type Input
<
string
[]
>
The entrypoint that overrides 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.
executionRole?
Type Input
<
string
>
Default Creates a new role
Assigns the given IAM role name to AWS ECS to launch and manage the containers. This allows you to pass in a previously created role.
By default, a new IAM role is created.
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.
image.tags?
Type Input
<
Input
<
string
>
[]
>
Tags to apply to the Docker image.
image.target?
Type Input
<
string
>
The stage to build up to in a multi-stage Dockerfile.
link?
Type Input
<
any
[]
>
Link resources to your containers. 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 containers.
logging?
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 “1 month”
The duration the logs are kept in CloudWatch.
memory?
Type “
${number} GB
”
Default “0.5 GB”
The amount of memory allocated to the container. If there are multiple containers, this is the total amount of memory shared across all the containers.
permissions?
Type Input
<
Object
[]
>
Permissions and the resources that you need to access. These permissions are used to create the task role.
Allow the container to read and write to an S3 bucket called my-bucket
.
Allow the container to perform all actions on an S3 bucket called my-bucket
.
Granting the container permissions to access all resources.
permissions[].actions
Type string
[]
The IAM actions that can be performed.
permissions[].effect?
Type “
allow
”
|
“
deny
”
Default “allow”
Configures whether the permission is allowed or denied.
permissions[].resources
Type Input
<
string
>
[]
The resourcess specified using the IAM ARN format.
ssm?
Type Input
<
Record
<
string
, Input
<
string
>
>
>
Key-value pairs of AWS Systems Manager Parameter Store parameter ARNs or AWS Secrets Manager secret ARNs. The values will be loaded into the container as environment variables.
storage?
Type “
${number} GB
”
Default “20 GB”
The amount of ephemeral storage (in GB) allocated to the container.
taskRole?
Type Input
<
string
>
Default Creates a new role
Assigns the given IAM role name to the containers. This allows you to pass in a previously created role.
By default, a new IAM role is created. It’ll update this role if you add permissions
or
link
resources.
However, if you pass in a role, you’ll need to update it manually if you add permissions
or link
resources.
transform?
Type Object
Transform how this component creates its underlying resources.
transform.executionRole?
Type RoleArgs
|
(
args
:
RoleArgs
,
opts
:
ComponentResourceOptions
,
name
:
string
)
=>
void
Transform the ECS Execution IAM Role resource.
transform.image?
Type ImageArgs
|
(
args
:
ImageArgs
,
opts
:
ComponentResourceOptions
,
name
:
string
)
=>
void
Transform the Docker Image resource.
transform.logGroup?
Type LogGroupArgs
|
(
args
:
LogGroupArgs
,
opts
:
ComponentResourceOptions
,
name
:
string
)
=>
void
Transform the CloudWatch log 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.
volumes?
Type Input
<
Object
>
[]
Mount Amazon EFS file systems into the container.
Create an EFS file system.
And pass it in.
Or pass in a the EFS file system ID.
volumes[].efs
Type Input
<
Efs
|
Object
>
The Amazon EFS file system to mount.
volumes[].efs.accessPoint
Type Input
<
string
>
The ID of the EFS access point.
volumes[].efs.fileSystem
Type Input
<
string
>
The ID of the EFS file system.
volumes[].path
Type Input
<
string
>
The path to mount the volume.
vpc
Type Vpc
|
Output
<
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.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
nodes
Type Object
The underlying resources this component creates.
nodes.executionRole
Type Role
The Amazon ECS Execution Role.
nodes.taskDefinition
Type Output
<
TaskDefinition
>
The Amazon ECS Task Definition.
nodes.taskRole
Type Role
The Amazon ECS Task Role.
taskDefinition
Type Output
<
string
>
The ARN of the ECS Task Definition.
SDK
Use the SDK in your runtime to interact with your infrastructure.
Links
This is accessible through the Resource
object in the SDK.
-
assignPublicIp
boolean
Whether to assign a public IP address to the task.
-
cluster
string
The ARN of the cluster this task is deployed to.
-
containers
string
[]
The names of the containers in the task.
-
securityGroups
string
[]
The security groups for the task.
-
subnets
string
[]
The subnets for the task.
-
taskDefinition
string
The ARN of the ECS Task Definition.
The task
client SDK is available through the following.
If you are not using Node.js, you can use the AWS SDK instead. For example, you can call
RunTask
to
run a task.
describe
Parameters
Returns Promise
<
DescribeResponse
>
Get the details of a given task.
For example, let’s say you had previously started a task.
You can use that to get the details of the task.
If you are not using Node.js, you can use the AWS SDK and call
DescribeTasks
.
run
Parameters
-
resource
Resource
-
environment?
Record
<
string
,string
>
-
options?
RunOptions
Returns Promise
<
RunResponse
>
Runs a task.
For example, let’s say you have defined a task.
You can then run the task in your application with the SDK.
This internally calls an AWS SDK API that returns an array of tasks. But in our case, there’s only one task.
The taskArn
is the ARN of the task. You can use it to call the describe
or stop
functions.
You can also pass in any environment variables to the task.
If you are not using Node.js, you can use the AWS SDK and call
RunTask
.
stop
Parameters
Returns Promise
<
StopResponse
>
Stops a task.
For example, let’s say you had previously started a task.
You can stop the task with the following.
Stopping a task is asnychronous. When you call stop
, AWS marks a task to be stopped,
but it may take a few minutes for the task to actually stop.
In most cases you probably don’t need to check if it has been stopped. But if necessary,
you can use the describe
function to get a task’s status.
If you are not using Node.js, you can use the AWS SDK and call
StopTask
.
DescribeResponse
DescribeResponse.arn
Type string
The ARN of the task.
DescribeResponse.response
The raw response from the AWS ECS DescribeTasks API.
DescribeResponse.status
Type string
The status of the task.
Options
Type Object
Options.aws?
Options.aws.accessKeyId?
Type string
Options.aws.allHeaders?
Type boolean
Options.aws.appendSessionToken?
Type boolean
Options.aws.cache?
Type Map
<
string
, ArrayBuffer
<
>
>
Options.aws.datetime?
Type string
Options.aws.region?
Type string
Options.aws.secretAccessKey?
Type string
Options.aws.service?
Type string
Options.aws.sessionToken?
Type string
Options.aws.signQuery?
Type boolean
Options.aws.singleEncode?
Type boolean
Resource
Type Object
Resource.assignPublicIp
Type boolean
Whether to assign a public IP address to the task.
Resource.cluster
Type string
The ARN of the cluster.
Resource.containers
Type string
[]
The names of the containers in the task.
Resource.securityGroups
Type string
[]
The security groups to use for the task.
Resource.subnets
Type string
[]
The subnets to use for the task.
Resource.taskDefinition
Type string
The ARN of the task definition.
RunOptions
Type Object
RunOptions.aws?
RunOptions.aws.accessKeyId?
Type string
RunOptions.aws.allHeaders?
Type boolean
RunOptions.aws.appendSessionToken?
Type boolean
RunOptions.aws.cache?
Type Map
<
string
, ArrayBuffer
<
>
>
RunOptions.aws.datetime?
Type string
RunOptions.aws.region?
Type string
RunOptions.aws.secretAccessKey?
Type string
RunOptions.aws.service?
Type string
RunOptions.aws.sessionToken?
Type string
RunOptions.aws.signQuery?
Type boolean
RunOptions.aws.singleEncode?
Type boolean
RunOptions.capacity?
Type “
fargate
”
|
“
spot
”
Default “fargate”
Configure the capacity provider; regular Fargate or Fargate Spot, for this task.
RunResponse
RunResponse.arn
Type string
The ARN of the task.
RunResponse.response
The raw response from the AWS ECS RunTask API.
RunResponse.status
Type string
The status of the task.
StopResponse
StopResponse.arn
Type string
The ARN of the task.
StopResponse.response
The raw response from the AWS ECS StopTask API.
StopResponse.status
Type string
The status of the task.