Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

aws s3 cp returns An error occurred (403) when calling the HeadObject operation: Forbidden

Foreword

I guess it may be a duplication but other posts with the same problem didn't help me much.

A problem

aws s3 cp s3://s3-us-west-2.amazonaws.com/my-test-bucket/intro.jpg test.jpg
Outputs the following:
fatal error: An error occurred (403) when calling the HeadObject operation: Forbidden

Bucket Policy:

{
    "Version": "2012-10-17",
    "Id": "Policy1539624480514",
    "Statement": [
        {
            "Sid": "Stmt1539624478431",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:*",
            "Resource": [
                "arn:aws:s3:::my-test-bucket",
                "arn:aws:s3:::my-test-bucket/*"
            ]
        }
    ]
}
Some notes
  1. intro.jpg was added by user A (who has AdministratorAccess) via AWS Console Dashboard (it's not copy file between buckets)
  2. aws sts get-caller-identity returns me information about user A

    {
        "UserId": "AIDXXXX3KDQHYYYYXRLO",
        "Account": "765123991235",
        "Arn": "arn:aws:iam::765123991235:user/[email protected]"
    }
  3. cat ~/.aws/config

[default]
region = us-west-2
output = json
  1. cat ~/.aws/credentials points to user A access key and secret

[default]
aws_access_key_id = AZZZIXXXXJQZA6YYYYUQ
aws_secret_access_key = <<<<<<<<<KEY REMOVED>>>>>>>>
  1. aws s3 ls returns the correct list of buckets
  2. time is synced on my local machine correctly
like image 818
Alexey Kucherenko Avatar asked Oct 15 '18 20:10

Alexey Kucherenko


People also ask

Why am I getting HTTP 403 Forbidden error on AWS S3 bucket?

Verify that the AWS Identity and Access Management (IAM) user or role that you're using has permissions for the s3:PutObject action on the bucket. Without this permission, you get an HTTP 403 Forbidden error.

Why getting an ERROR 403 when calling the headobject operation?

And why getting an error occurred (403) when calling the headobject operation: forbidden First, check whether your attached policy provides complete access to S3 and also to access objects within a S3 bucket, you have to provide this in the policy: The first statement allows complete access to all the objects available in the given S3 bucket.

Why am I getting an HTTP 403 Forbidden error when uploading?

Without this permission, you get an HTTP 403 Forbidden error. If you're trying to modify the object's ACL during the upload, then your IAM user or role must also have permissions for the s3:PutObjectAcl action. To access an S3 bucket that uses default encryption with a custom AWS KMS key, you must have the permissions to use the key.

Can I put objects on the AWS S3 bucket?

Here a bucket policy explicitly denies any access to s3:PutObject on the bucket awsdoc-example-bucket unless the upload request includes encryption with the AWS KMS key arn:aws:kms:us-east-1:111122223333:key: Suppose we use the root user account to upload objects to the S3 bucket.


1 Answers

s3://s3-us-west-2.amazonaws.com/my-test-bucket/intro.jpg refers to a bucket named s3-us-west-2.amazonaws.com and the object key my-test-bucket/intro.jpg.

Access is denied because that isn't your bucket.

The correct URI here would be s3://my-test-bucket/intro.jpg.

like image 195
Michael - sqlbot Avatar answered Sep 26 '22 07:09

Michael - sqlbot