-1

ClientError:

An error occurred (AllAccessDisabled) when calling the GetObject operation: All access to this object has been disabled

My code is:

s3resource = boto3.resource('s3')
my_bucket = s3.Bucket(bucket_name)
s3client = boto3.client('s3')
for s3_object in my_bucket.objects.all():
    path, file1 = os.path.split(s3_object.key)
    obj = s3client.get_object(Bucket='bucket_name',Key=file1)
    j = json.loads(obj['Body'].read())

And the bucket policy is:

{
    "Version": "2012-10-17",
    "Id": "Policy1559802940321",
    "Statement": [
        {
            "Sid": "Stmt1559802821882",
            "Effect": "Allow",
            "Principal": {
                "Service": "cloudtrail.amazonaws.com"
            },
            "Action": "s3:*",
            "Resource": "arn:aws:s3:::bucketname"
        }
    ]
}
Gerald Schneider
  • 19,757
  • 8
  • 52
  • 79

1 Answers1

0

Check this line:

s3client.get_object(Bucket='bucket_name',Key=file1)

If your code really says 'bucket_name' here then this is the cause of your error. That is a string literal, not a variable, so you need to remove those ' quotes:

s3client.get_object(Bucket=bucket_name,Key=file1)

Why this error?

There actually is a bucket somewhere in Amazon S3 named bucket_name and it has been administratively locked by AWS -- which is what causes the AllAccessDisabled error message -- and it appears that you may be trying to access it. There are only two things that cause that specific error -- accessing a locked bucket belonging to someone else, or not paying your AWS bill, which of course results in your own bucket being locked, and presumably not the case, here. You appear to be, inadvertently, trying to access that bucket.

Michael - sqlbot
  • 21,988
  • 1
  • 57
  • 81