Quantcast
Channel: Chiwai Chan's Blog
Viewing all articles
Browse latest Browse all 18

FeedMyFurBabies – Trigger the Cat Feeder using AWS API Gateway Endpoints

$
0
0

Some time ago I was on the AWS Twitch stream to talk about my AWS IoT Cat Feeder with Chris and Casey (link to the talk on the AWS Twitch on my AWS IoT Cat Feeder); and I wanted to have a fun and interactive way for the viewers of the stream to get involved - and that is where the idea of feeding Chris anywhere was born.

So the idea was to have Chris at the beach eating Temptations each time a new feed is triggered for the Cat Feeder, and each feed would be triggered by the AWS Twitch stream viewers using various API Endpoints (these endpoints may be down from time to time - more on this in a later blog):

Seeed AWS IoT Button

Problems

  • I left it til a few days before the Twitch stream to create the API Endpoints - I got lazy and created the Endpoints manually using the AWS Console

  • How do we power the Cat Feeder at the beach?

  • How does the Cat Feeder talk to AWS IoT Core?

  • Can I get Chris to eat some Temptations?

    Lets get the easy problems out of the way

  • Park your car up next to the beach

  • Plug an Inverter into the car's power socket -

  • Plug the IoT Cat Feeder's power adapter into the Inverter

  • Set up tethering on your phone so the IoT Cat Feeder can talk to AWS IoT to receive MQTT Messages after subscribing to an IoT Topic

  • Chris was not keen the Temptations - he replaced the cat food with coffee beans one side of the feeder, and M&Ms in the other

    IoT Power Internet

    AWS API Gateway with 3 different API Endpoints

For this piece of architecture I want it implemented using the AWS CDK, in particular with the CDK code written in Python.

API Gateway Architecture

In the architecture diagram above, we have:

As shown in the diagram (within the green box) are 3 distinct AWS Lambda Functions; even though there are 3 of them, each of the share the same Python code - when you review the CDK Python code in my GitHub repository (link included below), although you will see the code creates 3 Lambda Functions, all these Lambdas are using the same Python code (lambdas/api-handler/cat_feeder_handler.py).

Outside of the green box in the architecture diagram, we see an Amazon EventBridge Bus named “feedmyfurbabies”; when either one of the Lambda Functions is invoked via the API Gateway, the Lambda Function will in turn send an EventBridge Event to the EventBridge Bus. Have a read of my blog where the Amazon EventBridge Bus and its purpose is explained in greater detail: https://chiwaichan.co.nz/2023/03/18/feedmyfurbabies-event-sourcing-using-amazon-eventbridge/

Try this out for yourself by downloading the CDK code from my GitHub repository: https://github.com/chiwaichan/feedmyfurbabies-cdk-apis


Viewing all articles
Browse latest Browse all 18

Trending Articles