AWS Alexa Smart Home Skill: create lambda and manage security – 3

Spread the love

In this article we are going to create a new AWS Lambda function that will handle the Smart Home directives from Alexa.

Amazon AWS Smart Home Skill setup and security of a lambda function
Amazon AWS Smart Home Skill setup and security of a lambda function

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

Alexa Skill Smarthome: Create policy lambda en
Alexa Skill Smarthome: Create policy lambda en
  1. 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)
  2. Click the Create policy button.
  3. 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": "*"
        }
    ]
}
  1. Click the Review policy button.
  2. In the Review policy section, set the Name of the policy to skill-esp8266-nodejs-smarthome-switch-policy.
  3. Click the Create policy button to create the policy.

Create a Lambda Execution Role

Alexa Skill Smarthome: Create role for our lambda
Alexa Skill Smarthome: Create role for our lambda
  1. 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)
  2. Click the Create Role button.
  3. On the Create role page, select AWS Service for the type of trusted entity and then select Lambda from the list of services.
  4. Click the Next: Permissions button.
  5. When prompted to Attach permissions policies, filter and find the previously create skill-esp8266-nodejs-smarthome-switch-policy policy and select its check box.
  6. Don’t do nothing here. Click the Next: Review button.
  7. In the Review/Verifica section, set the Role name to lambda-skill-esp8266-nodejs-smarthome-switch-role.
  8. Click Create role to create the execution role.

Create a Lambda Function

Alexa Skill Smarthome: Create function lambda
Alexa Skill Smarthome: Create function lambda
  1. 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)
  2. Verify you are in N. Virginia (us-east-1) for North America or Ireland (eu-west-1) for Europe .
  3. Click on the Create function button to start creating an AWS Lambda function.
  4. On the Create function/Crea funzione page, select the Author from scratch option.
  5. For the Name of the function, enter lambda-skill-esp8266-nodejs-smarthome-switch.
  6. For the Runtime, select Node.js 12.x.
  7. Choose an existing role and select lambda-skill-esp8266-nodejs-smarthome-switch-role from the Existing Role options.
  8. Click the Create function button to create the AWS Lambda function.
  9. 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

Alexa Skill Smarthome: Add trigger to lambda
Alexa Skill Smarthome: Add trigger to lambda
  1. 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 to 
    https://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.
  2. Now click Add trigger, in this new page click Trigger configuration selector, and select Alexa Smart Home from the menu.
  3. 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
  4. Verify Enable trigger checkbox is checked and then click Add.
Alexa Skill Smarthome: Alexa Skill Select SkillID
Alexa Skill Smarthome: Alexa Skill Select SkillID

Thanks

  1. AWS Alexa Smart Home Skill: introduction and startup
  2. AWS Alexa Smart Home Skill: create the skill manage the security
  3. AWS Alexa Smart Home Skill: create lambda and manage security
  4. AWS Alexa Smart Home Skill: configure lambda for the skill
  5. AWS Alexa Smart Home Skill: setup the DynamoDB database
  6. AWS Alexa Smart Home Skill: load sample code and test Lambda
  7. AWS Alexa Smart Home Skill: test your skill in dev and manage log

Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *