GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||
GeezerVison is showing developer.amazon.com — Host a Custom Skill as an AWS Lambda Function | Alexa Skills Kit Alexa Skills Kit
| Get Started
Skill Types
Skill Development Process
Skill Developer Reference
Host a Custom Skill as an AWS Lambda FunctionThe easiest way to build the cloud-based service for a custom Alexa skill is to use AWS Lambda, an Amazon Web Services (AWS) offering that runs your code only when it's needed and scales automatically, so there is no need to provision or continuously run servers. After you upload the code for your Alexa skill to a Lambda function, Lambda does the rest, executing it in response to Alexa voice interactions and automatically managing the compute resources for you. You can use Alexa-hosted Skills to build your Lambda function in the Alexa developer console. Or, you can store your code and resources yourself. About Lambda functions and custom skillsUsing a Lambda function for your service eliminates some of the complexity around setting up and managing your own endpoint:
AWS Lambda supports code written in several languages, including Node.js, Java, and Python. For some languages, you can edit the code in the inline code editor in the AWS Lambda console. For basic testing, you can invoke your function manually by sending it JSON requests in the Lambda console. For an overview of AWS Lambda, see What Is AWS Lambda? The Lambda function must handle the requests sent to the skill by Alexa. See: Lambda functions for custom skills can be hosted in any AWS Lambda region. See Select the optimal region for your AWS Lambda function to help determine the optimal choice for your skill configuration. Complete the procedures in this section to create a new Lambda function for a custom skill and manage AWS resources yourself. To build your Lambda function for a custom skill in the Alexa developer console, see Create and Manage Alexa-hosted Skills. If you're using the Smart Home API, you use Lambda to create a skill adapter. For details, see Steps to Build Smart Home Add-ons. Select the optimal region for your AWS Lambda functionWhen you create an AWS Lambda function, you are prompted to select a region. In most cases, when you create or modify an AWS Lambda function used by your skill, you should use the commonly recommended region shown in the following table. This choice means you reduce latency between Alexa and your skill service. However, if your skill is using other resources that are hosted in a different region, such as DynamoDB databases, Amazon S3 content, or any external services, it might be best to select the region that is closest to those resources in order to reduce overall latency for your skill, even if that region is different from the recommendation in this table. You can decide whether you should make a tradeoff between the latency for Alexa and your skill service, compared to the latency between your skill service and other hosted resources. Look at the Allowed AWS Lambda Regions to determine which region you want to choose for your AWS Lambda function.
Allowed AWS Lambda RegionsThe list of allowed AWS Lambda regions is listed below. You can use any of these for your AWS Lambda functions if you determine that is the optimal choice for your skill configuration.
Use a template to create your Lambda functionIf you are using the Alexa Skills Kit SDK for Node or Python, you can use a template provided in the AWS Serverless App Repository to create your function. This method automatically creates the resources you need for the function to work with Alexa:
The serverless app repository lets you find applications to deploy. You can think of the "application" in this context as a template for creating a Lambda function. You deploy an application to create the resources associated with the application in an AWS CloudFormation stack. After you deploy the function, you can work with your Lambda function normally. You don't need familiararity with CloudFormation to set up your Lambda function this way. The serverless application repository currently contains applications for the ASK SDK for Node v2 and ASK SDK for Python. If you don't already have an AWS developer account, go to AWS and create an account first. Direct links to recommended Alexa samplesUse one of the following links to open the page for an Alexa sample in the serverless app repository. To use one of these, click the link, then follow the directions in Deploy the application to create your function, later: Search for an Alexa sampleAlternatively, you can search for Alexa samples in the serverless app repository:
Deploy the application to create your function
You can now do any of the following:
Configure AWS SAM for Lambda functionsIf you use AWS Serverless Application Model (SAM) to define and deploy your Lambda function, configure policies that prevent unintended deletion of the function behind your skill endpoint. By default, SAM generates a unique function name with a random suffix. This approach allows SAM to seamlessly replace Lambda functions when needed, such as when you change the package type from Adding SAM retention policies prevents deletion of the Lambda function by CloudFormation stack updates. After CloudFormation creates a replacement function, you can update your skill endpoint with the new function ARN in the Alexa developer console. Until then, your skill continues to use the old function. Alternatively, you can specify a static Configure retention policies for Alexa skillsAdd Copied to clipboard. Copied to clipboard. For details, see DeletionPolicy attribute and UpdateReplacePolicy attribute in the AWS CloudFormation documentation. Create a Lambda function from scratchYou can create a new Lambda function from scratch with the Lambda console. Use this method if you aren't using the ASK SDK for Node v2 or ASK SDK for Python. To create a new Lambda function
You can now do any of the following:
Define a new role for the functionThe role specifies the AWS resources your function can access. To create a new role while configuring your function:
View and edit the code for the Lambda functionTo view and edit the code, click the name of the function under Designer, then scroll down to the Function code section. From here, you can do any of the following, depending on the runtime you selected:
For more about the tools you can use to author your function, see Authoring Code for Your Lambda Function . Connect the Lambda function to your skillTo connect the function with your skill, you need to update the Endpoint field for your skill to the AWS Lambda Amazon Resource Name (ARN) for your function. Tip: Lambda creates a new version of your function each time that you publish the function. You can use the ARN for a specific version, or you can create an alias for a Lambda function version. Use an alias ARN to invoke a different version as you make enhancements to your Lambda function. For more details, see Lambda function aliases.
To connect the Lambda function to your skill
Configure the trigger for a Lambda functionYou must configure at least one trigger for your function to grant Alexa the necessary invocation permissions for your function. When you add the Alexa Skills Kit as a trigger, Amazon recommends that you also enable skill ID verification for the function and provide the skill ID (also called the application ID) for your skill. This means your function can be invoked only if the skill ID in the Alexa Skills Kit request matches the skill ID configured in the trigger. When using skill ID verification, you don't include code to verify that the request is intended for your service. Requests from unverified skills don't invoke your function. Multiple Skills Calling the Same Function
You can configure multiple triggers if you want to invoke the same Lambda function from multiple skills. In this case, each trigger must be configured with a unique skill ID. Note: You may have older Lambda functions that have skill ID verification setup as part of the function's code as described in Verify that the Request is Intended for Your Service. They don't include skill ID verification in the trigger. These functions will continue to work and verify the skill ID when these functions are run. However, Amazon recommends that you update the triggers to include the skill ID to perform the check at invocation. To do so, Remove the old trigger, then add a new trigger with the ID.
Add an Alexa Skills Kit triggerBefore you add the trigger, copy the skill ID from the developer console:
Once you have your skill ID, add the trigger to the function:
It is highly recommended that you limit invocation permissions to just Alexa and enable skill ID verification to protect your function from malicious callers. Tip: If you need to invoke the same function from multiple skills, follow the steps above to add the Alexa Skills Kit trigger multiple times.
Remove an Alexa Skills Kit triggerYou can remove a trigger from your function in the Lambda console. This also removes the skill ID verification for any skill ID included in the trigger.
Change an existing triggerYou can't edit an existing trigger for a Lambda function. To change a trigger (for instance, to add or change the skill ID), remove the old trigger, then add a new trigger. Configure triggers with the AWS CLI or Lambda APIAWS Lambda provides both an API and command line interface (CLI) for managing Lambda functions. You can use these tools to add or remove the Alexa Skills Kit trigger as well. These let you add a resource-based policy granting the Alexa Skills Kit permission to invoke the function.
For the Alexa Skills Kit trigger, you must set the following:
For example, this CLI command adds the trigger to the Lambda function For details about the API and CLI, see AddPermission and add-permission . Triggers added with the API or CLI are displayed in the Lambda console just like all other triggers. Disable Skill ID verificationYou can configure your function to not use skill ID verification if absolutely necessary. For instance, you may want to turn off the verification in an environment in which you have a large number of skills invoking the same function for testing purposes. It is still recommended that you re-enable verification before publishing your skill. To disable skill ID verification in the Lambda console:
To disable skill ID verification with the Lambda API or CLI:
For example, this CLI command adds the trigger to the Lambda function See AWS documentation for details about using the Lambda API or CLI. If you later want to re-enable skill ID verification (recommended before publishing the skill), delete any triggers that don't include the Note: Note that a trigger without the
EventSourceToken overrides triggers that do include this condition. Be sure to delete any triggers without the skill ID when you re-enable skill ID verification.Test a Lambda function in the consoleYou can manually test a Lambda function in the Lambda console by sending sample JSON events formatted in the same way as requests sent by Alexa. Sample events are provided for testing within the console. You can use these events as a starting point and modify them to represent requests that the Alexa service would send to your own function. Note that you can also send events to a Lambda function using the AWS CLI. The Lambda console does not check the conditions on the function's triggers, so your test event does not need to have a matching skill ID when you use skill ID verification. For details about the JSON interface, see Request and Response JSON Reference. To test your function, you need to create a new test event:
You can configure multiple events to test sending different requests to your function. Tip: If you get an error when you test the function, make sure your test event is a valid Alexa request. Make sure you are creating your event from one of the Alexa templates, not a different Lambda template such as "Hello World".
After the function runs, the Execution result section shows the response returned by the function, in JSON format. You should see a response appropriate for the request pasted into the Sample event box. For example, for a The Log output section shows any log messages generated by the code. The sample writes a log message for each type of request, so you should see something like the following:
Tip: You can also test your skill in the developer console. When troubleshooting and debugging, it can be useful to copy the JSON for a request from the Skill I/O: JSON Input field in the developer console into a new test event in the Lambda console. Then you can make changes to the request and see any log messages immediately.
Sample codeThe following sample code demonstrates a basic Hello World skill and other features of the ASK SDK:
Related topics
Was this page helpful?
Last updated: Nov 07, 2025
| |||||||||||||||||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. | |||||||||||||||||||||||||||||||||