Thursday 1 June 2017

Using AWS API Gateway SDK in Node.JS causes issues

So I am trying to follow the AWS API Gateway SDK tutorial on setting up a secure connection between the NodeJS App and API Gateway link here.

My test function looks like something like below:

  require('./lib/apigClient');
  require('./lib/axios/dist/axios.standalone');
  require('./lib/CryptoJS/rollups/hmac-sha256');
  require('./lib/CryptoJS/rollups/sha256');
  require('./lib/CryptoJS/components/hmac');
  require('./lib/CryptoJS/components/enc-base64');
  require('./lib/url-template/url-template');
  require('./lib/apiGatewayCore/sigV4Client');
  require('./lib/apiGatewayCore/apiGatewayClient');
  require('./lib/apiGatewayCore/simpleHttpClient');
  require('./lib/apiGatewayCore/utils');

var body = {
  "type": "the_best_kind",
  "status": "processed",
  "name": "test123"
};

export function getRatingsTest(req, res) {

  var apigClient = apigClientFactory.newClient({
    accessKey: 'ACCESS_KEY',
    secretKey: 'SECRET_KEY',
    sessionToken:'SESSION_TOKEn', //OPTIONAL: If you are using temporary credentials you must include the session token
    region: 'eu-west-1' // OPTIONAL: The region where the API is deployed, by default this parameter is set to us-east-1
});
  console.log('NEW CLIENT =====', apigClient)

  apigClient.calcRatingPost(null, body, null)
    .then(function(result){
        //This is where you would put a success callback
    }).catch( function(result){
        //This is where you would put an error callback
    });
  return res.json({test: 123})
}

I keep getting error such a apiGateway is not defined, CryptoJs is not defined and so on. All the 11 javascript files are not modular which is unfortunate.

What is the best approach for getting this to work in NodeJS?

I also tried the aws-api-gateway-client npm package but no luck yet.



via Andriy Kulak

No comments:

Post a Comment