Providers
Providers are the services that you can use in your app.
A provider is the infrastructure service that you can use in your app. It’s listed in your sst.config.ts
under providers
.
Install
To add a provider to your app run.
This command adds the provider to your config, installs the packages, and adds the namespace of the provider to your globals.
You can add multiple providers to your app.
The name of a provider comes from the URL of the provider in the Pulumi Registry. For example, https://www.pulumi.com/registry/packages/aws/
is the URL of the AWS Classic provider. So the name of the provider here is aws
.
Learn more about the sst add
command.
Configure
You can configure a provider in your sst.config.ts
. For example, to change the region for AWS.
You can check out the available list of options that you can configure for a provider over on the Pulumi docs. For example, here are the ones for AWS and Cloudflare.
Versions
In addition to these options, you can also pass in the version of the provider you want to use. By default, SST uses the latest version.
Credentials
Most providers will read your credentials from the environment. For example, for Cloudflare you might set your token like so.
However, some providers also allow you to pass in the credentials through the config.
Learn more about configuring providers.
Components
There are two types of components in your app.
- Native SST components, namespaced under
sst.*
- And Pulumi components, namespaced under
<provider>.*
The sst add
command injects the provider into the globals of your config.
For example, running sst add aws
will allow you to use all the components under the aws
namepsace.
Here we are using the BucketV2 component from the AWS Classic provider.
Functions
Aside from the components, there are a collection of functions that are exposed by a provider. These are listed in the Pulumi docs as getXXXXXX
on the sidebar.
For example, to get the AWS account being used in your app.
Or to get the current region.
Output versions
The above are async methods that return promises. That means that if you call these in your app, they’ll block the deployment of any resources that are defined after it.
So we instead recommend using the Output version of these functions. For example, if we wanted to set the above as environment variables in a function, we would do something like this
The aws.getXXXXOutput
functions typically return an object of type Output<primitive>
. Learn more about Outputs.
Home
The state of the deployed resources and your secrets are uploaded to a bucket in your provider. We call this the home
of your app.
You can specify which provider you’d like to use for this. Currently aws
and cloudflare
are supported.
When you specify your home provider, SST assumes you’d like to use that provider in your app as well and adds it to your providers internally. So the above is equivalent to doing this.
You can read more about the home
provider in Config.
Multiple providers
Aside from the providers that are listed in the providers
in your config, you can create your own providers. This is useful for multi-region or multi-account deployments.
Multi-region
You might want to create multiple providers in cases where some resources in your app need to go to one region, while others need to go to a separate region.
Let’s look at an example. Assume your app is normally deployed to us-west-1
. But you need to create an ACM certificate that needs to be deployed to us-east-1
.
Here the function is created in your default region, us-west-1
. While the certificate is created in us-east-1
.