Reference Resources
Reference externally created resources in your app.
Referencing is the process of using some externally created resources in your SST app. But without having SST to manage them.
This is for when you have some resources that are either managed by a different team or a different IaC tool. Typically these are low-level resources and not SST’s built-in components.
How it works
When you create a resource in your SST app, two things happen. First, the resource is created by making a bunch of calls to your cloud provider. Second, SST makes a call to get the resource from the cloud provider. The data that it gets back is stored in your state.
When you reference a resource, it skips the creation step and just gets the resource. It does this every time you deploy. But the object you get in both cases is the same.
How to reference
You reference a resource by passing in a property of the resource. These properties are the same ones that you’d use if you were trying to import them.
We’ve compiled a list of the most commonly referenced low-level resources and their Import Properties.
Most low-level resources come with a static get
method that use this property to look up the resource.
Look up the resource
Say you want to reference a previously created S3 Bucket with the following name.
We are going use the static aws.s3.BucketV2.get
method.
This gives you the same bucket object that you’d get if you had created this resource in your app. Let’s take it a step further.
Make it linkable
You can use the sst.Linkable
component, to be able to link any property of this resource.
Here we are using the domain name of the bucket as an example.
Link to it
And link it to a function.
Now you can use the SDK to access them at runtime.
Check out the list of Import Properties if you want to reference other low-level resources.