In this module you will create Lambda function to process your backend logic.
Each of the following sections provide an implementation overview and detailed, step-by-step instructions. The overview should provide enough context for you to complete the implementation if you're already familiar with the AWS Management Console or you want to explore the services yourself without following a walkthrough.
-
Go to your AWS Console
-
Login as IAM user which have enough privilege
-
Select AWS region: N. Virginia
Use the IAM console to create a new role. You'll need to attach policies that grant your function permissions to write to Amazon CloudWatch Logs and put items to your DynamoDB table.
-
From the AWS Management Console, click on Services and then select Identity & Access Management in the Security, Identity & Compliance section.
-
Select Roles in the left navigation bar and then choose Create New Role.
-
Select role type:
-
Make sure AWS Service Role is selected
-
Choose AWS Lambda, and click Select
-
Begin typing
AWSLambdaBasicExecutionRole
in the Filter text box and check the box next to that role. -
Click Next Step
-
Enter
lambda-supermission-role
for the Role Name. -
Click Create role
-
Type
lambda-supermission-role
into the filter box on the Roles page and choose the role you just created. -
On the Permissions tab, expand the Inline Policies section and choose the click here link to create a new inline policy. As shown below:
-
Ensure that Policy Generator is selected and choose Select.
-
Ensure that
Allow
is selected in Effect -
Select Amazon DynamoDB from the AWS Service dropdown.
-
Select All Actions from the Actions list.
-
Paste the ARN of the table you created in the previous section in the Amazon Resource Name (ARN) field.
-
Choose Add Statement
-
Choose Next Step, review Policy Document then click Apply Policy
-
From the AWS Management Console, click on Services and then select Lambda in Compute section.
-
Click Create a Lambda Function
-
Choose the Blank Function blueprint card.
-
Don't add any triggers at this time. Choose Next to proceed to defining your function.
-
Enter
GetHeroesList
in the Name field. -
Optionally enter a description.
-
Select Node.js 6.10 for the Runtime.
-
Copy and paste the code from getHeroesList.js into the code entry area.
-
Leave the default of
index.handler
for the Handler field. -
For Role, click Choose an existing role
-
Select
lambda-supermission-role
from the Existing Role dropdown. -
In the Advanced Settings section, all values canbe left at their defaults.
-
Choose Next and then choose Create function on the Review page.
-
From the Actions menu in the Lambda console, click Configure test event
-
For Sample event template click Hello World
-
Click Save and Test
-
You will see a message telling you that Execution Result: Succeeded. You will see a text box displaying contents of the SuperMission DynamoDB table.
-
Click Function at left side menu
-
Click Create a Lambda Function
-
Choose the Blank Function blueprint card.
-
Don't add any triggers at this time. Choose Next to proceed to defining your function.
-
Enter
GetMissionDetails
in the Name field. -
Optionally enter a description.
-
Select Node.js 6.10 for the Runtime.
-
Copy and paste the code from getMissionDetails.js into the code entry area.
-
Leave the default of
index.handler
for the Handler field. -
For Role, click Choose an existing role
-
Select
lambda-supermission-role
from the Existing Role dropdown. -
In the Advanced Settings section, all values canbe left at their defaults.
-
Choose Next and then choose Create function on the Review page.
-
From the Actions menu in the Lambda console, click Configure test event
-
For Sample event template click Hello World
-
In the editor, remove all of the placeholder code
-
Copy the code below, and paste it into the editor. This code will look for details of Batman's mission in the DynamoDB table.
{"superhero": "Batman"}
- You will see a message telling you that Execution Result: Succeeded. You will see a text box displaying mission details for Batman.