@acusti/aws-signature-v4
v1.0.0
Published
A lightweight isomorphic module to generate request headers that fulfill the AWS SigV4 signing process
Downloads
1,012
Maintainers
Readme
@acusti/aws-signature-v4
aws-signature-v4
is a lightweight isomorphic module that generates
request headers to fulfill the AWS SigV4 signing process.
Usage
npm install @acusti/aws-signature-v4
# or
yarn add @acusti/aws-signature-v4
The primary export is getHeadersWithAuthorization
, an async function that
takes three arguments: a resource
(i.e. request URL), a fetch init object
(i.e. request options), and an AWS options object where you can pass
credentials, the region, and the service name (see the type
definition). If the AWS region isn’t passed and can be derived from the
resource URL, it will be. The function’s return promise is resolved with a
plain JS object of the request’s headers with all required authorization
headers merged in over top of any existing headers passed to the function.
import { getHeadersWithAuthorization } from '@acusti/aws-signature-v4';
const resource = 'https://_.appsync-api.us-west-2.amazonaws.com/graphql';
const body = `{"query": "query { listItems { items { id } } }"}`;
const headers = await getHeadersWithAuthorization(
resource,
{ body, headers: { method: 'POST' } },
{
accessKeyId: '…',
region: 'us-west-2',
secretAccessKey: '…',
service: 'appsync',
sessionToken: '…',
},
);
const response = await fetch(resource, { body, headers });