Calling external REST Service from AWS Lambda? (Part 1)

tiny, simple, and without any overhead in Packaging.

Jörg Grote
Level Up Coding

--

It is quite simple, you just have to know-how. The following example comes without any additional Lambda packaged JavaScript Resources, and use just one 'index.js’.

No need for request.js or deep-dive into Node.js HTTP.

The trick is to just use the already available AWS SDK JavaScript Core!

AWS Lambda Functions, as a tiny self-containing boat in the Cloud

Content

what you will learn in this article

  • A Simple GET
  • GET with URL Parameter
  • Benefits in Package Size
  • used Sample REST Service
  • AWS SDK Documentation
  • TIBCO LABS
  • What’s next, … and Part 2

A Simple GET

Here is a custom AWS Service Descriptor Example

And here is how to call the external custom Service

Simple, or?

GET with URL Parameter

Here another Fragment Sample with an ID Parameter

Benefits in Package Size

Any Lambda Function to become very tiny, structured, and quickly deployable. But that’s not the only benefit, you can still use all the online Lambda Editor and Test Features, which becomes impossible when you deploy a huge JavaScript Package.

Size comparison of the same Implementation:

  • Package 1
    … using ‘request.js’ and ‘http-basic’, etc.
    Size: ~1,5 MB
  • Package 2
    … using AWS SDK Core Functionalities
    Size: ~9 KB

used Sample REST Service

The used RESTfull Service is graphically implemented by using TIBCO Cloud Integration (TCI) Flogo, connected to TIBCO Cloud LiveApps via standard Connectors to retrieve existing Case Instances and return them to AWS Lambda. Sign up for a 30-Day Free Trial of TIBCO Cloud Integration

custom Service Implementation in TIBCO Cloud Integration Flogo.

The Service can be a public one or managed by an API Gateway like TIBCO Mashery.

AWS SDK Documentation

The functionality here is not very well documented, but the Source is publically available, so you can always have a quick look at how Amazon is using their own functionality and learn from it.

here some nice GitHub Sample Links you can use as a quick reference …

  • aws-sdk-js/test/foo-service.fixture.js
  • aws-sdk-js/test/fixtures/protocol/input/rest-json.json
  • or even …
  • aws-sdk-js/lib/service.js
  • aws-sdk-js/lib/request.js
  • aws-sdk-js/lib/model/shape.js
  • aws-sdk-js/lib/protocol/rest_json.js

used just some paths here, as Versions get maybe updated.

TIBCO LABS

this article was written under the TIBCO LABS initiative, full reusable source can be found under the public TIBCO LABS GitHub Repository
incl. BSD 3-Clause License.

What's next

Check out the follow-up article Part 2 here!

Thanks for reading and claps!

--

--

Solution / Application Architect @ MHP – A Porsche Company, within the Area of: Data Architecture, Analytics & AI - Enabling you to shape a better tomorrow.