0

I'm a newbie at aws. I wanted to use the comprehend api with python.

I wrote the following python script:

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')

I created an IAM user with administrator access and configured it in my linux console:

(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]:

But there is an error every time I call my python file:

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

Unfortunatley I could not solve this error until now.

This is my first AWS project. Do I need to unlock anything? I would really appreciate any tip how to solve this issue.

Thanks in advance!

Florian Scherl
  • 115
  • 2
  • 5
  • I've not used this service, but the error message indicates AWS support needs to enable it for your account. – jordanm Dec 30 '21 at 17:56

1 Answers1

0

Please ensure that the IAM user/role that you are using has access operation comprehend:DetectSentiment For example look at IAM policy attached to the user whose credentials you are using . The policy should contain something like this -

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