AWS Alexa Smart Home Skill: create lambda and manage security – 3
In this article we are going to create a new AWS Lambda function that will handle the Smart Home directives from Alexa.
Select correct region
It’s very important for prevent error or similar select the correct region where develop and host your resources.
- For North America, the default region is
us-east-1
- For Europe, which I choose, is
eu-west-1
Pay attention if you select a region not supported by your Alexa device when we are going to test on the device your skill will not work.
To support all device you must release lambda in multiple region.
Create a Policy for the Lambda Function
- Navigate to the IAM Management Console policies at (policies are global so not so relevant the url)
https://console.aws.amazon.com/iam/home?region=us-east-1#/policies (North America)
https://console.aws.amazon.com/iam/home?region=eu-west-1#/policies (Europe) - Click the Create policy button.
- Select the JSON tab and then copy & paste the following policy into the text area:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogStream",
"dynamodb:UpdateItem",
"dynamodb:GetRecords",
"dynamodb:GetShardIterator",
"dynamodb:DescribeStream",
"dynamodb:ListStreams",
"logs:CreateLogGroup",
"logs:PutLogEvents"
],
"Resource": "*"
}
]
}
- Click the Review policy button.
- In the Review policy section, set the Name of the policy to
skill-esp8266-nodejs-smarthome-switch-policy
. - Click the Create policy button to create the policy.
Create a Lambda Execution Role
- Navigate to the IAM Management Console roles at
https://us-east-1.console.aws.amazon.com/iam/home?region=us-east-1#/roles (North America)
https://eu-west-1.console.aws.amazon.com/iam/home?region=eu-west-1#/roles (Europe) - Click the Create Role button.
- On the Create role page, select AWS Service for the type of trusted entity and then select Lambda from the list of services.
- Click the Next: Permissions button.
- When prompted to Attach permissions policies, filter and find the previously create skill-esp8266-nodejs-smarthome-switch-policy policy and select its check box.
- Don’t do nothing here. Click the Next: Review button.
- In the Review/Verifica section, set the Role name to
lambda-skill-esp8266-nodejs-smarthome-switch-role
. - Click Create role to create the execution role.
Create a Lambda Function
- Navigate to the AWS Lambda console at
https://us-east-1.console.aws.amazon.com/lambda/home?region=us-east-1 (North America)
https://eu-west-1.console.aws.amazon.com/lambda/home?region=eu-west-1 (Europe) - Verify you are in N. Virginia (us-east-1) for North America or Ireland (eu-west-1) for Europe .
- Click on the Create function button to start creating an AWS Lambda function.
- On the Create function/Crea funzione page, select the Author from scratch option.
- For the Name of the function, enter lambda-
skill-esp8266-nodejs-smarthome-switch
. - For the Runtime, select Node.js 12.x.
- Choose an existing role and select lambda-skill-esp8266-nodejs-smarthome-switch-role from the Existing Role options.
- Click the Create function button to create the AWS Lambda function.
- From the Lambda function page, copy the ARN from the top right of the page and save it into the
setup.txt
file in the [AWS Lambda ARN] section. The ARN should look something like:arn:aws:lambda:eu-west-1:XXXXXXXXXXXX:function:lambda-skill-esp8266-nodejs-smarthome-switch
Add a Smart Home Trigger to the Lambda Function
- On the Lambda function page for
lambda-skill-esp8266-nodejs-smarthome-switch
, select the Lastest/Più recente alias then Lastest configuration/Configurazione più recente. Optionally, you can browse tohttps://us-east-1.console.aws.amazon.com/lambda/home?region=us-east-1#/functions/lambda-skill-esp8266-nodejs-smarthome-switch/latest?newFunction=true&tab=configure
(North America)https://eu-west-1.console.aws.amazon.com/lambda/home?region=eu-west-1#/functions/lambda-skill-esp8266-nodejs-smarthome-switch/latest?newFunction=true&tab=configure
(Europe)
Note the Triggers section on the left menu. This part of the designer allows you to add triggers to your Lambda function. - Now click Add trigger, in this new page click Trigger configuration selector, and select Alexa Smart Home from the menu.
- In the Application ID input paste the Alexa Skill Application ID value from the setup.txt file [Alexa Skill Application ID] section into the Application ID text box. The Alexa Skill Application ID should look something like:
amzn1.ask.skill.XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
- Verify Enable trigger checkbox is checked and then click Add.
Thanks
- AWS Alexa Smart Home Skill: introduction and startup
- AWS Alexa Smart Home Skill: create the skill manage the security
- AWS Alexa Smart Home Skill: create lambda and manage security
- AWS Alexa Smart Home Skill: configure lambda for the skill
- AWS Alexa Smart Home Skill: setup the DynamoDB database
- AWS Alexa Smart Home Skill: load sample code and test Lambda
- AWS Alexa Smart Home Skill: test your skill in dev and manage log