Amazon API Gateway to AWS Lambda to AWS IoT

API Gateway REST API → AWS Lambda → IoT Core

Create an API Gateway REST API to invoke a Lambda function to publish to IoT Core.

This pattern creates an Amazon API Gateway REST API endpoint, that invokes a Lambda function.
The Lambda function has been given permissions to publish to AWS IoT Core (`iot:Publish`). Make a POST call to the API Endpoint with `topic` and `message` in the body.
This pattern deploys an API Gateway resource and one Lambda function.

< Back to all patterns

GitHub icon Download this pattern (.zip)

GitHub icon View this pattern on GitHub


Clone repo

git clone https://github.com/aws-samples/serverless-patterns/cd serverless-patterns/apigw-lambda-iot-cdk

Deploy

cdk deploy


Testing

See the GitHub repo for detailed testing instructions.

Cleanup

1. Delete the stack: cdk destroy.
2. Confirm the stack has been deleted: aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'STACK_NAME')].StackStatus".
3. You see a message confirming DELETE_COMPLETE.

Additional resources

Created by:

Ashu Joshi

Ashu Joshi

I am a Principal Architect, AWS Cloud Architect, Full-Stack Developer, Edge AI/ML/IoT Engineer, and Serverless Enthusiast.

Follow on LinkedIn