You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 14, 2025. It is now read-only.
In this module you'll use AWS Lambda and Amazon DynamoDB to build a backend process for handling requests from your web application. The browser application that you deployed in the first module allows users to request that a unicorn be sent to a location of their choice. In order to fulfill those requests, the JavaScript running in the browser will need to invoke a service running in the cloud.
3
+
In this module you'll use [AWS Lambda][lambda] and [Amazon DynamoDB][dynamodb] to build a backend process for handling requests from your web application. The browser application that you deployed in the first module allows users to request that a unicorn be sent to a location of their choice. In order to fulfill those requests, the JavaScript running in the browser will need to invoke a service running in the cloud.
4
4
5
5
You'll implement a Lambda function that will be invoked each time a user requests a unicorn. The function will select a unicorn from the fleet, record the request in a DynamoDB table and then respond to the front-end application with details about the unicorn being dispatched.
The function is invoked from the browser using Amazon API Gateway. You'll implement that connection in the next module. For this module you'll just test your function in isolation.
10
-
11
-
If you want to skip ahead to the next module, you can **launch the stack from [module 4 (RESTful APIs)](../4_RESTfulAPIs)**.
9
+
The function is invoked from the browser using [Amazon API Gateway][api-gw]. You'll implement that connection in the next module. For this module you'll just test your function in isolation.
12
10
13
11
## Implementation Instructions
14
12
15
-
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.
13
+
:heavy_exclamation_mark: Ensure you've completed the [User Management][user-management] step before beginning this module.
16
14
17
-
If you're using the latest version of the Chrome, Firefox, or Safari web browsers the step-by-step instructions won't be visible until you expand the section.
15
+
Each of the following sections provides 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.
18
16
19
17
### 1. Create an Amazon DynamoDB Table
20
18
21
19
Use the Amazon DynamoDB console to create a new DynamoDB table. Call your table `Rides` and give it a partition key called `RideId` with type String. The table name and partition key are case sensitive. Make sure you use the exact IDs provided. Use the defaults for all other settings.
22
20
23
21
After you've created the table, note the ARN for use in the next step.
24
22
25
-
<details>
26
-
<summary><strong>Step-by-step instructions (expand for details)</strong></summary><p>
27
-
28
-
1. From the AWS Management Console, choose **Services** then select **DynamoDB** under Databases.
29
-
23
+
**:white_check_mark: Step-by-step directions**
24
+
1. Go to the [Amazon DynamoDB Console][dynamodb-console]
30
25
1. Choose **Create table**.
31
-
32
26
1. Enter `Rides` for the **Table name**. This field is case sensitive.
33
-
34
27
1. Enter `RideId` for the **Partition key** and select **String** for the key type. This field is case sensitive.
35
-
36
28
1. Check the **Use default settings** box and choose **Create**.
1. Scroll to the bottom of the Overview section of your new table and note the **ARN**. You will use this in the next section.
41
31
42
-
</p></details>
43
-
44
-
45
32
### 2. Create an IAM Role for Your Lambda function
46
33
47
34
#### Background
@@ -54,52 +41,35 @@ Use the IAM console to create a new role. Name it `WildRydesLambda` and select A
54
41
55
42
Attach the managed policy called `AWSLambdaBasicExecutionRole` to this role to grant the necessary CloudWatch Logs permissions. Also, create a custom inline policy for your role that allows the `ddb:PutItem` action for the table you created in the previous section.
56
43
57
-
<details>
58
-
<summary><strong>Step-by-step instructions (expand for details)</strong></summary><p>
59
-
60
-
1. From the AWS Management Console, click on **Services** and then select **IAM** in the Security, Identity & Compliance section.
61
-
62
-
1. Select **Roles** in the left navigation bar and then choose **Create new role**.
63
-
44
+
**:white_check_mark: Step-by-step directions**
45
+
1. Go to the [AWS IAM Console][iam-console]
46
+
1. Select **Roles** in the left navigation bar and then choose **Create role**.
64
47
1. Select **Lambda** for the role type from the **AWS service** group, then click **Next: Permissions**
65
-
66
48
**Note:** Selecting a role type automatically creates a trust policy for your role that allows AWS services to assume this role on your behalf. If you were creating this role using the CLI, AWS CloudFormation or another mechanism, you would specify a trust policy directly.
67
-
68
49
1. Begin typing `AWSLambdaBasicExecutionRole` in the **Filter** text box and check the box next to that role.
69
-
50
+
1. Click **Next: Tags**. Add any tags that you wish.
70
51
1. Click **Next: Review**.
71
-
72
52
1. Enter `WildRydesLambda` for the **Role name**.
53
+
1. Choose **Create role**.
73
54
74
-
1. Choose **Create role**.
75
-
76
-
1. Type `WildRydesLambda` into the filter box on the Roles page and choose the role you just created.
55
+
Next you need to add permissions to the role so that it can access your DynamoDB table.
77
56
57
+
**:white_check_mark: Step-by-step directions*
58
+
1. While in the IAM Console on the roles page type `WildRydesLambda` into the filter box on the Roles page and choose the role you just created.
78
59
1. On the Permissions tab, choose the **Add inline policy** link in the lower right corner to create a new inline policy.
1. Begin typing `PutItem` into the search box labeled **Filter actions** and check the box next to **PutItem** when it appears.
89
-
90
66
1. Select the **Resources** section.
91
-
92
67
1. With the **Specific** option selected, choose the Add ARN link in the **table** section.
93
-
94
68
1. Paste the ARN of the table you created in the previous section in the **Specify ARN for table** field, and choose **Add**.
95
-
96
69
1. Choose **Review Policy**.
97
-
98
70
1. Enter `DynamoDBWriteAccess` for the policy name and choose **Create policy**.
99
71

100
72
101
-
</p></details>
102
-
103
73
### 3. Create a Lambda Function for Handling Requests
104
74
105
75
#### Background
@@ -112,46 +82,31 @@ Use the AWS Lambda console to create a new Lambda function called `RequestUnicor
112
82
113
83
Make sure to configure your function to use the `WildRydesLambda` IAM role you created in the previous section.
114
84
115
-
<details>
116
-
<summary><strong>Step-by-step instructions (expand for details)</strong></summary><p>
117
-
118
-
1. Choose on **Services** then select **Lambda** in the Compute section.
119
-
85
+
**:white_check_mark: Step-by-step directions**
86
+
1. Go to the [AWS Lambda][lambda-console]
120
87
1. Click **Create function**.
121
-
122
88
1. Keep the default **Author from scratch** card selected.
123
-
124
89
1. Enter `RequestUnicorn` in the **Name** field.
125
-
126
-
1. Select **Node.js 6.10** for the **Runtime**.
127
-
90
+
1. Select **Node.js 8.10** for the **Runtime**.
91
+
2. Expand *Choose or create an execution role* under **Permissions**.
128
92
1. Ensure `Choose an existing role` is selected from the **Role** dropdown.
129
-
130
93
1. Select `WildRydesLambda` from the **Existing Role** dropdown.
131
94

132
-
133
95
1. Click on **Create function**.
134
-
135
96
1. Scroll down to the **Function code** section and replace the existing code in the **index.js** code editor with the contents of [requestUnicorn.js](requestUnicorn.js).
136
97

137
-
138
98
1. Click **"Save"** in the upper right corner of the page.
139
99
140
-
</p></details>
141
-
142
100
## Implementation Validation
143
101
144
102
For this module you will test the function that you built using the AWS Lambda console. In the next module you will add a REST API with API Gateway so you can invoke your function from the browser-based application that you deployed in the first module.
145
103
146
-
1. From the main edit screen for your function, select **Configure test event** from the the **Select a test event...** dropdown.
104
+
**:white_check_mark: Step-by-step directions**
105
+
1. From the main edit screen for your function, select **Configure test events** from the the **Select a test event...** dropdown.
147
106

148
-
149
107
1. Keep **Create new test event** selected.
150
-
151
108
1. Enter `TestRequestEvent` in the **Event name** field
152
-
153
109
1. Copy and paste the following test event into the editor:
154
-
155
110
```JSON
156
111
{
157
112
"path": "/ride",
@@ -173,15 +128,10 @@ For this module you will test the function that you built using the AWS Lambda c

178
-
179
132
1. Click **Create**.
180
-
181
133
1. On the main function edit screen click **Test** with `TestRequestEvent` selected in the dropdown.
182
-
183
134
1. Scroll to the top of the page and expand the **Details** section of the **Execution result** section.
184
-
185
135
1. Verify that the execution succeeded and that the function result looks like the following:
186
136
```JSON
187
137
{
@@ -193,4 +143,24 @@ For this module you will test the function that you built using the AWS Lambda c
193
143
}
194
144
```
195
145
196
-
After you have successfully tested your new function using the Lambda console, you can move on to the next module, [RESTful APIs](../4_RESTfulAPIs).
146
+
### :star: Recap
147
+
148
+
:key:[AWS Lambda][lambda] is a serverless functions as a service product that removes the burden of managing servers to run your applications. You configure a trigger and set the role that the function can use and then can interface with almost anything you want from databases, to datastores, to other services eithe publicly on the internet or in your own Amazon Virtual Private Cloud (VPC). [Amazon DynamoDB][dynamodb] is a non-relational serverless database that can scale automatically to handle massive amounts of traffic and data without you need manage any servers.
149
+
150
+
:wrench: In this module you've created a DynamoDB table and then a Lambda function to write data into it. This function will be put behind an Amazon API Gateway in the next module which will in turn be connected to your web application to capture the ride details from your users.
151
+
152
+
### Next
153
+
154
+
:white_check_mark: After you have successfully tested your new function using the Lambda console, you can move on to the next module, [RESTful APIs][restful-apis].
0 commit comments