• Uncategorized

About python : AWS-Comprehend—NotAuthorizedException

Question Detail

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!

Question Answer

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": "*"
      }
   ]
}

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.