Using a REST API with Amazon Web Services, Part 2
In our previous blog post, we started our project by setting up a Lambda function in Amazon Web Services (AWS). We didn’t dive very deep, we barely even described much about those Lambda functions.
Our single Lambda returns all contacts in a table associated with a particular groupid. Now we are going to write three new methods: one to return a particular contact, one to create a contact, and one to update a contact.
Returning a particular contact looks a lot like returning many contacts. Actually, the code delta between those two actions is extremely small. The biggest difference is now we use the “get” method instead of the “scan” method.
To create an item, we will need to use the AWS “put” method. To do that, we will add an item to the DynamoDB table.
To update an item, we will need to use the AWS DynamoDB “update” method. If you’re an old SQL person, this will feel pretty familiar. You first must write a “where” clause for which item to update (the key). Then you must write a line of text describing what properties you want to copy across.
The three methods in this blog post are pretty similar to the Lambda in the previous blog post, but we now support reading, creating, and updating a single item.
In our next blog post, we will set up an API Gateway so we can call these methods from outside of AWS.
If you have any questions or comments, hit me up on Twitter.