Make sure you've selected the right region
- N.Virginia for English (US) or English (CA) skills
- EU (Ireland) region for English (UK), English (IN), German or French (FR) skills
- US West (Oregon) for Japanese and English (AU) skills.
If you are familiar with Serverless Framework, you can go direct to Deploy via Serverless Framework section. However, it is recommended to follow the manual deployment procedure for the first time.
-
Go to IAM Console, click Create Role
-
Under Choose the service that will use this role, choose Lambda
-
Click Next: Permissions, Next: Tags, Next: Review
-
In the Review page, enter
alexa-lambda-role
for the Role name, and choose Create role -
Click the
alexa-lambda-role
, under Permissions tab, click Add inline policy -
In Create Policy page, select JSON, and copy & paste the following policy. Please remember to replace
<device-table-name>
. Check your DynamoDB table name in DynamoDB Console. If you followed Create a Web Interface to bind Smart Lamp to User, a DynamoDB table has already been created. This policy grant the Lambda to read items from device table and put logs to CloudWatch.
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": [
"*"
],
"Effect": "Allow"
},
{
"Action": [
"dynamodb:Query"
],
"Resource": [
"arn:aws:dynamodb:*:*:table/<device-table-name>/index/ByUsernameThingName"
],
"Effect": "Allow"
},
{
"Action": [
"iot:UpdateThingShadow"
],
"Resource": [
"*"
],
"Effect": "Allow"
}
]
}
-
Go to Lambda Console, click Create function
-
Select Author from scratch, and enter the following information:
- Name: Provide a name for your Lambda function, should be same
- Runtime: To use the sample code provided in this topic, choose Node.js 10.x
- Role: select a role you previously created
-
Click Create Function. Your function should be created and you will move to Configuration
-
In the Configuration designer, under Add triggers select the Alexa Smart Home trigger
-
In the Configure triggers section, add the Skill ID from the developer console in the box specified.
-
Leave Enable trigger checked. This enables the Amazon Alexa service to call your Lambda function. If you don't enable it when you create, you will not be able to enable it in the console later
-
Click Add and then click Save
-
Change directory to
src
-
Edit
config.json
file, you can find these information in AWS Console and Alexa Console -
Run
npm install --production
to install dependencies -
Make a zip file to include
index.js
,auth.js
,config.json
,alexa/
andnode_modules/
, these files/directories should be located at the root level of the zip file -
Go to AWS Lambda Console, click the lambda function
-
Under Function code, click Upload to upload the zip file
All of the above settings in this section including Lambda execution role, permission, code,
Alexa Smart Home SKill can be configured using Serverless Framework.
However, you only need to edit config.json
file and deploy via sls
command.
-
Edit
config.json
file -
Run
npm install
to install dependencies including development dependencies -
Run
sls deploy
After success deployment, you should be able to see a Lambda named
alexa-smarthome-{stage}-backend
.