Skip to content
GitHub Discord

AWS Hono container with Redis

Creates a hit counter app with Hono and Redis.

This deploys Hono API as a Fargate service to ECS and it’s linked to Redis.

sst.config.ts
new sst.aws.Service("MyService", {
cluster,
link: [redis],
loadBalancer: {
ports: [{ listen: "80/http", forward: "3000/http" }],
},
dev: {
command: "npm run dev",
},
});

Since our Redis cluster is in a VPC, we’ll need a tunnel to connect to it from our local machine.

Terminal window
sudo npx sst tunnel install

This 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.

Terminal window
npx sst dev

Now if you go to http://localhost:3000 you’ll see a counter update as you refresh the page.

Finally, you can deploy it by:

  1. Using the Dockerfile that’s included in this example.

  2. This compiles our TypeScript file, so we’ll need add the following to the tsconfig.json.

    tsconfig.json
    {
    "compilerOptions": {
    // ...
    "outDir": "./dist"
    },
    "exclude": ["node_modules"]
    }
  3. Install TypeScript.

    Terminal window
    npm install typescript --save-dev
  4. And add a build script to our package.json.

    package.json
    "scripts": {
    // ...
    "build": "tsc"
    }

And finally, running npx sst deploy --stage production.

sst.config.ts
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: "npm run dev",
},
});

View the full example.