The Voice UI you built in Task 2
- In a new browser tab click on 'Services' (on the top left)
- In the search bar type 'IAM' and hit return
- You'll be presented with the IAM Dashboard
- Click on 'Roles' on the left navigation bar
- Click the 'Create role'
- Make sure 'AWS service' is selected as the 'type of trusted entity'
- Select 'API Gateway' as the service that will use the role
- Click 'Next: Permissions'
- Click 'Next: Review'
- Type 'ALX402API-Role' as the 'Role name'
- Click on "Create role"
- You'll be presented with the list of roles, click on the one you created ('ALX402API-Role')
- Click 'Add inline policy' (on the bottom right)
- Make sure 'Policy Generator' is selected and click the 'Select' button
- Select the 'Allow' radio button
- From the 'AWS Service' dropdown select 'Amazon DynamoDB'
- In the 'Actions' dropdown check the boxes for:
- 'GetItem'
- 'PutItem'
- 'Query'
- Paste the ARN for the 'ALX402Facts' DynamoDB table you created in Task 2
- You should have it in a text file, if not you can find it under the 'Overview' tab for your table
- Click 'Add Statement'
- Review the confirmation
- Click 'Next Step'
- Policy should look as follows:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt1511207534000",
"Effect": "Allow",
"Action": [
"dynamodb:GetItem",
"dynamodb:PutItem",
"dynamodb:Query"
],
"Resource": [
"The ARN for you DynamoDB Table should be here"
]
}
]
}
- Click 'Apply Policy'
- You will be presented with a 'Summary' page
- Make sure a policy that has 'policygen' as part of its name is present
- You can confirm the JSON object by clicking the arrow next to it
- Copy the Role ARN, for this role we will need it in the next task 1.
- Navigate to the 'API Gateway' Dashboard
- Click on the 'Create API' button or the 'Get Started' button
- If presented with a confirmation pop-up click 'OK'
- Select the 'New API' radio button
- Set 'API name' to 'ALX402FactAPI'
- Leave the 'Endpoint Type' set to 'Edge optimized'
- Click on the 'Create API' button
- Select 'Create Method' from the Actions dropdown
- From the new dropdown select 'Post'
- Click the checkmark button
- From the right hand pane select the 'AWS Service' radio button
- Select 'eu-west-1' as the 'AWS Region'
- Select 'DynamoDB' as the 'AWS Service'
- Leave the 'Subdomain' field blank
- Select 'Post' as the 'HTTP method'
- Leave the 'Use action name' radio button selected
- In the 'Action' field type 'PutItem'
- Paste the Role ARN you created in Task 5, into the 'Execution role' bfield
- Leave 'Content Handling' set to 'Passthrough'
- Click the save button
- You'll be presented with a 'Method Execution' page
- Click on 'Integration Request'
- Expand 'Body Mapping Templates' (at the bottom)
- Click on 'Add mapping template'
- Type 'application/json' as the 'content type'
- Click the gray check mark button
- Select 'Yes, secure this integration' from the pop-up that will appear
- Click 'Add mapping'
- Add the following mapping in the form that appeared at the bottom
{
"TableName": "ALX402FactDB",
"Item": {
"FactId": {
"S": "$context.requestId"
},
"locale": {
"S": "$input.path('$.locale')"
},
"speech": {
"S": "$input.path('$.speech')"
},
"text": {
"S": "$input.path('$.text')"
}
}
}
- Click 'Save'
- Scroll back to the top
- Click '<- Method Execution'
- Click 'Test'
- Paste the following objet in 'Request Body'
{
"locale":"en-US",
"speech":"Added from API test",
"text":"Text for Added from API test"
}
- Click ':zap: Test' button
- On the top right you should see 'Status: 200'
- Make sure the 'Response Body' is '{}'
- There will be an item in you DynamoDB table with 'test-invoke-request' as it's 'FactId'