Code for a talk on Lambda & API Gateway at the Dec 2, 2015 AWS Chicago Meetup
- Create a table named
cats
with a string hash keyname
- Accept all other defaults and create the table
- Create a new function using the
simple-mobile-backend
template - Create the suggested
Basic with DynamoDB
role if it doesn't already exist - Name it
cats
Note that this lambda function multiplexes operations based on the body. It doesn't have to work that way.
Create a cat:
{
"operation": "create",
"TableName": "cats",
"Item": {
"name": "henry",
"status": "hungry"
}
}
Get a cat:
{
"operation": "read",
"TableName": "cats",
"Key": {
"name": "henry"
}
}
List all cats:
{
"operation": "read",
"TableName": "cats",
"Key": {
"name": "henry"
}
}
Update a cat:
{
"operation": "create",
"TableName": "cats",
"Item": {
"name": "henry",
"status": "sleepy"
}
}
- Name it
MeetupCats
- Create a new
/cats
resource - Create a new
/{name}
resource under/cats
- Create the following methods with the corresponding mapping templates:
{
"operation": "create",
"TableName": "cats",
"Item": $input.json('$')
}
{
"operation": "list",
"TableName": "cats"
}
{
"operation": "read",
"TableName": "cats",
"Key": {
"name": "$input.params('name')"
}
}
{
"operation": "create",
"TableName": "cats",
"Item": {
"name": "$input.params('name')",
"status": "$input.path('$.status')"
}
}