Skip to content

Latest commit

 

History

History
 
 

02_Lambda

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

AWS Lambda

In this module you will create Lambda function to process your backend logic.

Serverless Backend Architecture

Implementation Instructions

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.

1. Login to AWS Console

  1. Go to your AWS Console

  2. Login as IAM user which have enough privilege

  3. Select AWS region: N. Virginia

2. Create IAM Role for AWS Lambda Execution

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.

  1. From the AWS Management Console, click on Services and then select Identity & Access Management in the Security, Identity & Compliance section.

  2. Select Roles in the left navigation bar and then choose Create New Role.

  3. Select role type:

  4. Make sure AWS Service Role is selected

  5. Choose AWS Lambda, and click Select

  6. Begin typing AWSLambdaBasicExecutionRole in the Filter text box and check the box next to that role.

  7. Click Next Step

  8. Enter lambda-supermission-role for the Role Name.

  9. Click Create role

  10. Type lambda-supermission-role into the filter box on the Roles page and choose the role you just created.

  11. On the Permissions tab, expand the Inline Policies section and choose the click here link to create a new inline policy. As shown below:
    Inline policies screenshot

  12. Ensure that Policy Generator is selected and choose Select.

  13. Ensure that Allow is selected in Effect

  14. Select Amazon DynamoDB from the AWS Service dropdown.

  15. Select All Actions from the Actions list.

  16. Paste the ARN of the table you created in the previous section in the Amazon Resource Name (ARN) field.
    Inline policies screenshot

  17. Choose Add Statement

  18. Choose Next Step, review Policy Document then click Apply Policy

3. Create Lambda Function - GetHeroesList

  1. From the AWS Management Console, click on Services and then select Lambda in Compute section.

  2. Click Create a Lambda Function

  3. Choose the Blank Function blueprint card.

  4. Don't add any triggers at this time. Choose Next to proceed to defining your function.

  5. Enter GetHeroesList in the Name field.

  6. Optionally enter a description.

  7. Select Node.js 6.10 for the Runtime.

  8. Copy and paste the code from getHeroesList.js into the code entry area.

  9. Leave the default of index.handler for the Handler field.

  10. For Role, click Choose an existing role

  11. Select lambda-supermission-role from the Existing Role dropdown.

  12. In the Advanced Settings section, all values canbe left at their defaults.

  13. Choose Next and then choose Create function on the Review page.

  14. From the Actions menu in the Lambda console, click Configure test event

  15. For Sample event template click Hello World

  16. Click Save and Test

  17. You will see a message telling you that Execution Result: Succeeded. You will see a text box displaying contents of the SuperMission DynamoDB table.

4. Create Lambda Function - GetMissionDetails

  1. Click Function at left side menu

  2. Click Create a Lambda Function

  3. Choose the Blank Function blueprint card.

  4. Don't add any triggers at this time. Choose Next to proceed to defining your function.

  5. Enter GetMissionDetails in the Name field.

  6. Optionally enter a description.

  7. Select Node.js 6.10 for the Runtime.

  8. Copy and paste the code from getMissionDetails.js into the code entry area.

  9. Leave the default of index.handler for the Handler field.

  10. For Role, click Choose an existing role

  11. Select lambda-supermission-role from the Existing Role dropdown.

  12. In the Advanced Settings section, all values canbe left at their defaults.

  13. Choose Next and then choose Create function on the Review page.

  14. From the Actions menu in the Lambda console, click Configure test event

  15. For Sample event template click Hello World

  16. In the editor, remove all of the placeholder code

  17. 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"}
  1. You will see a message telling you that Execution Result: Succeeded. You will see a text box displaying mission details for Batman.