Skip to content

Commit

Permalink
Add got4aws to AWS section
Browse files Browse the repository at this point in the history
  • Loading branch information
SamVerschueren committed Jul 26, 2020
1 parent a3e171c commit 9693ab5
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -699,8 +699,6 @@ Default: `[]`

Called with [normalized](source/core/index.ts) [request options](#options). Got will make no further changes to the request before it is sent. This is especially useful in conjunction with [`got.extend()`](#instances) when you want to create an API client that, for example, uses HMAC-signing.

See the [AWS section](#aws) for an example.

**Tip:** You can override the `request` function by returning a [`ClientRequest`-like](https://nodejs.org/api/http.html#http_class_http_clientrequest) instance or a [`IncomingMessage`-like](https://nodejs.org/api/http.html#http_class_http_incomingmessage) instance. This is very useful when creating a custom cache mechanism.

###### hooks.beforeRedirect
Expand Down Expand Up @@ -1860,29 +1858,14 @@ got('unix:/var/run/docker.sock:/containers/json');

## AWS

Requests to AWS services need to have their headers signed. This can be accomplished by using the [`aws4`](https://www.npmjs.com/package/aws4) package. This is an example for querying an ["API Gateway"](https://docs.aws.amazon.com/apigateway/api-reference/signing-requests/) with a signed request.
Requests to AWS services need to have their headers signed. This can be accomplished by using the [`got4aws`](https://www.npmjs.com/package/got4aws) package. This is an example for querying an ["API Gateway"](https://docs.aws.amazon.com/apigateway/api-reference/signing-requests/) with a signed request.

```js
const got = require('got');
const AWS = require('aws-sdk');
const aws4 = require('aws4');
const chain = new AWS.CredentialProviderChain();
const got4aws = require('got4aws');;
// Create a Got instance to use relative paths and signed requests
const awsClient = got.extend({
prefixUrl: 'https://<api-id>.execute-api.<api-region>.amazonaws.com/<stage>/',
hooks: {
beforeRequest: [
async options => {
const credentials = await chain.resolvePromise();
aws4.sign(options, credentials);
}
]
}
});
const awsClient = got4aws();
const response = await awsClient('endpoint/path', {
const response = await awsClient('https://<api-id>.execute-api.<api-region>.amazonaws.com/<stage>/endpoint/path', {
// Request-specific options
});
```
Expand Down

0 comments on commit 9693ab5

Please sign in to comment.