fetch-aws4
Version:
Fetch wrap to add AWS v4 signature to the request
45 lines (36 loc) • 1.07 kB
Markdown
with AWS V4 signature headers
```js
import fetch from 'fetch-aws4';
// Getting credentials from environment var: AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
const response = await fetch('https://httpbin.org/html');
console.log(await response.text());
// Passing credentials as options
const response = await fetch('https://httpbin.org/html', {
credentials: {
accessKeyId: 'key',
secretAccessKey: 'secret',
sessionToken: 'optional token',
}
});
console.log(await response.text());
```
```js
const jsonResponse = await fetch('https://httpbin.org/json');
console.log(await jsonResponse.json());
```
```js
const postResponse = await fetch('https://httpbin.org/post', {
method: 'POST',
});
console.log(await postResponse.json());
```
```js
import { wrapper } from 'fetch-aws4';
const nodeFetchResponse = await wrapper(fetch)('https://httpbin.org/get');
console.log(await nodeFetchResponse.json());
```
Wapper around native `fetch` to sign the request