/aws-api-client

A JavaScript module to consume AWS API Gateway endpoints using AWS SDK. This is the same code generated by AWS, but packaged to be used as ES6 modules compatible with bundlers like Webpack.

Primary LanguageJavaScriptApache License 2.0Apache-2.0

aws-api-client

A JavaScript module to consume AWS API Gateway endpoints using AWS SDK. This is the same code generated by AWS, but packaged to be used as ES6 modules compatible with bundlers like Webpack.

Install

npm install --save aws-api-client

Background

When we generate AWS API Gateway SDKs for JavaScript, they are built expecting you to import all the JavaScript files inside the lib folder, declaring everything as global variables. This might be useful for simple applications, but for others using bundlers like Webpack, you need to be able to import modules instead. This NPM module allows you to get rid of that lib folder by importing those JS functions instead.

Use

You can download a JavaScript SDK for your code like mentioned here: http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-generate-sdk.html

Then, do the following replacements in the apigClient.js file generated by AWS:

Include the module

Import the module with the following line of code

import {APIGatewayClient, Utils, uritemplate} from 'aws-api-client'

APIGatewayClient

Replace instances of apiGateway.core.apiGatewayClientFactory.newClient from this:

var apiGatewayClient = apiGateway.core.apiGatewayClientFactory.newClient(simpleHttpClientConfig, sigV4ClientConfig);

to this:

var apiGatewayClient = new APIGatewayClient(this.simpleHttpClientConfig, this.sigV4ClientConfig);

Utils

Replace instances of apiGateway.core.utils for this.utils = new Utils():

Example:

apiGateway.core.utils.assertParametersDefined(params, [], ['body']);

this.utils = new Utils(); utils.assertParametersDefined(params, [], ['body']);

uritemplate

The variable uritemplate is exported as a function, so you shouldn't need to change anything.