AWS Comprehend - NotAuthorizedException

问题描述 投票:0回答:2

我是 aws 的新手。我想将 comprehend api 与 python 一起使用。

我编写了以下Python脚本:

import boto3
import json

comprehend = boto3.client(service_name='comprehend')
                
text = "It is raining today in Seattle"

print('Calling DetectSentiment')
sentiment_output=comprehend.detect_sentiment(Text=text, LanguageCode='en')
print('End of DetectSentiment\n')

我创建了一个具有管理员访问权限的 IAM 用户,并在我的 Linux 控制台中对其进行了配置:

(base) florian@florian3090:~/Desktop/aws$ aws configure
AWS Access Key ID [****************BIP6]:
AWS Secret Access Key [****************a/1f]:
Default region name [us-west-1]:
Default output format [json]:

但是每次调用我的python文件时都会出现错误:

botocore.exceptions.ClientError: An error occurred (NotAuthorizedException) when calling the DetectSentiment operation: Your account is not authorized to make this call.

不幸的是,直到现在我都无法解决这个错误。

这是我的第一个 AWS 项目。我需要解锁什么吗? 我真的很感激任何如何解决这个问题的提示。

提前致谢!

python linux amazon-web-services aws-cli amazon-comprehend
2个回答
0
投票

请确保您使用的 IAM 用户/角色具有访问操作权限

comprehend:DetectSentiment
例如,查看附加到您正在使用其凭证的用户的 IAM 策略。该政策应该包含这样的内容 -

{
   "Version": "2012-10-17",
   "Statement": [{
      "Sid": "AllowSentimentDetect",
      "Effect": "Allow",
      "Action": [
                "comprehend:DetectSentiment"
             ],   
      "Resource": "*"
      }
   ]
}

0
投票

检查您是否在受支持的区域之一使用 Comprehend (https://aws.amazon.com/about-aws/global-infrastruct/regional-product-services/)。如果您在不受支持的地区使用它,它将返回该帐户未授权错误

© www.soinside.com 2019 - 2024. All rights reserved.