Skip to content

Instantly share code, notes, and snippets.

@pahud
Last active April 2, 2020 06:55
Show Gist options
  • Select an option

  • Save pahud/d85ba0c0002c5a24d74510efb735c80b to your computer and use it in GitHub Desktop.

Select an option

Save pahud/d85ba0c0002c5a24d74510efb735c80b to your computer and use it in GitHub Desktop.
sending signed request to API Gateway of custom domain name
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))
@itrustgod
Copy link

hey i dont know code but need this added to my javascript can anyone help me im willing to pay contact me [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment