`An error occurred (AccessDenied) when calling the PutObject operation: Access Denied` although the IAM policy allows `s3:PutObject`.
AdvancedTroubleshootingboto3, HTTP & API errors
Answer
Likely causes → Something else denies: the bucket policy (for example requiring aws:kms encryption or TLS), SSE-KMS key policy missing kms:GenerateDataKey for your role, an SCP, a VPC endpoint policy, or Object Ownership/ACL settings when passing ACL=.
Diagnose →
aws s3api get-bucket-policy --bucket b | jq -r .Policy | jq .
aws s3api get-bucket-encryption --bucket b
Check CloudTrail for the denied event and its errorMessage.
Fix → Add the required headers (ServerSideEncryption="aws:kms", SSEKMSKeyId=...), grant KMS permissions, or adjust the bucket policy.
Prevent → Document bucket requirements; test uploads with the real role in staging.
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`botocore.exceptions.ClientError: An error occurred (UnauthorizedOperation) when calling the DescribeInstances operation: You are not authorized to perform this operation.`Beginner`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