Spotlight
AWS Lambda Functions: Return Response and Continue Executing
A how-to guide using the Node.js Lambda runtime.
At Trek10 we love the “pre:Invent” season… these days, AWS tends to push out lots of announcements the week before re:Invent so they can focus the keynotes on a few really big new services and categories. As users who really appreciate the depth of AWS services, we love seeing these announcements: our favorite services becoming even better, and newer services finally getting their shine and polish.
This year one of the trends we’re seeing is more and more AWS features that enable the idea of “functionless” architectures.
This isn’t a new idea. Many of our friends have been talking about this recently, like this great piece by Chase Douglas at Stackery, Jeremy Daly in his interesting Serverless Chats podcast with Sheen Brisals from LEGO, and Trek10’s very own Forrest Brazeal and Jared Short in the “Future of FaaS” episode of our Think Faas Podcast. The basic idea is that the less custom code you own and manage, the better. If you can have cloud-native components handling more functionality natively, you get systems that are easier to maintain and more resilient, and you can build faster and focus on your unique business logic. Configuring a cloud service with YAML is going to typically be far less complex and easier to understand than whatever you’ve written in your language of choice.
Ultimately functionless is going to be driven by cloud service capabilities. It’s a great idea but it can’t become a reality unless the functionality is there. That’s why it’s really exciting to see the really rapid progress AWS is making in these pre:Invent announcements.
IOT Core, among many other things, routes your data to other services via “IOT Actions”, driven by “IOT Rules”. Of course one action is triggering a Lambda function so you can process the IOT data with your own code, but there are already many other Actions that are direct integrations to other AWS services which let us build functionless architectures (that is, no Lambda needed): for example writing directly from IOT Core to DynamoDB or IOT Analytics or Kinesis Firehose.
Now another option is HTTP Targets. This opens up a whole new world of functionless use cases… if you have data that needs to go from an IOT device to some arbitrary REST API, you can do that without any Lambda function. This could be your legacy app on premise, or a third party. (Note that HTTP Targets requires validating you own the endpoint, so figuring out how that will work with third party APIs will take some studying.) One of our favorite third party providers is Datadog, so we plan on trying to build a direct, functionless integration between IOT Core and Datadog. If you’re interested in trying out the new IOT Action for HTTP Targets, check out this new tutorial.
This is an exciting new architectural component for serverless systems, and another example of how AWS is reducing the amount of code we have to write. As AWS puts it, With Destinations, you can route asynchronous function results as an execution record to a destination resource without writing additional code. Previously if you had asynchronous work to handle as part of a bigger process, you need to either synchronously wait for a response or write additional code to handle coordinating function execution, retries, and failure handling with dead letter queues. Lambda Destinations simplifies all this down to a simple config setting.
This can also be used as a zero code producer for SQS, SNS, or EventBridge. Instead of writing code that puts your events on these AWS services, you can just set the Destination and voila, your events appear there when the function is completed.
This is another great example of AWS building a direct integration between two commonly-used services, eliminating the need for Lambda function code.
In this case, the services are Greengrass, Kinesis, and IOT Analytics. Greengrass brings AWS service capabilities to the edge via a gateway device. A typical use case is IOT devices using a local communication protocol to stream data to a gateway, which can filter and aggregate it and push it to Kinesis or IOT Analytics in AWS where it can be further processed and consumed. This results in lower power consumption and bandwidth costs for IOT devices.
Previously, you had to write your own code in a Lambda function (deployed locally on Greengrass) to aggregate and send data to IOT Analytics or Kinesis. Stream Manager handles that for you now including priority management, bandwidth utilization, aggregation, and timeouts and intermittent connectivity. These advanced features are where the value of “functionless” really becomes apparent. It’s one thing to save a few lines of code that push a message into Kinesis, but it’s quite another when you consider all of the developer time that could go into coding this robustness on your own.
At Trek10, we’re looking forward to building faster for our customers with less code, and excited to see what other “functionless” capabilities AWS releases as re:Invent gets underway.
A how-to guide using the Node.js Lambda runtime.