`botocore.exceptions.ClientError: An error occurred (UnauthorizedOperation) when calling the DescribeInstances operation: You are not authorized to perform this operation.`
BeginnerTroubleshootingboto3, HTTP & API errors
Answer
Likely causes → The identity lacks ec2:DescribeInstances, an SCP or permission boundary denies it, or you are in the wrong account/role.
Diagnose →
aws sts get-caller-identity
aws iam simulate-principal-policy --policy-source-arn <role-arn> --action-names ec2:DescribeInstances
For EC2 write calls the message includes an encoded authorization message: aws sts decode-authorization-message --encoded-message <msg>.
Fix → Add the permission to the role (least privilege), or switch to the correct role.
Prevent → Keep the tool's IAM policy in code next to the tool; test with a sandbox role.
More on boto3, HTTP & API errors
`botocore.exceptions.NoCredentialsError: Unable to locate credentials`Beginner`botocore.exceptions.NoRegionError: You must specify a region.` even though `AWS_REGION` is set.Intermediate`An error occurred (ExpiredToken) when calling the ... operation: The security token included in the request is expired` midway through a long job.Advanced`An error occurred (RequestLimitExceeded) when calling the DescribeInstances operation (reached max retries: 4): Request limit exceeded.`Intermediate`An error occurred (InvalidClientTokenId) when calling the GetCallerIdentity operation: The security token included in the request is invalid.`Beginner`An error occurred (SignatureDoesNotMatch)` or `RequestTimeTooSkewed` from AWS.Intermediate