@acusti/aws-signature-v4
TypeScript icon, indicating that this package has built-in type declarations

0.6.2 • Public • Published

@acusti/aws-signature-v4

latest version maintenance status downloads per month install size

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 });

Package Sidebar

Install

npm i @acusti/aws-signature-v4

Weekly Downloads

4

Version

0.6.2

License

Unlicense

Unpacked Size

48.5 kB

Total Files

17

Last publish

Collaborators

  • acusti