Photo by Christopher Robin Ebbinghaus on Unsplash

Member-only story

Developing on AWS Lambda (Part 1): NodeJS and the AWS SDK

George Mao

--

Developers who are new to Lambda, NodeJS, and the AWS SDK tend to run into issues with the async nature of NodeJS. This post will provide a quick intro to async development on Lambda.

The first thing to remember is that all calls using the AWS SDK for NodeJS are asynchronous. This means requests are placed on the call stack and when the call is completed the response will either invoke a callback (that you provide) or you must handle a promise.

Lets take a look at a few examples. Open the official AWS API documentation for the Node SDK and pick any service you are interested in. Lets try S3 or DynamoDB. Open the S3 or DynamoDB docs and scroll to the ‘Method Summary’ section. Notice every single Method has a parent class of ‘AWS.Request’. Click the ‘Request’ link to see how this class is defined and you’ll see the first statement:

All requests made through the SDK are asynchronous and use a callback interface

Now lets say you want to call one of the operations such as ‘listBuckets’. The definition says:

listBuckets(params = {}, callback)

The first parameter is input you provide to the listBuckets call. This will include details that pertain to the operation being invoked. The second parameter is a function that the Node…

--

--

Responses (1)