AWS Lambda - Hidden Treasures (I)
Manish Jain
Fin-Educator | Global Markets | 3 X CTO | Cloud & Data Science | AWS X 2 (Certified Security Specialist, Certified Solution Architect) | HCD + CX
More you dive deeper into AWS Lambda, more you get awed at the fantastic work done by the dev team behind Lambda. For frugal architects who want to scale-out horizontally on-demand, AWS Lambda is a delight.
This post is about providing customer parameters at the invoker level (not config). Every Lambda can be triggered by multiple types of events and multiple events including Cloudwatch Events which we used as a scheduler. Cloudwatch Events can in-turn trigger multiple targets (up to 5) and the supported variety of target types is awesome!
We have used Lambda + Cloudwatch Events + Microsoft Teams to design a small SRE concept where Cloudwatch event fires an event every 30 mins that trigger's a Lambda which talks to an API to get some details, formats the data and then posts them to a Teams channel.
There was a need to compare the day end snapshot with the previous day. We decided to create another Channel but wanted to reuse the Lambda code. Following served our purpose beautifully:
Cloudwatch Events >> Edit Rule >> Targets >> Configure Input >> Constant (JSON Text)
So we configured two Events/Rules and passed a JSON object with different values {invocationtype:perodic} and {invocationtype:dayend}
Inside the Lambda Function Handler, Stream was good enough to tell the Lambda which event invoked the Lambda to decide which channel to post to.
public string FunctionHandler(Stream input, ILambdaContext context)
{
The concepts in this post are very simple once you know them, but when they work together, they add tremendous value and at a very reasonable price point.
#aws #lambda #cloudwatchevents #msteams