使用AWS CDK创建Lex Bot V2报错:en_US区域缺少回退意图
解决AWS CDK创建Lex Bot V2的fallback intent报错问题
问题描述
使用AWS CDK创建Lex Bot V2时,代码如下:
const bot = new lex.CfnBot(this, "MyLexBot", { name: "MyBot", dataPrivacy: { ChildDirected: false }, idleSessionTtlInSeconds: 300, roleArn: lexRole.roleArn, botLocales: [ { localeId: "en_US", nluConfidenceThreshold: 0, intents: [ { name: "OrderIntent", sampleUtterances: [ { utterance: "hello" }, { utterance: "I want to order" }, { utterance: "Can I place an order?" }, ], fulfillmentCodeHook: { enabled: false }, }, { name: "CustomFallbackIntent", description: "Default fallback intent", parentIntentSignature: "AMAZON.FallbackIntent", fulfillmentCodeHook: { enabled: false }, }, ], }, ],
持续收到报错:
Couldn't import a locale. Locale ‘en_US’ in the zip file doesn't contain a fallback intent. Provide a fallback intent for the locale, then try your request again.
尝试创建不含意图的botLocales,问题依旧。
解决方案
核心修复:标记自定义fallback意图
Lex V2要求每个locale必须有一个明确标记为fallback的意图,你的代码中虽定义了继承AMAZON.FallbackIntent的自定义意图,但未添加isFallback: true属性,导致Lex无法识别它为fallback意图。修改后的代码如下:
const bot = new lex.CfnBot(this, "MyLexBot", { name: "MyBot", dataPrivacy: { ChildDirected: false }, idleSessionTtlInSeconds: 300, roleArn: lexRole.roleArn, botLocales: [ { localeId: "en_US", nluConfidenceThreshold: 0.5, // 建议设置合理阈值,0易引发匹配异常 intents: [ { name: "OrderIntent", sampleUtterances: [ { utterance: "hello" }, { utterance: "I want to order" }, { utterance: "Can I place an order?" }, ], fulfillmentCodeHook: { enabled: false }, }, { name: "CustomFallbackIntent", description: "Default fallback intent", parentIntentSignature: "AMAZON.FallbackIntent", isFallback: true, // 关键:添加此属性标记为fallback意图 fulfillmentCodeHook: { enabled: false }, }, ], }, ], });
额外排查点
- 确保每个bot locale的intents列表中,仅有一个标记为
isFallback: true的意图。 - 检查Lex角色权限,确保拥有配置bot意图的相关权限。
- 若使用旧版CDK,需升级至支持Lex V2
isFallback属性的版本。
内容的提问来源于stack exchange,提问作者ZunX
相关产品推荐
相关产品推荐

