Deploying Alexa Skill with already created lambda function and role

In this article, we will discuss how to deploy a custom Alexa skill that uses an already created lambda function and role.

When you are working on Alexa skill development and your role is a developer or a DevOps you should use ask-cli to create, manage, and deploy your skill with multiple staging environments.

When we are working with Alexa skill deployment with already created lambda function we are facing issues with custom lambda deployment because when we run ask deploy the command will deploy everything including skill, model, and lambda(backend) but in our case, we already created the AWS Lambda function so we don't need to deploy lambda we just need to integrate it with our skill directly.

So, we just have to deploy skills and models only, and then lambda function separately because we have a separate project directory and deployment process.

There are two cases where we have issues with the already created lambda function.

Let's start our exercise

We already configured ASK-CLI in our previous discussion.

please check the above article if you don't have setup ask-cli on your machine.

→ Deploy existing skills with an already created lambda function.

Let’s Clone our skill using the following command:

ask init --hosted-skill-id <skill-id> -p <profile>

Output:

It will create a new project directory with your skill name.

cd <Created-Skill-Name>

> Now we have to Remove the lambda deployment configuration from our skill project.

To remove the lambda function configuration for doing the first deployment, we must configure ask-resource.json and .ask/ask-states.json files in a specific way

1. Let’s reinitialize the skill project and remove the lambda configuration.

Run the following command in the created project directory

ask init -p <profile>

This command asks some questions about skill deployment.

? ask-resources.json already exists in the current directory. Do you want to overwrite it?  Yes
? Skill Id (leave empty to create one):  amzn1.ask.skill.94f84b4a-tr50-4ac6-8tr4-788zz02g7a55
? Skill package path:  ./skill-package
? Lambda code path for default region (leave empty to not deploy Lambda):

Output:

It will also update both files and remove the AWS lambda configurations.

2. Let’s remove lambda configuration manually

Note: Use this if you want to remove lambda configuration manually instead ofask init command.

Open ask-resource.json and remove the lambda configuration block.

Originally:

New Code:

{
"askcliResourcesVersion": "2020-03-31",
"profiles": {
"<AKS-PROFILE-NAME>": {
"skillMetadata": {
"src": "./skill-package"
}
}
}
}

After that go to.aks/ and open ask-states.jsonfile and remove the lambda configuration block.

Originally:

New Code:

{
"askcliStatesVersion": "2020-03-31",
"profiles": {
"<AKS-PROFILE-NAME>": {
"skillId": "<CREATED-SKILL-ID>"
}
}
}

Now Run ask deploy to deploy skills and models only.

Output:

==================== Deploy Skill Metadata ====================    
- Uploading the entire skill package (it may take few minutes to build the skill metadata)...
Skill package deployed successfully.
Skill ID: <Alexa_Skill_ID>
==================== Enable Skill ====================
Skill is already enabled, skip the enable process.

Note: When we run ask deploy make sure we have added our Alexa skill id in lambda function trigger otherwise it will return an error.

The trigger setting for the Lambda arn:aws:lambda:us-east-”function” is invalid. Error code: SkillManifestError

→Create new skills and Deploy with an already created lambda function.

Let’s create a new skill project using the following command.

ask new -p <profile>

It will ask some questions about skill configurations.

? Please type in your skill name:
? Please type in your folder name for the skill project (alphanumeric):

Output:

Project for skill "<Skill-Name>" is successfully created at <FOLDER-PATH>/<PROJECT-NAME>The Project was initialized successfully.

Now Our skill initialized successfully.

> Remove the lambda configuration.

When skill initialized it will create an ask-resources.json file like

But we have to remove lambda section like

Now Let’s deploy our created skill with --target argument.

ask deploy --target skill-metadata -p <profile>

Output:

==================== Deploy Skill Metadata ====================
Skill package deployed successfully.
Skill ID: <CREATED-SKILL-ID>

> Add the lambda configuration in skill.json.

We get Skill id in the above step. Now we have to that skill id to lambda function trigger with Alexa Skill Kit.

After that add lambda configuration in the skill-package/skill.json file.

"manifest": {
"apis": {
"custom": {
"endpoint": {
"uri": "<AWS-LAMBDA-ARN>"
},
"interfaces": [],
"regions": {
"NA": {
"endpoint": {
"uri": "<AWS-LAMBDA-ARN>"
}
},
"EU": {
"endpoint": {
"uri": "<AWS-LAMBDA-ARN>"
}
},
"FE": {
"endpoint": {
"uri": "<AWS-LAMBDA-ARN>"
}
}
}
}
}
"manifestVersion": "1.0",
"permissions": [
{
. . . . . .
. . . . .
}

Now Let’s redeploy our created skill.

ask deploy -p <profile>

Output:

==================== Deploy Skill Metadata ====================    - Uploading the entire skill package (it may take few minutes to build the skill metadata)...    Skill package deployed successfully.    Skill ID: amzn1.ask.skill.3ab5dc2b-9d46-476c-86d1-ae81489fb86c        ==================== Enable Skill ====================    Skill is already enabled, skip the enable process.

🎊 🎉🤖🎊 🎉 We deployed our skill with the already created lambda function.

In my next article, we will see how we can create an automatic deployment pipeline for our Alexa skill.

Thank you for reading, if you have anything to add please send a response or add a note!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Prashant Bhatasana

AWS Community Builder | Terraform Associate | Infra. Automation Engineer, Love to work with #AWS #Terraform #Jenkins #kubernetes #Docker #Ansible #Selenium