Module 13 - Challenge Lab - Implementing A Serverless Architecture For The Café
Module 13 - Challenge Lab - Implementing A Serverless Architecture For The Café
Sofía and Nikhil's initial idea is to use one of the Amazon Elastic Compute Cloud (Amazon EC2) web server instances to generate the
report. Sofía sets up a cron job on the web server instance, which sends email messages that report daily sales. However, the cron job
reduces the performance of the web server because it is resource-intensive.
Nikhil mentions the cron job to Olivia, and how it reduces the web application's performance. Olivia advises Sofía and Nikhil to separate
non-business-critical reporting tasks from the production web server instance. After Sofía and Nikhil review the advantages and
disadvantages of their current approach, they decide that they don't want to slow down the web server. They also consider running a
separate EC2 instance, but they are concerned about the cost of running an instance 24/7 when it is only needed for a short time each
day.
Sofía and Nikhil decide that running the report generation code as an AWS Lambda function would work, and it would also lower costs.
The report itself could be sent to Frank and Martha's email address through Amazon Simple Notification Service (Amazon SNS).
In this lab, you will take on the role of Sofía to implement the daily report code as a Lambda function.
After completing this lab, you should be able to implement a serverless architecture to generate a daily sales report that features:
A Lambda function within a virtual private cloud (VPC) that connects to an Amazon Relational Database Service (Amazon RDS)
database with the café's sales data
A Lambda function that generates and runs the sales report
A scheduled event that triggers the sales report Lambda function each day
When you start the lab, your architecture will look like the following example:
At the end of this lab, your architecture should look like the following example:
Note: In this challenge lab, step-by-step instructions are not provided for most of the tasks. You must figure out how to complete the tasks
on your own.
Duration
This lab will require approximately 90 minutes to complete.
AWS service restrictions
In this lab environment, access to AWS services and service actions might be restricted to the ones that are needed to complete the lab
instructions. You might encounter errors if you attempt to access other services or perform actions beyond the ones that are described in
this lab.
Tip: If you need more time to complete the lab, choose the Start Lab button again to restart the timer for the environment.
2. Wait until you see the message Lab status: ready, then close the Start Lab panel by choosing the X.
This opens the AWS Management Console in a new browser tab. The system will automatically log you in.
Tip: If a new browser tab does not open, a banner or icon is usually at the top of your browser with a message that your
browser is preventing the site from opening pop-up windows. Choose the banner or icon and then choose Allow pop ups.
4. Arrange the AWS Management Console tab so that it displays along side these instructions. Ideally, you will be able to see both
browser tabs at the same time so that you can follow the lab steps more easily.
Answers will be recorded when you choose the blue Submit button at the end of the lab.
9. Create a security group for the Lambda function with the following settings:
Add a second inbound rule. For the new rule, configure the Type as MYSQL/Aurora. Then, in the search box to the right of
Custom, type sg- and choose your new Lambda function security group as the source. Finally, choose Save rules.
11. Create a Lambda function with the following settings:
Role: salesAnalysisReportDERole
VPC:
Name: SalesReportTopic
Display Name: Sales Report Topic
17. Update the salesAnalysisReport Lambda function by adding the following environment variable:
Question 3: Could the topicARN be stored as an AWS Systems Manager parameter instead of as an environment variable
(assuming that the code could be updated)?
19. Create a new email subscription to the topic. Use an email address that you can easily access for this lab.
21. Return to the browser tab with the multiple-choice questions for this lab, and answer the following question:
Question 4: Will you receive an email message if you do not confirm the topic subscription?
Tip: You don't need to worry about parameters, so enter an event name and accept the default hello-world test event.
23. Run the salesAnalysisReport test. If the test succeeds, you should have an email report in a couple of minutes.
24. If the Lambda function test execution failed, use the logs to review any errors, address them, and run the test again. Here are some
troubleshooting tips that you can try:
Review the logs from Amazon CloudWatch Logs for both Lambda functions:
If you see an error about connecting to the café database, check that your security groups are configured correctly.
If you see an error about timeout, check that the timeout is set to 30 seconds.
If you see an error about lambda_function not found, check that you have configured the correct handler.
Review your work to make sure that you completed all the steps.
Go to the Submitting your work section and follow the steps to submit your work. The submission report will show whether you
completed the previous steps correctly.
Task 7: Setting up an Amazon EventBridge event to trigger the Lambda function each
day
The last step in this challenge is to set up a trigger that will run the report each day.
25. Create a new EventBridge rule that runs the salesAnalysisReport Lambda function each day at a specific time. Make sure to choose
Continue to create rule.
Hint: If you get stuck, see the cron expression examples in the AWS Documentation.
Tip: Use a time that is close to your current time, but remember that the time must be specified in Coordinated Universal Time (UTC)!
27. Return to the browser tab with the multiple-choice questions for this lab, and answer the following question:
Question 5: Frank tells you that he hasn't received an email report in the last few days. What could you do to troubleshoot this
issue?
Sofía is pleased that she automated sales reporting for the café, which will continue to help Frank and Martha analyze daily sales and
plan the café's inventory. She's also happy that she successfully learned how to use AWS Lambda, Amazon SNS, and Amazon
EventBridge. In fact, Sofía plans to implement more serverless and automated reporting features into the café's web application to help
the café grow and manage their business.
29. If the results don't display after a couple of minutes, return to the top of these instructions and choose Grades
Tip: You can submit your work multiple times. After you change your work, choose Submit again. Your last submission is what will
be recorded for this lab.
30. To find detailed feedback on your work, choose Details followed by View Submission Report.
Lab complete
Congratulations! You have completed the lab.
31. To confirm that you want to end the lab, at the top of this page, choose End Lab , and then choose Yes
A panel should appear with this message: DELETE has been initiated... You may close this message box now.
©2020 Amazon Web Services, Inc. and its affiliates. All rights reserved. This work may not be reproduced or redistributed, in whole or in
part, without prior written permission from Amazon Web Services, Inc. Commercial copying, lending, or selling is prohibited.