Aws4fetch: a tiny AWS client


Hey there – author of aws4 here, which I know a few of you have used to connect to AWS services from your workers.

I’m happy to announce I’ve finally gotten around to pushing up aws4fetch – an AWS client that you can use in Cloudflare Workers (and modern browsers) – much smaller than aws4 and uses the crypto libraries available in CF Workers directly:

It looks like this:

import { AwsClient } from 'aws4fetch'

const aws = new AwsClient({ accessKeyId: MY_ACCESS_KEY, secretAccessKey: MY_SECRET_KEY })

const response = await aws.fetch(MY_LAMBDA_URL, { body: JSON.stringify(event) })

You can see this in action in a proof-of-concept we developed at Bustle that does server-side rendering and fetching data from AWS Lambda in a CF worker:


Thank you for putting this together. I had just implemented aws4 in cloudflare then found this . Luckily wasn’t hard to migrate.

Question: The response from the lambda function returns a json object that contains the headers and body. Thats fine, I can retrieve them and insert into the response before sending.


To do that, it requires reading the response into memory to gain those details. Does anyone know of a way to simply return the aws.fetch(…) command, which would then stream the result instead of reading into memory (thus avoiding the memory limitations) but still replace the header/body fields into their corresponding fields in the response back to client?

The goal I’m hoping to achieve is have the results be the same format when using serverless lambda local (which must perform this conversion) for testing and using cloudflare workers for production.