Registry / security / fetch-aws4

fetch-aws4

JSON →
library3.0.0jsnpmunverified

Thin wrapper around the native fetch API that automatically signs HTTP requests with AWS Signature V4 using credentials from environment variables or explicit options. Version 3.0.0 is ESM-only, ships TypeScript definitions, and supports custom wrappers via the exported `wrapper` function. It is lightweight with no external runtime dependencies, making it ideal for serverless environments and Node.js 18+. Unlike alternatives, it does not bundle its own fetch implementation, relying on the platform's native fetch.

npm install fetch-aws4
INSTALL
IMPORT
SIG · FETCH-AWS4
F
fetch-aws4
securityjavascriptv3.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import fetch from 'fetch-aws4'
const fetch = require('fetch-aws4')
The package is ESM-only since v3. CommonJS require will fail.
wrapper
import { wrapper } from 'fetch-aws4'
const { wrapper } = require('fetch-aws4')
Named export for creating a custom wrapper around any fetch-like function. ESM-only.
fetch
import fetch from 'fetch-aws4'
import { fetch } from 'fetch-aws4'
Default export is the signed fetch function. Named export 'fetch' does not exist.

Demonstrates making a signed GET request with explicit AWS credentials.

import fetch from 'fetch-aws4'; const response = await fetch('https://httpbin.org/get', { credentials: { accessKeyId: process.env.AWS_ACCESS_KEY_ID ?? '', secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY ?? '', sessionToken: process.env.AWS_SESSION_TOKEN } }); console.log(await response.json());
Debug
Known issues
breakingVersion 3.x is ESM-only and requires Node.js 18+. CommonJS require() will throw an error.
fix
Update to ES modules: use import statements or set type:module in package.json.
affects: >=3.0.0
gotchaThe default export replaces the global fetch. Ensure you don't have conflicting fetch implementations.
fix
Use the wrapper function to apply signing only where needed.
affects: >=3.0.0
deprecatedVersion 2.x used CommonJS with require('fetch-aws4'). It is deprecated and no longer maintained.
fix
Upgrade to v3 and migrate to ESM imports.
affects: >=2.0.0 <3.0.0
gotchaCredentials passed in options override environment variables entirely. Partial credentials will cause authentication failures.
fix
Always provide a complete set: accessKeyId, secretAccessKey, and optionally sessionToken.
affects: *
gotchaThe package relies on the native fetch API which is only available in Node.js 18+. Older runtimes will throw ReferenceError.
fix
Upgrade to Node.js 18+ or use a polyfill like node-fetch (but wrap with the wrapper function).
affects: >=3.0.0
Errors
Common errors & fixes
Cannot find module 'fetch-aws4'
Package not installed or ESM not configured properly.
fix
Run 'npm install fetch-aws4' and ensure your project uses ES modules (type:module in package.json or .mjs extension).
fetch is not a function
Using require() to import the ESM-only default export.
fix
Change to 'import fetch from \'fetch-aws4\'' and use ES module context.
CredentialsError: Missing credentials in config
AWS credentials not found in environment variables or options.
fix
Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables, or pass credentials object in options.
TypeError: The "url" argument must be of type string
First argument to fetch is not a string or URL object.
fix
Pass a valid URL string or URL object to fetch.
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
14
OpenAI (training)
1
Resources
fetch-aws4 — npm install fetch-aws4 · libregistry