|
| 1 | +## Lab 3: |
| 2 | +### Pre-Requisites |
| 3 | + |
| 4 | +The Voice UI you built in |
| 5 | +[Task 2](/Lab1.md#task-2-build-a-voice-ui) |
| 6 | + |
| 7 | +-------- |
| 8 | + |
| 9 | +### Task 5: Create IAM role for our API |
| 10 | + 1. In a new browser tab click on 'Services' (on the top left) |
| 11 | + 2. In the search bar type 'IAM' and hit return |
| 12 | + 1. You'll be presented with the [IAM Dashboard](https://console.aws.amazon.com/iam/home?region=eu-west-1#/home) |
| 13 | + 3. Click on 'Roles' on the left navigation bar |
| 14 | + 4. Click the 'Create role' |
| 15 | + 5. Make sure 'AWS service' is selected as the 'type of trusted entity' |
| 16 | + 6. Select 'API Gateway' as the service that will use the role |
| 17 | + 7. Click 'Next: Permissions' |
| 18 | + 8. Click 'Next: Review' |
| 19 | + 9. Type 'ALX402API-Role' as the 'Role name' |
| 20 | + 10. Click on "Create role" |
| 21 | + 11. You'll be presented with the list of roles, click on the one you created ('ALX402API-Role') |
| 22 | + 12. Click 'Add inline policy' (on the bottom right) |
| 23 | + 13. Make sure 'Policy Generator' is selected and click the 'Select' button |
| 24 | + 14. Select the 'Allow' radio button |
| 25 | + 15. From the 'AWS Service' dropdown select 'Amazon DynamoDB' |
| 26 | + 16. In the 'Actions' dropdown check the boxes for: |
| 27 | + 1. 'GetItem' |
| 28 | + 2. 'PutItem' |
| 29 | + 3. 'Query' |
| 30 | + 17. Paste the ARN for the 'ALX402Facts' DynamoDB table you created in Task 2 |
| 31 | + 1. You should have it in a text file, if not you can find it under the 'Overview' tab for your table |
| 32 | + 18. Click 'Add Statement' |
| 33 | + 19. Review the confirmation |
| 34 | + 20. Click 'Next Step' |
| 35 | + 21. Policy should look as follows: |
| 36 | + |
| 37 | + ```javascript |
| 38 | + { |
| 39 | + "Version": "2012-10-17", |
| 40 | + "Statement": [ |
| 41 | + { |
| 42 | + "Sid": "Stmt1511207534000", |
| 43 | + "Effect": "Allow", |
| 44 | + "Action": [ |
| 45 | + "dynamodb:GetItem", |
| 46 | + "dynamodb:PutItem", |
| 47 | + "dynamodb:Query" |
| 48 | + ], |
| 49 | + "Resource": [ |
| 50 | + "The ARN for you DynamoDB Table should be here" |
| 51 | + ] |
| 52 | + } |
| 53 | + ] |
| 54 | + } |
| 55 | + ``` |
| 56 | + |
| 57 | + 22. Click 'Apply Policy' |
| 58 | + 23. You will be presented with a 'Summary' page |
| 59 | +#### Verify: |
| 60 | + 24. Make sure a policy that has 'policygen' as part of its name is present |
| 61 | + 1. You can confirm the JSON object by clicking the arrow next to it |
| 62 | + 25. Copy the Role ARN, for this role we will need it in the next task |
| 63 | + 1. |
| 64 | + |
| 65 | +-------- |
| 66 | + |
| 67 | +### Task 6: Add an API Gateway to handle writing new facts |
| 68 | + 1. Navigate to the ['API Gateway' Dashboard](https://eu-west-1.console.aws.amazon.com/apigateway) |
| 69 | + 2. Click on the 'Create API' button or the 'Get Started' button |
| 70 | + 1. If presented with a confirmation pop-up click 'OK' |
| 71 | + 3. Select the 'New API' radio button |
| 72 | + 4. Set 'API name' to 'ALX402FactAPI' |
| 73 | + 5. Leave the 'Endpoint Type' set to 'Edge optimized' |
| 74 | + 6. Click on the 'Create API' button |
| 75 | + 7. Select 'Create Method' from the Actions dropdown |
| 76 | + 8. From the new dropdown select 'Post' |
| 77 | + 1. Click the checkmark button |
| 78 | + 10. From the right hand pane select the 'AWS Service' radio button |
| 79 | + 11. Select 'eu-west-1' as the 'AWS Region' |
| 80 | + 12. Select 'DynamoDB' as the 'AWS Service' |
| 81 | + 13. Leave the 'Subdomain' field blank |
| 82 | + 14. Select 'Post' as the 'HTTP method' |
| 83 | + 15. Leave the 'Use action name' radio button selected |
| 84 | + 16. In the 'Action' field type 'PutItem' |
| 85 | + 17. Paste the Role ARN you created in Task 5, into the 'Execution role' bfield |
| 86 | + 18. Leave 'Content Handling' set to 'Passthrough' |
| 87 | + 19. Click the save button |
| 88 | + 20. You'll be presented with a 'Method Execution' page |
| 89 | + 21. Click on 'Integration Request' |
| 90 | + 22. Expand 'Body Mapping Templates' (at the bottom) |
| 91 | + 23. Click on 'Add mapping template' |
| 92 | + 24. Type 'application/json' as the 'content type' |
| 93 | + 25. Click the gray check mark button |
| 94 | + 26. Select 'Yes, secure this integration' from the pop-up that will appear |
| 95 | + 27. Click 'Add mapping' |
| 96 | + 28. Add the following mapping in the form that appeared at the bottom |
| 97 | + |
| 98 | + ```javascript |
| 99 | + { |
| 100 | + "TableName": "ALX402FactDB", |
| 101 | + "Item": { |
| 102 | + "FactId": { |
| 103 | + "S": "$context.requestId" |
| 104 | + }, |
| 105 | + "locale": { |
| 106 | + "S": "$input.path('$.locale')" |
| 107 | + }, |
| 108 | + "speech": { |
| 109 | + "S": "$input.path('$.speech')" |
| 110 | + }, |
| 111 | + "text": { |
| 112 | + "S": "$input.path('$.text')" |
| 113 | + } |
| 114 | + } |
| 115 | +} |
| 116 | + ``` |
| 117 | + |
| 118 | + 29. Click 'Save' |
| 119 | +#### Verify: |
| 120 | + 30. Scroll back to the top |
| 121 | + 31. Click '<- Method Execution' |
| 122 | + 32. Click 'Test' |
| 123 | + 33. Paste the following objet in 'Request Body' |
| 124 | + |
| 125 | +```javascript |
| 126 | + { |
| 127 | + "locale":"en-US", |
| 128 | + "speech":"Added from API test", |
| 129 | + "text":"Text for Added from API test" |
| 130 | + } |
| 131 | +``` |
| 132 | + |
| 133 | + 33. Click ':zap: Test' button |
| 134 | + 34. On the top right you should see 'Status: 200' |
| 135 | + 35. Make sure the 'Response Body' is '{}' |
| 136 | + 36. There will be an item in you DynamoDB table with 'test-invoke-request' as it's 'FactId' |
| 137 | + |
| 138 | +-------- |
| 139 | + |
| 140 | +### [Lab 4](/Lab4.md) |
| 141 | + |
| 142 | +-------- |
| 143 | + |
| 144 | +### Extra Credit 1 : Add a Get method that returns all the facts |
| 145 | +### Extra Credit 2 : Add a method to edit a single fact by providing it's FactId |
| 146 | + |
| 147 | +-------- |
0 commit comments