Amazon Lambda – Part 1 – The Basic Call

This blog entry is going to be the first in a series of five or six and they will be on my experience with Amazon Lambda.  I was turned on to Amazon Lambda’s by a colleague who was thinking about using them to replace legacy .Net Services.

On the surface, the implementation seems a little sparse.  The initial languages supported are Python and two flavors of Node.js (4.3 and .100).  For a cloud system as robust as Amazon, I was expecting Java, C# and a bunch of other languages to be supported.  Azure’s new Function service supports more according to the documentation.  After Amazon Lambda and time permitting, I will explore Azure Function.

Even though there are only two languages supported, the implications have both pros and cons from what I can see.  On the positive side, the ‘scaffolding’ that is normally needed to host your own services is not needed.  You put in the part of the code you need and in theory they handle the rest.  This is the big promise of the cloud.  Slowly increasing abstractions that allow you to concentrate on the portions of your system that you care about.  That said, if you go with an Amazon Lambda or Azure Function, you are (in my opinion) crossing a boundary.  That boundary is you are further cementing yourself in with a specific platform.  That is not necessarily a good or bad thing…it is just a thing to consider when designing the application at the very beginning 🙂

For this effort, I did a very basic call to the Amazon Dynamo ‘SatelliteUpdates’ Database that I loaded a few blog entries ago.  90% of the code came from the Amazon code guide (see References #1 & #2).  The method and return value is below.  For the next entry, I will call the method from a console application.

Stay tuned!

Query Node.js Amazon Lambda Code

‘use strict’;

console.log(‘Loading function’);

exports.handler = (SatelliteUpdateId, context, callback) =>
console.log(‘Starting Lambda Method call!’);

console.log(‘SatelliteUpdateId =’, SatelliteUpdateId.SatelliteUpdateId);

console.log(‘Obtaining SDK…’);
var AWS = require(“aws-sdk”);
console.log(‘SDK obtained!’);

console.log(‘Creating client…’);
var docClient = new AWS.DynamoDB.DocumentClient();
console.log(‘Client created!’);

console.log(‘Setting up params…’);
var params = {
TableName: “SatelliteUpdates”,
KeyConditionExpression: “SatelliteId = :satelliteUpdateId”,
ExpressionAttributeValues: {
“:satelliteUpdateId”: Number(SatelliteUpdateId.SatelliteUpdateId)
console.log(‘Params setup!’);

console.log(‘Running query…’);
docClient.query(params, function(err, data)
if (err)
console.log(JSON.stringify(err, null, 2));
console.log(JSON.stringify(data, null, 2));

console.log(‘Lambda Method call complete!’);

Method Output
START RequestId: 00555d92-279a-11e6-8262-039f9228452a Version: $LATEST
2016-06-01T01:41:47.783Z    00555d92-279a-11e6-8262-039f9228452a    Starting Lambda Method call!
2016-06-01T01:41:47.783Z    00555d92-279a-11e6-8262-039f9228452a    SatelliteUpdateId = 5828
2016-06-01T01:41:47.784Z    00555d92-279a-11e6-8262-039f9228452a    Obtaining SDK…
2016-06-01T01:41:50.242Z    00555d92-279a-11e6-8262-039f9228452a    SDK obtained!
2016-06-01T01:41:50.242Z    00555d92-279a-11e6-8262-039f9228452a    Creating client…
2016-06-01T01:41:50.424Z    00555d92-279a-11e6-8262-039f9228452a    Client created!
2016-06-01T01:41:50.424Z    00555d92-279a-11e6-8262-039f9228452a    Setting up params…
2016-06-01T01:41:50.425Z    00555d92-279a-11e6-8262-039f9228452a    Params setup!
2016-06-01T01:41:50.425Z    00555d92-279a-11e6-8262-039f9228452a    Running query…
2016-06-01T01:41:51.064Z    00555d92-279a-11e6-8262-039f9228452a    Lambda Method call complete!
2016-06-01T01:41:51.384Z    00555d92-279a-11e6-8262-039f9228452a    {
“Items”: [
“SatelliteId”: 5828,
“Type”: “East_ClientUpdate_20160917020910597PM”,
“Id”: 5828,
“Created”: “2016-02-17T20:09:10.597Z”,
“SatelliteRange”: “Thread1_Db-5828_East_ClientUpdate_20160917020910597PM”,
“Data”: “{\”Id\”:5828,\”Type\”:\”East_ClientUpdate_20160917020910597PM\”,\”Data\”:\”{\\\”SatelliteName\\\”:\\\”East\\\”,\\\”Onstation\\\”:false,\\\”SolarPanelsDeployed\\\”:false,\\\”PlanetShift\\\”:true,\\\”DestinationX\\\”:625,\\\”DestinationY\\\”:680}\”,\”Created\”:\”2016-02-17T14:09:10.597\”}”
“Count”: 1,
“ScannedCount”: 1
END RequestId: 00555d92-279a-11e6-8262-039f9228452a
REPORT RequestId: 00555d92-279a-11e6-8262-039f9228452a    Duration: 3676.58 ms    Billed Duration: 3700 ms     Memory Size: 128 MB    Max Memory Used: 48 MB



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s