Step 2 - Provisioning Lambda (AWS CLI)

Go through the following steps to deploy and invoke the lambda. Refer to previous recipes or code files if you need more details on any of the steps. You can also follow Your first Lambda with AWS CLI recipe in Chapter 1Getting Started with Serverless Computing on AWS and use CloudFormation for Lambda provisioning:

  1. Run mvn clean package from inside the Lambda project root folder to create the Uber JAR.
  2. Upload the Uber JAR to S3.
  3. Create a role called lambda-alexa-simple-intro-role for the lambda, with an appropriate trust relationship definition.
  4. Create a policy for basic logging permissions and attach it to the role.
  5. Create the lambda function as follows:
aws lambda create-function 
--function-name lambda-alexa-simple-intro
--runtime java8
--role arn:aws:iam::<account id>:role/lambda-alexa-simple-intro-role
--handler tech.heartin.books.serverlesscookbook.SelfIntroStreamHandler::handleRequest
--code S3Bucket=serverless-cookbook,S3Key=lambda-alexa-simple-intro-0.0.1-SNAPSHOT.jar
--timeout 15
--memory-size 512
--region us-east-1
--profile admin
  1. Give permission for the Alexa skill to invoke this Lambda as follows:
aws lambda add-permission 
--function-name lambda-alexa-simple-intro
--statement-id "12345"
--action "lambda:InvokeFunction"
--principal "alexa-appkit.amazon.com"
--region us-east-1
--profile admin

We have given permission to any Alexa skill to invoke this lambda. Once you create a skill, you can remove this lambda and add a permission that allows only a particular skill to invoke this lambda, as shown in the following code:

aws lambda remove-permission 
--function-name lambda-alexa-simple-intro
--statement-id "12345"
--region us-east-1
--profile admin

aws lambda add-permission
--function-name lambda-alexa-simple-intro
--statement-id "12345"
--action "lambda:InvokeFunction"
--principal "alexa-appkit.amazon.com"
--event-source-token <skill id from lambda>
--region us-east-1
--profile admin
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.93.141