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):
- https://api.feedmyfurbabies.com/feed_all
- https://api.feedmyfurbabies.com/feed_left
- https://api.feedmyfurbabies.com/feed_right
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
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.
In the architecture diagram above, we have:
- An Amazon API Gateway: we are using the REST version of the API Gateway to serve API Endpoints under the domain https://api.feedmyfurbabies.com; more on this is described in this blog
- Depending on the Path in the API Endpoint URL that is made to the Amazon API Gateway, the request will be routed to a corresponding downstream Lambda Function depending on the Path. The Paths are:
- https://api.feedmyfurbabies.com/feed_all : when this API Endpoint URL is invoked M&Ms are dispensed in the left bowl, and coffee beans dispensed in the right bowl
- https://api.feedmyfurbabies.com/feed_left : when this API Endpoint URL is invoked M&Ms are dispensed in the left bowl
- https://api.feedmyfurbabies.com/feed_right : when this API Endpoint URL is invoked coffee beans dispensed in the right bowl
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