A serverless guestbook using AWS Lambda.
- Sign up for AWS Lambda
- Install and configure the
aws
command-line client - Run
script/bootstrap
Sign up for AWS here.
The Lambda free tier includes 1M free requests per month and 400,000 GB-seconds of compute time per month.
To install the aws
command-line client use pip
:
pip install awscli --upgrade --user
To configure aws
, follow these quick configuration steps.
Once configured, you should see config
and credentials
files in ~/.aws
.
script/bootstrap
script/pack_lambda .
script/push_lambda guestbook_add package.zip
script/push_lambda guestbook_list package.zip
script/push_lambda message_add package.zip
script/push_lambda messages_received_list package.zip
script/push_lambda messages_sent_list package.zip
This will:
- Ensure the Lambda function role is created, with the correct policy attached
- Create the DynamoDB table
- Package the Lambda function and all its dependencies
- Create the Lambda functions,
guestbook_add
,guestbook_list
,message_add
,messages_received_list
, andmessages_sent_list
on AWS
Use the script/exec_lambda
script.
E.g. to create an entry in the guestbook:
# Create an entry in the guestbook
script/exec_lambda guestbook_add '{"name":"Florian", "message":"I program my home computer, beam myself into the future"}'
And to list today's guestbook entries:
# List today's guestbook entries
script/exec_lambda guestbook_list
To send a message:
script/exec_lambda message_add '{"toId": 2993937, "to": "imjohnbo", "fromId": 27806, "from": "swinton", "message": "Hello, John, how are you?"}'
To list the 50 most recently received messages:
script/exec_lambda messages_received_list '{"toId": 2993937}'
To list the 50 most recently sent messages:
script/exec_lambda messages_sent_list '{"fromId": 27806}'