AWS Mini-Project - Cats Need Love Too
Tags: aws, cloud, dynamodb, lambda
Published: 2023-04-15 15:00:26

Completed my first AWS Mini Project today. The services used were DynamoDB, Lambda, and SNS. 

I first created a DynamoDB table where I manually entered in fictional data for a cat adoption agency. I entered in 8 kittens, their names and adoption statuses. In a real world example this would have been populated from a front-end website. In an ideal world all cats would have homes with all the cat nip and sunlight a kitten could dream of.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/23jmtmvkm1bo5zinz2lt.png)

After creating my table I explored the comparison of querying the data in the table versus running a scan of the existing records. Querying the data appears to be more efficient, eliminating the need for DynamoDB to iterate over every record, however I will use scanning later in the project. 

Next I set up an SNS email protocol. In simple terms AWS SNS is a messaging service that will allow me to send messages and notifications to any subscribed member in my cat loving community that is interested in adopting a cat. In this example they will be receiving updates when a cat is adopted encouraging them to hop onto the site if they want to adopt one before they are all gone.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oq6n4n769ftpx42qqb9w.png)

Now onto creating the Lambda function, which is named cat-adoption-function. In this portion I inserted code that will iterate through all the cat records that Dynamo DB passes to the Lambda function, and then publish the message for our subscribers to receive.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s1bdp7bytnhtmcto7ooo.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vbaxg39hzp3wyx8awmf5.png)

Next, I gave the Lambda function created permission to access DynamoDB so it can read the data from the DynamoDB Stream. Without this permission, the function created will not work. 

Next, I enabled the DynamoDB Stream that will trigger that  cat-adoption-function every time a cat's adoption status is  changed to true. 

The final step involved testing it out. In the DynamoDB console I ran a scan to ensure the code is working as expected and that the Lambda function is correctly reading and processing all of the table items. At the initial scan all of the adoption statuses were set to false. In a real world example this testing phase will be crucial to identify any data insertion, bug, and performance issues that could occur with larger datasets.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8akfxyznh0qxxn4fvzxw.png)

To test the trigger, I changed the adoption status of one of the cats to true in the DynamoDB table. Upon making the status change I received an email notifying me that the cat selected has been adopted! 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/03gs2eyghkcnmihz0sqh.png)

As best practice with all projects, my final step involved cleaning up, by deleting all the resources used in this project.

And voila! There goes my first project, looking forward to the next. Shout out to my favorite AWS course that is helping develop these skills and support my learning with these projects: [adrian cantrill](https://www.youtube.com/c/learncantrill)

Cover Photo by <a href="https://unsplash.com/@theluckyneko?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">The Lucky Neko</a> on <a href="https://unsplash.com/images/animals/kitten?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Unsplash</a>