aws4fetch is a JavaScript library designed for signing AWS requests using the AWS Signature Version 4 process. It provides a compact client (6.4kb minified, 2.5kb gzipped) tailored for modern JavaScript environments that natively support the Web `fetch` API and `SubtleCrypto`. This makes it particularly well-suited for serverless edge computing platforms like Cloudflare Workers, as well as modern web browsers. The library is currently at version `1.0.20` and maintains an active release cadence, frequently adding support for new AWS features and refining existing functionality. A key differentiator is its built-in exponential backoff with full jitter retry strategy, enhancing the reliability of AWS interactions. Unlike traditional Node.js-centric AWS SDKs, `aws4fetch` leverages browser-native APIs, prioritizing minimalism and performance in environments where those APIs are readily available.
npm install aws4fetchVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to instantiate `AwsClient` with credentials and use it to invoke an AWS Lambda function via the `fetch` API, handling potential errors.
For Node.js environments, ensure `fetch` and `SubtleCrypto` are available, either by using a recent Node.js version (v18+ for global fetch) or by installing and importing polyfills like `node-fetch` and a Web Crypto API implementation.
Upgrade your bundler or Node.js version to one that supports `package.json#exports`. Ensure you are using ESM `import` statements for `aws4fetch`. If stuck on an older setup, consider using a bundler configuration to resolve the package correctly or stay on an older `aws4fetch` version if possible.
Verify your Node.js project is configured to handle ESM correctly (e.g., `"type": "module"` in `package.json` or `.mjs` file extensions) and that your bundler is configured for ESM output where appropriate.
Update your project's TypeScript version to a recent stable release that is compatible with the latest `aws4fetch` types. Review any custom type declarations or workarounds you might have had for `aws4fetch`.
Ensure that any dynamically generated hostnames comply with the 63-character label limit. Review hostname generation logic for AWS services, particularly S3, R2, and Backblaze, which have specific hostname conventions.
For Node.js v18+, `fetch` is global. For older Node.js versions, install a `fetch` polyfill (e.g., `npm install node-fetch`) and ensure it's loaded before `aws4fetch` is used: `import fetch from 'node-fetch'; global.fetch = fetch;`.
In Node.js, you might need a Web Crypto API polyfill. Consider libraries like `@peculiar/webcrypto` if your Node.js version doesn't provide it globally or if you're in a specific environment that omits it.
Ensure your bundler (e.g., Webpack, Rollup, esbuild) is up-to-date and configured to handle ESM and `package.json#exports` correctly. Always use `import { AwsClient } from 'aws4fetch'` and avoid `require()` where possible.Verify `aws4fetch` is correctly installed. Ensure your `tsconfig.json` has `"moduleResolution": "bundler"` or `"node16"` (or appropriate for modern ESM) and that your TypeScript version is compatible (v1.0.18 fixed type issues for newer TS). Reinstall `@types/aws4fetch` if it exists, though `aws4fetch` ships its own types.
No dependency data recorded yet.