This Alexa Skill provides users the ability to get flash briefings on Company's KPI's. The Skill demonstrates how to use AWS Lambda and SNS to enable Voice + SMS based Authentication within a Skill. You will also learn to Publish this Skill as a Private skill to an Alexa for Business account rather than the public Alexa Skills Store.
This demo assumes you have your developer environment ready to go and that you have some familiarity with CLI (Command Line Interface)Tools, AWS, and the ASK Developer Portal.
Clone the repository.
$ git clone https://github.com/aws-samples/alexa-skill-authentication
If it's your first time using it, initiatialize the ASK CLI by navigating into the repository and running ask command: ask init
. Follow the prompts. This will initialize credentials profile and help you configure credentials to access Alexa Skills Kit Developer Console and the AWS Console.
$ cd alexa-skill-authentication
$ ask init
Install npm dependencies by navigating into the /lambda/custom
directory and running the npm command: npm install
$ cd lambda/custom
$ npm install
Deploy the skill by running the following command in the alexa-skill-authentication
folder.
$ ask deploy
The Skill would be deployed. Ignore any errors related to enabling the skill. You will Enable it in the subsequent steps. Make a note of the Skill Id as shown in the output below.
Skill Id: amzn1.ask.skill.fede81a9-09a7-4b46-85f3-1fea4a96f
Skill deployment finished.
Model deployment finished.
[Info]: No lambda functions need to be deployed.
[Info]: No in-skill product to be deployed.
In the root directory alexa-skill-authentication
, you should see a file named 'deploy-lambda.sh'. This will let you deploy the Skill's backend code as a Lambda function. Ensure you edit this file to replace the name of the S3 bucket as found in your AWS account.
Deploy the lambda function by executing the deploy-lambda.sh
file (Change permissions of this file by executing the command chmod +x deploy-lambda.sh
if need be.). Make note of the name of the Lambda function and its ARN. You will need it in subsequent steps.
Configure the Alexa Skill Kit as a Trigger to the Lambda function by running this command.
$ aws lambda add-permission \
--function-name LAMBDA_FUNCTION_NAME \
--statement-id 123 \
--action lambda:InvokeFunction \
--principal alexa-appkit.amazon.com \
--event-source-token SKILL_ID
Note: Replace the LAMBDA_FUNCTION_NAME and SKILL_ID values appropriately.
In the root directory alexa-skill-authentication
, edit the skill_final.json
by replacing the ARN of the Lambda function created in Step 3. Look for the place holder LAMBDA_ARN in this file.
Replace the contents of the skill.json
with the contents in skill_final.json
.
Re-deploy the skill by running the following command.
$ ask deploy --force
The Skill should be deployed and linked to the Lambda function.
Skill Id: amzn1.ask.skill.fede81a9-09a7-4b46-85f3-1fea4a96f
Skill deployment finished.
Model deployment finished.
[Info]: No lambda functions need to be deployed.
[Info]: No in-skill product to be deployed.
Your skill is now deployed and enabled in the development stage. Try simulate your Alexa skill skill using "ask dialog" command.
Test the Skill. Refer to Testing the Skill
section for Instructions on testing the skill.
Submit the skill. The submission process is similar to certification for public skills. Just issue the following command:
ask api submit -s SKILL_ID
Note: Replace the value of SKILL_ID.
This submission process may take about 90 minutes to complete and once completed the skill will be available in the live stage.
Ensure that the Skill's Status is Live
before executing this step. The final step is to distribute the skill to an Alexa for Business organization. To do this, you’ll need the ARN of the AWS account for the organization which you want to deploy the skill. Then enter the following command:
$ ask api add-private-distribution-account -s SKILL_ID --stage live --account-id <id>
For example
ask api add-private-distribution-account -s amzn1.ask.skill.fede81a9-09a7-4b46-85f3-1fea4a96f --stage live --account-id arn:aws:iam::1234567890:root
Invoke the Skill by saying "Alexa, Open Business Insights"
Then ask "How is the Net profit Margin?". Alexa will respond with "Your mobile number is not registered with this device. Please contact the skill administrator."
You will need to locate the DeviceId and map it to your Mobile Number in a DynamoDB Table.
To locate the DeviceId, login to the AWS Management Console. Choose Lambda and click on Functions in the left navigation pane. Locate the Lambda function configured with this Skill.
Choose the Lambda function and click on the Monitoring tab.
Click on View logs in CloudWatch and click on the first "Log Stream".
Look for the DeviceId in the logs. It starts with the prefix "amzn1.ask.device.". Note this DeviceId.
Navigate to DynamoDB in the AWS Management Console.
Choose Tables in the left navigation pane.
Locate the DeviceContactMapping table and click on CreateItem.
Add the value of DeviceId into the Id Attribute and also add a new attribute called PhoneNumber. Enter your Mobile Number starting with the CountryCode.Click on Save to save this Item.
Invoke the Skill by saying "Alexa, Open Business Insights"
Then ask "How is the Net profit Margin?".
The Alexa Skill will send a 4 Digit PIN via SMS. The Skill will prompt you to Utter the 4 Digit PIN.
Provide a valid PIN and Alexa should now respond with the KPI Information.
This library is licensed under the Amazon Software License.