Registry / devops / aws-sigv4-fetch

aws-sigv4-fetch

JSON →
library4.4.1jsnpmunverified

A lightweight wrapper around the native fetch API that automatically signs HTTP requests with AWS Signature Version 4 (SigV4) authentication. v4.4.1 is the latest stable release, actively maintained. Built on the official AWS SDK credential providers. Differentiates from alternatives by using the native `fetch` (no additional HTTP client), supporting both ESM and CommonJS, and working in Node.js >=18 and modern browsers. Credentials can be auto-resolved from environment in Node.js or provided explicitly for browser usage. Requires `@aws-sdk/credential-provider-node` (for Node.js), `@smithy/types`, and `@aws-sdk/credential-providers` as dependencies.

npm install aws-sigv4-fetch
INSTALL
IMPORT
SIG · AWS-SIGV4-FETCH
A
aws-sigv4-fetch
devopsjavascriptv4.4.1
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.

createSignedFetcher
import { createSignedFetcher } from 'aws-sigv4-fetch'
const createSignedFetcher = require('aws-sigv4-fetch');
ESM default; CommonJS also supported with destructuring. The function is named, not default exported.
SignedFetcherOptions
import { createSignedFetcher, SignedFetcherOptions } from 'aws-sigv4-fetch'
TypeScript type, import alongside the main function.
createSignedFetcher (browser)
import { createSignedFetcher } from 'aws-sigv4-fetch'
Works in browser when bundled with a module bundler (e.g., Webpack, Rollup). Credentials must be provided explicitly.

Creates a signed fetch client for AWS Lambda function URL and makes a POST request.

import { createSignedFetcher } from 'aws-sigv4-fetch'; const signedFetch = createSignedFetcher({ service: 'lambda', region: 'us-east-1', credentials: { accessKeyId: process.env.AWS_ACCESS_KEY_ID ?? '', secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY ?? '', }, }); async function main() { try { const response = await signedFetch('https://mylambda.lambda-url.us-east-1.on.aws/', { method: 'POST', body: JSON.stringify({ key: 'value' }), headers: { 'Content-Type': 'application/json' }, }); const data = await response.json(); console.log(data); } catch (error) { console.error('Request failed:', error); } } main();
Debug
Known issues
breakingv4.0.0 renamed the main export from `createSignedFetch` to `createSignedFetcher`.
fix
Replace `import { createSignedFetch } from 'aws-sigv4-fetch'` with `import { createSignedFetcher } from 'aws-sigv4-fetch'`.
affects: >=4.0.0
breakingv4.0.0 changed the options parameter; `region` default changed to `us-east-1` (was possibly undefined).
fix
If your service expects a different region, set `region` explicitly in options.
affects: >=4.0.0
gotchaIn Node.js 18+, native `fetch` is available but may not support all features. The library uses native `fetch` by default.
fix
If you need polyfilled fetch (e.g., for older Node or specific proxy support), pass a custom `fetch` implementation.
affects: >=4.0.0
gotchaCredentials are optional in Node.js but required in browser. Omitting credentials in browser will throw 'Credentials must be provided' error.
fix
Always provide explicit credentials when using in browser environments.
affects: >=4.0.0
deprecatedUsing `require` in ESM context is discouraged; the package supports ESM imports.
fix
Use `import` syntax instead of `require` for better tree-shaking.
affects: >=4.0.0
Errors
Common errors & fixes
Credentials must be provided when calling createSignedFetcher in a browser.
Browser environment lacks automatic credential resolution.
fix
Pass credentials explicitly: `createSignedFetcher({ service, credentials: { accessKeyId: '...', secretAccessKey: '...' } })`.
TypeError: (0 , aws_sigv4_fetch.createSignedFetcher) is not a function
Attempting to use require incorrectly (e.g., `const csf = require('aws-sigv4-fetch')`) without destructuring.
fix
Use `const { createSignedFetcher } = require('aws-sigv4-fetch');` or switch to ESM import.
Credential should be scoped to correct service: 'lambda'
The `service` parameter in options does not match the intended AWS service.
fix
Ensure `service` matches the AWS service you are calling (e.g., 'lambda' for Lambda, 'execute-api' for API Gateway).
The region 'us-east-1' is not a valid region for service 'iam'.
Some AWS services (like IAM) are global and do not require a region.
fix
Set `region: undefined` or omit region for global services, e.g., `createSignedFetcher({ service: 'iam' })`.
Upgrade
Version history
4.4.1latest on npm
Audit
Dependencies
@aws-sdk/credential-provider-nodeoptionalResolves AWS credentials from environment variables, SSO, EC2 metadata, etc. in Node.js.
@smithy/typesoptionalProvides TypeScript types for SignatureV4 signing.
@aws-sdk/credential-providersoptionalProvides credential providers for browser environments.
Agent activity
13 hits · last 30 days
node
10
OpenAI (training)
1
Resources
aws-sigv4-fetch — npm install aws-sigv4-fetch · libregistry