Skip to content
This repository was archived by the owner on Mar 4, 2022. It is now read-only.

Commit 416cdfd

Browse files
author
Justin
committed
Update readme and add lab guides
Signed-off-by: Justin <[email protected]>
1 parent 93598a5 commit 416cdfd

File tree

6 files changed

+560
-5
lines changed

6 files changed

+560
-5
lines changed

Lab1.md

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
## Lab 1:
2+
### Pre-Requisites
3+
4+
An [AWS Account](https://aws.amazon.com/)
5+
6+
**IMPORTANT: Make sure you are on the 'EU (Ireland)' AWS Region**
7+
8+
A [Developer Portal Account](https://developer.amazon.com/)
9+
10+
--------
11+
12+
### Task 1: Deploy Code to Lambda
13+
1. In a new browser window go to [console.aws.amazon.com](http://console.aws.amazon.com)
14+
2. Sign in with your credentials.
15+
3. Type `Lambda` in the search bar at the top & hit *enter*
16+
4. Click on the orange 'Create function' button in the top right corner or on the blue 'get started' button
17+
5. Type `Fact` in the Blueprint search bar & hit *enter*
18+
6. Click on 'alexa-skill-kit-sdk-factskill'
19+
7. Type `ALX402` for your function name
20+
8. From the 'Role' dropdown select 'Create new role from template(s)'
21+
9. Type `ALX402-role` for your role name
22+
10. Select 'Simple Microservices Permissions' from the 'Policy templates' dropdown
23+
11. Scroll to the bottom of the page and click the orange 'Create function' button.
24+
#### Verify:
25+
12. Click on the 'Test' button on the top right corner
26+
13. From the 'Event Template' dropdown select 'Alexa Start Session'
27+
14. Type `StartSession` in the 'event name' field
28+
15. Click the orange 'Create' button at the bottom of the screen.
29+
16. Click the 'Test' button again to run your newly created test.
30+
17. You should see a green box with the legend: 'Execution result: succeeded'
31+
18. Click on 'Triggers' tab
32+
19. Click on 'Add trigger'
33+
20. Click on the dotted line square
34+
21. From the dropdown select 'Alexa Skills Kit'
35+
22. Click 'Submit'
36+
23. Congratulations! You've deployed a serverless backend for an Alexa Skill
37+
24. From the top right corner copy the Amazon Resource Name (ARN) for this Lambda function (make sure to get everything after the dash)
38+
39+
![screenshot](https://s3-eu-west-1.amazonaws.com/alx402/AwsCopyArn.png)
40+
41+
--------
42+
43+
### Task 2: Build a Voice UI
44+
1. In a new browser tab go to [developer.amazon.com](https://developer.amazon.com/)
45+
2. On the top right corner Click on "Developer Console" and sign in
46+
3. Click on 'Alexa' in the navigation bar
47+
4. Under 'Alexa Skills Kit' click on the 'Get Started>' button.
48+
5. Click the 'Add a New Skill' button in the top right corner.
49+
6. Leave 'Custom Interaction Model' selected as the skill type
50+
7. Select 'English (US)' from the 'Language' dropdown
51+
8. Set the 'Name' & 'Invocation Name' to `Dynamic Facts`
52+
9. Leave all of the 'Global Fields' set to 'No'
53+
10. Click the 'Save' button at the bottom of the page.
54+
11. Click the yellow 'Next' button.
55+
12. Click the large black 'Launch Skill Builder (beta)' button.
56+
57+
![screenshot](https://s3-eu-west-1.amazonaws.com/alx402/LaunchSkillBuilder.png)
58+
13. In the blue 'Intents' navigation pane click 'Add an Intent'
59+
60+
![screenshot](https://s3-eu-west-1.amazonaws.com/alx402/SkillBuilderAddIntent.png)
61+
62+
14. Under 'Create a new custom intent' type `GetNewFactIntent`
63+
15. Click the 'Create Intent' button
64+
16. In the 'Sample Utterances' field, type the following sentences, hit *enter* after each
65+
1. `We want a fact`
66+
2. `Another fact please`
67+
3. `One more`
68+
69+
![screenshot](https://s3-eu-west-1.amazonaws.com/alx402/AddingUtterances.png)
70+
71+
17. Click on the 'Build Model' button from the top pane
72+
18. Wait for the 'model built' confirmation message (this can take up to 90 seconds.)
73+
19. Click the 'Configuration' button
74+
20. Select the 'AWS Lambda ARN (Amazon Resource Name)' radio button
75+
21. Paste the **ARN you copied in Step 1.23** into the 'Default' Field
76+
1. Leave the checkbox for 'Provide geographical region endpoint' unchecked
77+
22. Leave 'Account Linking' set to 'no' and all the 'Permissions' checkboxes unchecked
78+
![screenshot](https://s3-eu-west-1.amazonaws.com/alx402/FinalDevSkill.png)
79+
23. Click 'Next'
80+
### Verify:
81+
24. Under 'Service Simulator' type `Give me a fact`
82+
25. There will now be a JSON object under the 'Service Response' Field
83+
26. Congrats again :trophy: You have built a simple Alexa Skill
84+
85+
--------
86+
87+
### [Lab 2](/Lab2.md)
88+
89+
--------
90+
91+
### Extra Credit: Use Echosim.io to test your skill
92+
1. Open a new browser tab and navigate to (Echosim.io)[https://echosim.io/]
93+
2. Click the yellow 'Login with Amazon' button
94+
3. Log in with the same credentials you used in [Developer Portal](https://developer.amazon.com/)
95+
1. **Allow your browser to access the microphone**
96+
3. Click and hold the blue 'microphone' button and say `Open Dynamic Facts`
97+
98+
### Extra Credit 2: Use a device with Alexa to test your skill
99+
1. Any device that is configured with the credentials you used for Developer Portal will have access to your skill.

Lab2.md

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
## Lab 2:
2+
### Pre-Requisites
3+
4+
**IMPORTANT: Make sure you are on the 'EU (Ireland)' AWS Region**
5+
6+
The back end hosted as a Lambda function
7+
you built in [Task 1](/Lab1.md#task-1-deploy-code-to-lambda)
8+
9+
--------
10+
11+
### Task 3: Create a DynamoDB for Storing facts
12+
1. In a separate browser tab go to [the Amazon Dynamo DB Dashboard](https://eu-west-1.console.aws.amazon.com/dynamodb)
13+
2. Click on 'Create table'
14+
3. In the 'table name' field type `ALX402FactDB`
15+
4. For 'Partition key' use 'FactId'
16+
1. Leave the type set to 'String'
17+
5. Leave 'Use Default Settings' checked
18+
6. Click the 'Create' button at the bottom of the page. (This can take a couple of minutes.)
19+
7. On the right hand side click on the 'Indexes' tab
20+
8. Click on the 'Create Index' button
21+
9. Type `locale` into the 'Primary key' field
22+
1. Leave the type set to 'String'
23+
2. The index name should have auto populated to 'locale-index'
24+
10. Don't change any of the other settings
25+
11. Click the 'Create Index' button
26+
1. This process will take about 5 minutes
27+
2. The 'Status' will change to 'Active' once it's done
28+
12. Click on the 'Overview' tab
29+
13. Copy the 'Amazon Resource Name (ARN)' for the table, paste it to a text file as we will use it later
30+
1. It is located at the **bottom** of the page
31+
#### Verify: Add an item to the table
32+
14. Click on the 'Items' tab
33+
15. Click the 'Create item' button
34+
16. In the new form that appears, do the following:
35+
1. Type in `0001` for 'FactId'
36+
2. Type in `en-US` for 'locale'
37+
2. Click the '+' button and append a string.
38+
3. Type `speech` for the 'Field' and `Manually added fact` for the 'Value'
39+
4. Click the '+' button and append an additional string.
40+
5. Type `text` for the 'Field' and `Text for manually added fact` for the 'Value'
41+
17. Click 'Save' button
42+
18. You now have a properly formatted item stored in DynamoDB
43+
44+
--------
45+
46+
### Task 4: Modify Lambda to read from the new DynamoDB table
47+
1. In a new tab, navigate to the [AWS Identity Access Management Service](https://console.aws.amazon.com/iam)
48+
2. Click on 'Roles' on the left hand side
49+
3. Click on the **name** 'ALX402-Role'
50+
4. Click 'Attach Policy' button
51+
5. Type `DynamoDBReadOnlyAccess` in the search bar
52+
6. Click on the **checkbox** next to 'AmazonDynamoDBReadOnlyAccess'
53+
7. Click 'Attach Policy' button
54+
8. Go back to the Lambda service and select the function called 'ALX402' (We created it in [Task 1](/Lab1.md#task-1-deploy-code-to-lambda))
55+
9. Replace the 'GetFact' function with the following code:
56+
1. The function should start on line
57+
```javascript
58+
'GetFact': function () {
59+
let requestLocale = this.event.request.locale; //get locale from request for our DB secondary index
60+
let AWS = require('aws-sdk'); //instantiate the aws sdk
61+
let docClient = new AWS.DynamoDB.DocumentClient(); // create a DynamoDB client
62+
let params = { // Parameters object for a query that will return all facts for a locale
63+
TableName : "ALX402FactDB",
64+
IndexName: "locale-index",
65+
KeyConditionExpression: "locale = :v1",
66+
ExpressionAttributeValues: {
67+
":v1": requestLocale
68+
}
69+
};
70+
71+
let dynamoQuery = docClient.query(params).promise();//create the query and wrap in a promise
72+
dynamoQuery.then(fulfilled.bind(this), rejected.bind(this));//execute query asynchronously
73+
74+
function fulfilled(value) {//function for handling a fulfilled promise
75+
console.log(value);
76+
const factArr = value.Items;//array form DynamoDB
77+
const factIndex = Math.floor(Math.random() * factArr.length); //random int bounded by length of array
78+
const randomFact = factArr[factIndex]; //get the item that matches the random number
79+
const speechOutput = randomFact.speech; //get the speech value form the item
80+
const textOutput = randomFact.text; //get the text value form the item
81+
this.emit(':tellWithCard', speechOutput, 'ALX 402', textOutput);//send a response to the alexa service
82+
};
83+
function rejected(reason) {//function for handling a rejected promise
84+
console.log(reason);
85+
this.emit(':tell', "An Error occurred, please check the console log");
86+
};
87+
},
88+
```
89+
#### Verify: Test the code in the lambda console
90+
10. Make sure the 'StartSession' event you created is selected
91+
11. Click on 'Save and Test' on the top right
92+
12. Click the arrow next to 'Details' and review the object being sent back
93+
13. Review the content of the console log
94+
95+
--------
96+
97+
### [Lab 3](/Lab3.md)
98+
99+
--------
100+
101+
### Extra Credit:
102+
1. Remove all the hardcoded facts, but leave the other constants

Lab3.md

+147
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
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

Comments
 (0)