October 17, 2018
We will build a simple serverless (AWS Lambda) web application that enables users to request unicorn rides from the Wild Rydes fleet. The application will present users with an HTML based user interface for indicating the location where they would like to be picked up and will interface on the backend with a RESTful web service to submit the request and dispatch a nearby unicorn. The application will also provide facilities for users to register with the service and log in before requesting rides.
AWS Tutorial: Build a Serverless Web Application
Amazon S3 hosts static web resources including HTML, CSS, JavaScript, and image files which are loaded in the user’s browser.
Make bucket content public by setting up policy
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::wildrydes-warren/*"
}
]
}
Amazon Cognito provides user management and authentication functions to secure the backend API.
Modify /js/config.js by filling in Pool Id, App client id, and region
window._config = {
cognito: {
userPoolId: 'us-east-1_65cLrZQkK', // e.g. us-east-2_uXboG5pAb
userPoolClientId: '3m1t3bi2d9p62qa79pj930r65p', // e.g. 25ddkmj4v6hfsfvruhpfi7n4hv
region: 'us-east-1' // e.g. us-east-2
},
api: {
invokeUrl: '' // e.g. https://rc7nyt4tql.execute-api.us-west-2.amazonaws.com/prod',
}
};
Visit register.html to create an account, either with a real mailbox or a dummy one
Visit verify.html, fill in the verification code or confirm user in Cognito console (General settings/Users and groups) manually
Visit ride.html, log in with email and password, you should see
Amazon DynamoDB provides a persistence layer where data can be stored by the API’s Lambda function.
Create DynamoDB table with name Rides, and RideId for partition key
Create an IAM role for Your Lambda function, name it WildRydesLambda
Every Lambda function has an IAM role associated with it. This role defines what other AWS services the function is allowed to interact with.
Grant IAM role WildRydesLambda to write DynamoDB
Create a Lambda Function for Handling Requests, name it RequestUnicorn
Choose an existing role for function RequestUnicorn as WildRydesLambda, so that the function is able to write DynamoDB
In this module you’ll use Amazon API Gateway to expose the Lambda function RequestUnicorn as a RESTful API. This API will be accessible on the public Internet. It will be secured using the Amazon Cognito user pool you created in the previous module.
Written by Warren who studies distributed systems at George Washington University. You might wanna follow him on Github