SDK
Interact with linked resources in your functions in a typesafe way.
The JS SDK is an npm package that you can use in your runtime code to interact with your infrastructure.
You can use the SDK in your functions, frontends, and container applications. You can access links from components in a typesafe way. And some components come with SDK clients that you can use.
Currently, the SDK is only available for JavaScript and TypeScript. Support for other languages is coming soon.
Installation
Install the npm package.
Usage
The SDK allows you to access links from your components and some components come with a client that you can use.
Links
Import Resource
to access the linked resources.
Here we are assuming that a bucket has been linked to the function. Here’s what that could look like.
How it works
In the above example, Resource.MyBucket.name
works because it’s been injected into the function package on sst dev
and sst deploy
.
For functions, this is injected into the globalThis
using esbuild and for frontends, it’s injected into the process.env
object.
The JS SDK first checks the process.env
and then the globalThis
for the linked resources. You can read more about how the links are injected.
Client
Components like the Realtime
component come with a client that you can use.
For example, realtime.authorizer
let’s you create the handler for the authorizer function that Realtime
needs.