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.
Copy file name to clipboardExpand all lines: WebApplication/3_ServerlessBackend/README.md
+29-23Lines changed: 29 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -61,7 +61,7 @@ Attach the managed policy called `AWSLambdaBasicExecutionRole` to this role to g
61
61
62
62
1. Select **Roles** in the left navigation bar and then choose **Create new role**.
63
63
64
-
1. Select **Lambda** for the role type from **AWS Service Role**, then click **Next: Permissions**
64
+
1. Select **Lambda** for the role type from the **AWS service** group, then click **Next: Permissions**
65
65
66
66
**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
67
@@ -75,22 +75,28 @@ Attach the managed policy called `AWSLambdaBasicExecutionRole` to this role to g
75
75
76
76
1. Type `WildRydesLambda` into the filter box on the Roles page and choose the role you just created.
77
77
78
-
1. On the Permissions tab, click **Add inline policy** link to create a new inline policy.
78
+
1. On the Permissions tab, choose the **Add inline policy** link in the lower right corner to create a new inline policy.
1.With the **Specific** option selected, choose the Add ARN link in the **table** section.
92
93
93
-
1. Choose **Next Step** then **Apply Policy**.
94
+
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
+
1. Choose **Review Policy**.
97
+
98
+
1. Enter `DynamoDBWriteAccess` for the policy name and choose **Create policy**.
99
+

94
100
95
101
</p></details>
96
102
@@ -113,39 +119,36 @@ Make sure to configure your function to use the `WildRydesLambda` IAM role you c
113
119
114
120
1. Click **Create function**.
115
121
116
-
1.Click on **Author from scratch**.
122
+
1.Keep the default **Author from scratch** card selected.
117
123
118
124
1. Enter `RequestUnicorn` in the **Name** field.
119
125
126
+
1. Select **Node.js 6.10** for the **Runtime**.
127
+
128
+
1. Ensure `Choose an existing role` is selected from the **Role** dropdown.
129
+
120
130
1. Select `WildRydesLambda` from the **Existing Role** dropdown.
121
131

122
132
123
133
1. Click on **Create function**.
124
134
125
-
1. Click **Configuration**.
126
-
127
-
1. Select **Node.js 6.10** for the **Runtime**.
128
-
129
-
1. Leave the default of `index.handler` for the **Handler** field.
130
-
131
-
1. Copy and paste the code from [requestUnicorn.js](requestUnicorn.js) into the code entry area.
135
+
1. Scroll down to the **Function code** section and replace the exiting code in the **index.js** code editor with the contents of [requestUnicorn.js](requestUnicorn.js).
132
136

133
137
134
-
1.Scroll to top and click **"Save"**(**Not** "Save and test" since we haven't configured any test event)
138
+
1.Click **"Save"**in the upper right corner of the page.
135
139
136
140
</p></details>
137
141
138
142
## Implementation Validation
139
143
140
144
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.
141
145
142
-
1. From the main edit screen for your function, select **Configure test event** from "Select a test event..." dropdown list.
146
+
1. From the main edit screen for your function, select **Configure test event** from the the **Select a test event...** dropdown.
143
147

144
148
145
-
1.Leave "Hello World" there
149
+
1.Keep **Create new test event** selected.
146
150
147
-
1. Put "TestRequestEvent" into Event name
148
-

151
+
1. Enter `TestRequestEvent` in the **Event name** field
149
152
150
153
1. Copy and paste the following test event into the editor:
151
154
@@ -171,10 +174,13 @@ For this module you will test the function that you built using the AWS Lambda c
171
174
}
172
175
```
173
176
177
+

174
178
175
179
1. Click **Create**.
176
180
177
-
1. Click **Test**.
181
+
1. On the main function edit screen click **Test** with `TestRequestEvent` selected in the dropdown.
182
+
183
+
1. Scroll to the top of the page and expand the **Details** section of the **Execution result** section.
178
184
179
185
1. Verify that the execution succeeded and that the function result looks like the following:
Copy file name to clipboardExpand all lines: WebApplication/4_RESTfulAPIs/README.md
+17-28Lines changed: 17 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -69,6 +69,9 @@ Use the Amazon API Gateway console to create a new API.
69
69
70
70
1. Select **New API** and enter `WildRydes` for the **API Name**.
71
71
72
+
1. Keep `Edge optimized` selected in the **Endpoint Type** dropdown.
73
+
***Note***: Edge optimized are best for public services being accessed from the Internet. Regional endpoints are typically used for APIs that are accessed primarily from within the same AWS Region.
74
+
72
75
1. Choose **Create API**
73
76
74
77

@@ -91,35 +94,37 @@ In the Amazon API Gateway console, create a new Cognito user pool authorizer for
91
94
92
95
1. Chose **Create New Authorizer**.
93
96
94
-

95
-
96
97
1. Enter `WildRydes` for the Authorizer name.
97
98
98
99
1. Select **Cognito** for the type.
99
100
100
-
1. In the Region drop-down under **Cognito User Pool**, select the Region where you created your Cognito user pool in module 2.
101
+
1. In the Region drop-down under **Cognito User Pool**, select the Region where you created your Cognito user pool in module 2 (by default the current region should be selected).
101
102
102
103
1. Enter `WildRydes` (or the name you gave your user pool) in the **Cognito User Pool** input.
103
104
104
105
1. Enter `Authorization` for the **Token Source**.
105
106
106
107
1. Choose **Create**.
107
108
109
+

110
+
108
111
#### Verify your authorizer configuration
109
112
110
113
1. Open a new browser tab and visit `/ride.html` under your website's domain.
111
114
112
115
1. If you are redirected to the sign-in page, sign in with the user you created in the last module. You will be redirected back to `/ride.html`.
113
116
114
-
1. Copy the auth token from the notification on the `/ride.html`,
117
+
1. Copy the auth token from the notification on the `/ride.html`,
115
118
116
119
1. Go back to previous tab where you have just finished creating the Authorizer
117
120
118
-
1. Click "Test", paste it into the **Authorization Token** field in the popup dialog.
121
+
1. Click **Test** at the bottom of the card for the authorizer.
122
+
123
+
1. Paste the auth token into the **Authorization Token** field in the popup dialog.
1. With the newly created `/ride` resource selected, from the **Action** dropdown select **Create Method**.
143
152
144
153
1. Select `POST` from the new dropdown that appears, then **click the checkmark**.
@@ -169,27 +178,7 @@ Create a new resource called /ride within your API. Then create a POST method fo
169
178
170
179
</p></details>
171
180
172
-
### 4. Enable CORS
173
-
Modern web browsers prevent HTTP requests from scripts on pages hosted on one domain to APIs hosted on another domain unless the API provides cross-origin resource sharing (CORS) response headers that explicitly allow them. In the Amazon API Gateway console you can add the necessary configuration to send the appropriate CORS headers under the action menu when you have a resource selected. You should enable CORS for POST and OPTIONS on your /ride resource. For simplicity, you can set the Access-Control-Allow-Origin header value to '\*', but in a production application you should always explicitly whitelist authorized domains to mitigate [cross-site request forgery (CSRF)](https://www.owasp.org/index.php/Cross-Site_Request_Forgery_%28CSRF%29) attacks.
174
-
175
-
For more information about CORS configurations in general, see https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
176
-
177
-
<details>
178
-
<summary><strong>Step-by-step instructions (expand for details)</strong></summary><p>
179
-
180
-
1. In the Amazon API Gateway console, in the middle panel, select the `/ride` resource.
181
-
182
-
1. From the **Actions** drop-down list select **Enable CORS**.
183
-
184
-
1. Use the default settings and choose **Enable CORS and replace existing CORS headers**.
185
-
186
-
1. Choose **Yes, replace existing values**.
187
-
188
-
1. Wait for a checkmark to appear next to all the steps.
189
-
190
-
</p></details>
191
-
192
-
### 5. Deploy Your API
181
+
### 4. Deploy Your API
193
182
From the Amazon API Gateway console, choose Actions, Deploy API. You'll be prompted to create a new stage. You can use prod for the stage name.
194
183
195
184
<details>
@@ -207,7 +196,7 @@ From the Amazon API Gateway console, choose Actions, Deploy API. You'll be promp
207
196
208
197
</p></details>
209
198
210
-
### 6. Update the Website Config
199
+
### 5. Update the Website Config
211
200
Update the /js/config.js file in your website deployment to include the invoke URL of the stage you just created. You should copy the invoke URL directly from the top of the stage editor page on the Amazon API Gateway console and paste it into the \_config.api.invokeUrl key of your sites /js/config.js file. Make sure when you update the config file it still contains the updates you made in the previous module for your Cognito user pool.
0 commit comments