是的,可以将一个Alexa技能绑定在多个Lambda函数上。这可以通过使用Alexa技能开发工具包(ASK)的多集成点(Multi-Endpoint)功能来实现。
下面是一个使用ASK CLI v2创建的Alexa技能,并将其绑定到两个Lambda函数的示例:
首先,创建两个Lambda函数:
Lambda函数1代码:
exports.handler = async (event) => {
const response = {
statusCode: 200,
body: JSON.stringify('Hello from Lambda Function 1!'),
};
return response;
};
Lambda函数2代码:
exports.handler = async (event) => {
const response = {
statusCode: 200,
body: JSON.stringify('Hello from Lambda Function 2!'),
};
return response;
};
接下来,使用ASK CLI v2创建一个新的Alexa技能:
ask new
? Choose a skill template: Custom -> Start from scratch
? Choose a default language for your skill: (e.g. en-US, en-GB, de-DE, etc.): en-US
? Choose a name for your skill: My Skill
然后,将该技能配置为使用多个集成点:
cd my-skill
ask api create-endpoint-configuration --skill-id [SKILL_ID] --region default --endpoint-default --endpoint-uri arn:aws:lambda:us-east-1:123456789012:function:lambda-function-1 --endpoint-type PROD
ask api create-endpoint-configuration --skill-id [SKILL_ID] --region default --endpoint-default --endpoint-uri arn:aws:lambda:us-east-1:123456789012:function:lambda-function-2 --endpoint-type DEV
最后,将“Hello world”意图与两个Lambda函数关联:
ask add -t intent -f HelloWorldIntent -s my-skill/models/en-US.json
? Choose an intent type: Custom Intent
? Enter an intent name: HelloWorldIntent
? Would you like to add some sample utterances to this intent?