Hey guys, I put together a really comprehensive tutorial detailing how to build a CRUD Serverless API and hooking it up to a React SPA entirely on AWS. The API functions are in ES6 and authenticated with Cognito User Pool. It also shows you how to host your app on S3 and serve it out using CloudFront and Route 53. It is an end-to-end tutorial that shows the Serverless architecture in action. Initially, I was putting it together for myself but then I had a few other folks ask for it as well.
So take a look and let me know if I missed something that I shouldāve covered - http://serverless-stack.com
Now that the core tutorial is completed, a couple advanced items that would be useful to add:
federated authentication with Cognito (eg, Facebook, Google)
using RDS (eg, MySQL) and Sequelize as the database (and ORM) as an alternative to DynamoDB. Granted DynamoDB is most appropriate for this simple demo, but RDS/Aurora is also used by many enterprise applications.
Got it until the Add a Create Note API part. Tried to invoke, serverless webpack invoke --function create --path event.json but I get 500 error. I reviewed from the start and even used the cloned repository and just updated the details with my own but I canāt still get it working. Is there anywhere we could ask to get this all working?
Dorell, the 500 error most likely results from the DynamoDB call. If you open up dynamodb-lib.js and print out the error object inside the if block.
if (error) {
console.log(error); // Add this line
reject(error);
return;
}
Run the invoke command again and letās see what error it prints out. Btw, you can always talk to us through the live chat right on the tutorial page.
Frank - Thank you so much man. Iāve identified the error. In the Create a DynamoDB table, the fields userid and noteid are both lowercase, however, the code constructing the data to be inserted uses camelCase such as noteId and userId.
Really amazing tutorial! Very clean and good writing. I ran into a few issues that were all my own doing. I think it would be great if there was a way to capture troubleshooting tips from people as they walk through it. On one of the e-learning sites (udacity, i think), they has a discussion thread for each topic or chapter so the students could leave notes for other students.
For example, one of my problems was bad indentation for the delete api in serverless.yml. I got the super helpful message āCannot read property āhandlerā of undefinedā. Maybe āserverless-stackā should just be a tag on StackOverflow.
Thanks for putting this all together. Super helpful.
Thanks @fanjie
I believe this framework is based on the idea that all routes (other then direct to index.html) will be directed to the index.html as 404 in the HTTP status. So for a logical SPA path like domain.com/path/ the browser would show the valid page looking very VALID and in all its creative love, but the http status would be 404? If that is correct, I think this would have adverse affects on SEO, no?
Seems like there is no golden bullet though. If you end up going SPA with no true webserver, you end up losing some HTTP status clarity.
Iāve thought about what it might look like to add an API Gateway and Lambda layer that could push all requests thru and let the Lambda handle the simple naked->www and single page redirects. But not sure what that would look like. Iād be willing to invest time to figuring it out if someone thought it would work.
Amazing repo, iām using it as the basis for my app. Would you think about adding social login to it? Would be great to see a clear example of how to integrate with Google and Facebook.