Lambda

Like other resources, Lambda can be deployed with awscli. But I'll use SST for better developer experience.

I'll also use hono as the web framework. It's minimal and works on other platforms as well.

Permission

SST requires a bunch of permissions to work correctly. For now, grant AdministratorAccess permission. More on this.

Init

bunx sst@latest init
bun add hono

Update sst.config.ts:

  async run() {
    const fn = new sst.aws.Function("Foo", {
      url: true,
      handler: "index.handler",
    })

    return {
      api: fn.url,
    }
  }

Add index.ts

import { Hono } from "hono"
import { handle } from "hono/aws-lambda"

const app = new Hono()
  .get("/", async (c) => {
    return c.text("Hono")
  })

export const handler = handle(app)

Start dev server:

bunx sst dev

Deployment

bunx sst deploy --stage prod

More On SST

SST combines IaC with a web framework, allowing you to allocate AWS resource in a declarative way.

Add a bucket in sst.config.ts:

+   const bucket = new sst.aws.Bucket("bucket0")
    const hono = new sst.aws.Function("Foo", {
      url: true,
+     link: [bucket],
      handler: "index.handler",
    })

Then you can use it in the application like this:

const objects = await s3.send(
  new ListObjectsV2Command({
    Bucket: Resource.bucket0.name,
  }),
)

SST ensures the bucket is created.