Skip to main content
Run a command with all the resources linked to the environment. This is useful for running scripts against your infrastructure.
sst shell node my-script.js

How it works

For example, let’s say you have the following resources in your app:
sst.config.ts
new sst.aws.Bucket("MyMainBucket");
new sst.aws.Bucket("MyAdminBucket");
We can now write a script that can access both these resources with the JS SDK:
my-script.js
import { Resource } from "sst";

console.log(Resource.MyMainBucket.name, Resource.MyAdminBucket.name);
And run the script with sst shell:
sst shell node my-script.js
This’ll have access to all the buckets from above.
Run the command with -- to pass arguments to it.
To pass arguments into the script, you’ll need to prefix it using --:
sst shell -- node my-script.js --arg1 --arg2

Opening a shell session

If no command is passed in, it opens a shell session with the linked resources:
sst shell
This is useful if you want to run multiple commands, all while accessing the resources in your app.

Targeting a component

Optionally, you can run this for a specific component by passing in the name of the component:
sst shell --target MyComponent
Here the linked resources for MyComponent and its environment variables are available.

Options

--target

Only run it for the given component.
sst shell --target MyComponent
This will only load the resources linked to MyComponent.

Arguments

command

command
string
A command to run.
The command to run with linked resources available. If not provided, opens an interactive shell.
sst shell node script.js

Examples

Open a shell session

Open an interactive shell with all resources linked:
sst shell

Run a Node.js script

sst shell node my-script.js

Run a Python script

sst shell python my-script.py

Pass arguments to the script

Use -- to pass arguments:
sst shell -- node my-script.js --arg1 --arg2

Run for a specific component

sst shell --target MyComponent node script.js

Run database migrations

sst shell npx prisma migrate dev

Build docs developers (and LLMs) love