AWS S3 Bucket giving 'policies must be valid JSON and the first byte must be '{'
Asked Answered
H

3

15
    { 
"Id": "Policy1590051531320", 
"Version": "2012-10-17",
"Statement": [ 
{ "Sid": "Stmt1590051522178", 
"Action": [ "s3:GetObject", 
"s3:GetObjectVersion", 
"s3:PutObject", 
"s3:AbortMultipartUpload", 
"s3:ListMultipartUploadParts", 
"s3:GetBucketVersioning", 
"s3:ListBucket", 
"s3:GetBucketLocation", 
"s3:ListBucketMultipartUploads", 
"s3:ListBucketVersions" ], 
"Effect": "Allow", 
"Resource": ["arn:aws:s3:::lakefs", "arn:aws:s3:::lakefs/backend.txt/*"], 
"Principal": {"AWS": ["arn:aws:iam::REDACTED:user/uing"]
 } 
} 
] 
}

This my s3 bucket policy, but it's returning a 'Policies must be valid JSON and the first byte must be '{'. I have the correct bucket name, and bucket name with path prefix in my resource field. Any idea why I am getting this error?

Hexahedron answered 12/10, 2021 at 2:47 Comment(0)
I
8

[lakeFS dev here, but this is an AWS issue]

As the error message says, it wants you to start your policy with a { (and no preceding whitespace).

Note that S3 separates resource-based policies (like this one) from identity-based policies, which you would set up on the IAM service. There are important differences. Often identity-based policies are easier to set up than resource-based policies: the error messages are easier to read, the web-based UI can be friendlier (and offers online error reporting for JSON policies, or a reasonably nice visual policy editor), etc.

Ind answered 15/10, 2021 at 6:30 Comment(1)
That's 1hr of my life wasted. Thank you @IndRetarder
T
26

You can't have these spaces { at the beginning. It should be:

{ 
"Id": "Policy1590051531320", 
"Version": "2012-10-17",
"Statement": [ 
{ "Sid": "Stmt1590051522178", 
"Action": [ "s3:GetObject", 
"s3:GetObjectVersion", 
"s3:PutObject", 
"s3:AbortMultipartUpload", 
"s3:ListMultipartUploadParts", 
"s3:GetBucketVersioning", 
"s3:ListBucket", 
"s3:GetBucketLocation", 
"s3:ListBucketMultipartUploads", 
"s3:ListBucketVersions" ], 
"Effect": "Allow", 
"Resource": ["arn:aws:s3:::lakefs", "arn:aws:s3:::lakefs/backend.txt/*"], 
"Principal": {"AWS": ["arn:aws:iam::172787983831:user/uing"]
 } 
} 
] 
}
Tarboosh answered 12/10, 2021 at 2:52 Comment(0)
I
8

[lakeFS dev here, but this is an AWS issue]

As the error message says, it wants you to start your policy with a { (and no preceding whitespace).

Note that S3 separates resource-based policies (like this one) from identity-based policies, which you would set up on the IAM service. There are important differences. Often identity-based policies are easier to set up than resource-based policies: the error messages are easier to read, the web-based UI can be friendlier (and offers online error reporting for JSON policies, or a reasonably nice visual policy editor), etc.

Ind answered 15/10, 2021 at 6:30 Comment(1)
That's 1hr of my life wasted. Thank you @IndRetarder
J
2

there is an unsuspected one space bar behind the { , all you have to do is get your cursor to its back and press a backspace to get rid of the space and you will be good. Took me almost 12 hours to figure it out.

Juliettajuliette answered 28/8, 2022 at 18:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.