AWS CodeBuild script fails s3 sync with AccessDenied

Adding the following to the CodeBuild generated role worked for me:

{
    "Effect": "Allow",
    "Resource": [
        "arn:aws:s3:::mytestbucket",
        "arn:aws:s3:::mytestbucket/*"
    ],
    "Action": [
        "s3:PutObject",
        "s3:Get*",
        "s3:List*"
    ]
}

I had this same error and tried everything in this thread. I was trying to do

aws s3 sync ./build s3://s3-us-east-1.amazonaws.com/some-amazing-s3-bucket

from a Codebuild action, but the S3 response was always

fatal error: An error occurred (AccessDenied) when calling the ListObjects operation: Access Denied

even when I did it from the aws-cli on my laptop (with admin access keys).

It took me several hours to realize that the actual s3 url is supposed to be written like this:

s3://some-amazing-s3-bucket

instead of

s3://s3-us-east-1.amazonaws.com/some-amazing-s3-bucket

That being said, a policy like tedsmitt's has to be attached to the (in my case) codebuild role too.

Hope this helps someone.