Interview Prep/Python for DevOps/boto3, HTTP & API errors

`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.

All Python for DevOps questions Roadmap: Python for automation

More on boto3, HTTP & API errors