AWS events generator

Anton Klimenko
Cloud recipes
Published in
2 min readJan 20, 2021

--

AWS Lambda is a serverless compute service. It can be automatically triggered by various AWS services such as Kinesis, SQS, S3, EventBridge. Also, it can be invoked manually via CLI or HTTP API.

When called manually, the lambda handler receives input in a format defined by the developer. Thus, it’s easy to create sample payload for testing (since the developer familiar with the data structure).

When lambda invoked in response to AWS service event, then the handler receives input according to the caller service. In this case, user-defined data embedded in the event structure.

User data embed to SQS event payload.

Until recent time, I had to manually create an AWS service event samples to test lambda handlers. This approach was time-consuming — need to study pages of documentation and error-prone. Therefore I was happy to find that AWS SAM can also generate service events samples.

AWS Serverless Application Model (SAM)

I knew that SAM is a tool to create, run, and deploy serverless applications. The feature I didn’t know about was the ability to generate AWS services events samples. To create services payloads you need SAM CLI installed on your machine. Once installed, run the following command to create event samples:

$ sam local generate-event [SERVICE] [EVENT] [FLAGS] 

For example, to generate sample events for S3 put event run:

$ sam local generate-event s3 put

The list of supported services is available via the following command:

$ sam local generate-event --help 

Thank you for reading. Please share what other events samples generator tools you know.

References

--

--