[英]Unable to access AWS Lex From Lambda
我正在尝试从 lambda function 访问 amazon lex。Lambda function 将输入消息从聊天机器人发送到 lex。 当我尝试发送文本时,它给我一个错误。
errorMessage: "An error occurred (AccessDeniedException) when calling the RecognizeText operation: User: arn:aws:sts::524709025091:assumed-role/LF0-role-0nuz6ho1/LF0 is not authorized to perform: lex:RecognizeText on resource: arn:aws:lex:us-east-1:524709025091:bot-alias/1TN1TWNYYG/TSTALIASID because no identity-based policy allows the lex:RecognizeText action"
errorType: "AccessDeniedException"
requestId: "45ee975b-ecfa-4823-837b-790cdd908a5b"
我的lambda function中的代码:
import json
import random
import boto3
def lambda_handler(event, context):
responsemsg = ''
for msg in event['messages']:
responsemsg += msg['unstructured']['text']
session = boto3.Session()
client = boto3.client('lexv2-runtime')
response = client.recognize_text(
botId='****',
botAliasId='****',
localeId='en_US',
sessionId="test_session",
text='hi')
return response
用户:arn:aws:sts::524709025091:assumed-role/LF0-role-0nuz6ho1/LF0 无权执行:lex:RecognizeText
这意味着您的 Lambda 承担执行的角色没有执行lex:RecognizeText
的权限。
您可以:
创建一个内联策略,在 Lambda 执行角色上授予对lex:RecogniseText
的访问权限
如果您还需要访问其他常见的 Lex API,请将 AWS 托管的AmazonLexRunBotsOnly
策略附加到该角色
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.