Skip to content

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.

License

Notifications You must be signed in to change notification settings

pfernandom/aws-api-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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, either:

  1. Add the following rule to webpack.config:
	{
		test: /apigClient.js$/,
		loader: 'imports-loader?aac=aws-api-client&uritemplate=>aac.uritemplate&apiGateway=>aac.apiGateway!exports-loader?apigClientFactory'
	}

Using this method ensures that you can replace the apigClient.js file with new versions without further requiring changes.

  1. OR 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'

and export the factory by adding the following line of code at the end of the file

export default apigClientFactory

APIGatewayClient

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

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

to this:

var apiGatewayClient = new APIGatewayClient(simpleHttpClientConfig, sigV4ClientConfig);

Utils

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

Example:

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

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

uritemplate

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

About

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.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •