In this part, we will deploy our skill and create the AWS Lambda function that powers it. First, you need to update the constants.js file in order to match your setup.
-
./lambda/custom/constants.js
Modify these values in constants.js file : Salesforce instance URL and the name of your Voice Code custom setting and field name. There are other fields here we will modify later, so this won't be the last time you will be edit this file.
Note: You can also control this value via Lambda Environment Variables using the same names shown below.
// Salesforce Constants
INSTANCE_URL: process.env.INSTANCE_URL || '', // TODO Set your own
VOICE_CODE_OBJECT_NAME: process.env.VOICE_CODE_OBJECT_NAME || 'voice_code__c',
VOICE_CODE_FIELD_NAME: process.env.VOICE_CODE_FIELD_NAME || 'code__c',
- If you've deployed the application using the Serverless Application Repository, you simply need to add the function name that was created to one of the configuration files. Skip to Step 4.
- If you wish to deploy the skill function using the AWS Serverless Application Repository, find the application skill-sample-nodejs-salesforce.
- Follow the instructions to deploy the application, setting the required parameter for your Salesforce instance URL based off what you created in Part 1.
- Open your Lambda console.
- Find the function that is named something like this: aws-serverless-repository-AlexaSalesforceFunction-
- Copy the full function name, including the stack name and generated ID at the end.
- Open the
.ask/config
in the root directory of this project. - Modify the value of "uri" to be the function name you copied in step 6.
"apis": {
"custom": {
"endpoint": {
"uri": "ask-custom-AlexaSalesforceDemo-default"
}
}
ASK will create the skill and the lambda function for you. The Lambda function will be created in us-east-1
(Northern Virginia) by default.
If you created the Lambda function already with the Serverless Application Repository deployment process, it will link the function to your skill.
- You deploy the skill and the lambda function in one step :
$ ask deploy
-------------------- Create Skill Project --------------------
ask profile for the deployment: default
Skill Id: amzn1.ask.skill.<Skill ID>
Skill deployment finished.
Model deployment finished.
Lambda deployment finished.
- Make sure to save your skill ID returned in the previous output. We’ll use that often in the future steps.
The standard execution role that is used for Lambda doesn’t allow permission to access DynamoDB. In order to fix that, you need to add a policy to the role that runs the Lambda function.
- From the AWS Console, type IAM in the AWS services search box at the top of the page.
- Click Roles.
- Find the role that was automatically created for this Lambda function. It should be called ask-lambda-Salesforce-Demo. Click on it.
- In the Permissions tab, click Attach policy.
- In the search box, search for AmazonDynamoDBFullAccess and then check the box next to the policy that shows up.
- Click Attach policy at the bottom right.
In order to test the skill before publishing, you need to enable testing on the Alexa Developer Console.
You can directly jump to the page by substituting your Skill ID into the following URL: https://developer.amazon.com/alexa/console/ask/test/<Skill ID>/development/en_US
- Modify the following value in
./lambda/custom/constants.js
file using the skill ID you just obtained. You can also make this chance in the AWS Lambda console as an environment variable.
appId: process.env.SKILL_ID || '',
- Run the deploy command again to update your Lambda function with the latest change.
$ ask deploy