Last active
April 2, 2020 06:55
-
-
Save pahud/d85ba0c0002c5a24d74510efb735c80b to your computer and use it in GitHub Desktop.
sending signed request to API Gateway of custom domain name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var AWS = require('aws-sdk'); | |
| var rp = require('request-promise') | |
| var aws4 = require('aws4') | |
| AWS.CredentialProviderChain.defaultProviders = [ | |
| function () { return new AWS.EnvironmentCredentials('AWS'); }, | |
| function () { return new AWS.EnvironmentCredentials('AMAZON'); }, | |
| function () { return new AWS.SharedIniFileCredentials({profile: 'my_profile_name'}); }, | |
| function () { return new AWS.EC2MetadataCredentials(); } | |
| ] | |
| var chain = new AWS.CredentialProviderChain(); | |
| chain.resolve((err, cred)=>{ | |
| AWS.config.credentials = cred; | |
| }); | |
| AWS.config.update({region: 'us-west-2' }); | |
| var opts = { | |
| host: '<my_custom_api_gateway_domain_name>', | |
| path: '/required-auth', | |
| uri: 'https://<my_custom_api_gateway_domain_name>/required-auth', | |
| json: true, | |
| headers: {} | |
| } | |
| opts.region = 'us-west-2' | |
| opts.service = 'execute-api' | |
| var signer = new aws4.RequestSigner(opts, cred) | |
| signer.sign() | |
| //console.log(opts) | |
| rp(opts) | |
| .then( (html)=> console.log( html ) ) | |
| .catch( (e)=> console.log('failed:'+e)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hey i dont know code but need this added to my javascript can anyone help me im willing to pay contact me [email protected]