AWS Bun Redis
Creates a hit counter app with Bun and Redis.
This deploys Bun as a Fargate service to ECS and it’s linked to Redis.
new sst.aws.Service("MyService", { cluster, loadBalancer: { ports: [{ listen: "80/http", forward: "3000/http" }], }, dev: { command: "bun dev", }, link: [redis],});We also have a couple of scripts. A dev script with a watcher and a build script
that used when we deploy to production.
{ "scripts": { "dev": "bun run --watch index.ts", "build": "bun build --target bun index.ts" },}Since our Redis cluster is in a VPC, we’ll need a tunnel to connect to it from our local machine.
sudo bun sst tunnel installThis needs sudo to create a network interface on your machine. You’ll only need to do this once on your machine.
To start your app locally run.
bun sst devNow if you go to http://localhost:3000 you’ll see a counter update as you refresh the page.
Finally, you can deploy it using bun sst deploy --stage production using a Dockerfile
that’s included in the example.
const vpc = new sst.aws.Vpc("MyVpc", { bastion: true });const redis = new sst.aws.Redis("MyRedis", { vpc });const cluster = new sst.aws.Cluster("MyCluster", { vpc });
new sst.aws.Service("MyService", { cluster, link: [redis], loadBalancer: { ports: [{ listen: "80/http", forward: "3000/http" }], }, dev: { command: "bun dev", },});View the full example.