A few of my developer friends and colleagues at work asked me how they can learn more about AWS. I told them that the best way to learn is:
- To do hands-on experience
- Learn something that has close parallels to what you're doing
- Solve a well-defined problem that you have to research the answer for instead of handing it to you.
Hence, the serverless challenge was born. The challenge is best suited for people who have some experience in development but have not necessarily touched up on the latest trend of serverless computing.
You are the dev lead (aka 'the only dev') of a chain of restaurants. To increase sales, your boss wants you to create a simple loyalty application. He has heard of the Serverless Framework and how it allows your team to use serverless technologies like Lambda to deploy your application. Your boss is particularly sensitive to cost. Since Lambda only charges you when the code is run (when someone uses your app), your boss is thrilled to introduce the technology.
Create 3 Lambda functions for each endpoint:
- POST /loyalty-cards: create a loyalty card
- GET /loyalty-cards/10: display the loyalty card you just created using the id
- GET /loyalty-cards: display all loyalty cards
You must follow the guidelines below:
- The Lambda function must be deployed using the Serverless Framework (SF). SF is a tool that makes deploying Lambda functions easier. You no longer have to package dependencies and upload code to Lambda manually. All you need to do is run "serverless deploy".
- Your data must persist, and your database must be DynamoDB. DynamoDB is a NoSQL database service by AWS. Unlike traditional relational databases, DynamoDB does not maintain a schema. Except for the primary key attributes (which have to be unique for each record), you can add different attributes for different items in the table.
The resources here will certainly help you get started with this challenge. But it won't be the only ones you'll use. You will have to research some answers.
- Create your own AWS account (if you don't have access to one). See the AWS Tutorial on how to do this.
- Setup AWS CLI in your local: https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html
- Hello World in Lambda - your first Lambda function deployed using Serverless Framework
- Creating Rest APIs
serverlessto initialize a project
serverless deployto deploy your project. A link to API Gateway will be displayed after deployment. Use that link to test in Postman
- At this point, the only way to test your code is to keep deploying using
serverless deployand using APIGW to test.
- To debug, leave print messages in your code and find the log group for the lambda function. It is under cloudwatch > logs > log groups (https://console.aws.amazon.com/cloudwatch/home?region=us-east-1#logsV2:log-groups)
- If you are wondering why we have to test by deploying your function every time and test via APIGW and if there's a better way, you are right. The better way is to use serverless offline and serverless invoke. You can find them at the third challenge
Comment a screencap of your work below. Or better yet, create a blog post here in dev.to explaining how you did it.
If you have any questions or are stuck somewhere, comment below or send me a pm, and I'd be happy to help you.