tRPC on AWS with SST
Create and deploy a tRPC API in AWS with SST.
We are going to build a serverless tRPC API, a simple client, and deploy it to AWS using SST.
Before you get started:
1. Create a project
Let’s start by creating our app.
Init SST
Now let’s initialize SST in our app. Make sure you have the CLI installed.
This’ll create a sst.config.ts
file in your project root.
2. Add the API
Let’s add two Lambda functions; one for our tRPC server and one that’ll be our client. Update your sst.config.ts
.
We are linking the server to our client. This will allow us to access the URL of the server in our client.
Start dev mode
Start your app in dev mode. This runs your functions Live.
This will give you two URLs.
3. Create the server
Let’s create our tRPC server. Add the following to index.ts
.
We are creating a simple method called greet
that takes a string as an input.
Add the imports.
And install the npm packages.
4. Add the client
Now we’ll connect to our server in our client. Add the following to client.ts
.
Add the relevant imports. Notice we are importing the types for our API.
Install the client npm package.
Test your app
To test our app, hit the client URL.
This will print out Hello Patrick Star!
.
5. Deploy your app
Now let’s deploy your app.
Connect the console
As a next step, you can manage your app and view issues in the SST Console.
You can create a free account and connect it to your AWS account.