AWS Amplify CLI creates inaccessible bucket for hosting

Viewed 1644

I have got a strange problem with the Amplify CLI. When adding hosting to my angular app through

amplify hosting add

and subsequently calling

amplify publish

the link provided at the end of the process links to a webpage that just shows an XML document telling me the access was denied. What is happening here? It seems to me like the hosting bucket has a wrong policy attached, but why would the amplify CLI create a private bucket?

Can someone shed some light here?

Here is the bucket policy created by the CLI:

{
"Version": "2012-10-17",
"Id": "MyPolicy",
"Statement": [
    {
        "Sid": "APIReadForGetBucketObjects",
        "Effect": "Allow",
        "Principal": {
            "AWS": "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity xxx"
        },
        "Action": "s3:GetObject",
        "Resource": "arn:aws:s3:::xxx/*"
    }
]
}
3 Answers

When using the amplify init command be very careful when passing the path to the project build.

In case of angular projects the default value is dist/{project-name}, so when initializing the amplify to correctly this path, this way:

Distribution Directory Path: dist/{project-name}

If the path is not passed correctly, the access message has been denied it will appear as if everything is working, but in fact it can not find the files.

Finally if even then the error continues to happen here is a reference to other possible reasons for this to be happening.

I just encountered this as well. If I go into the Cloudfront distribution and update the origin to include an Origin Path pointing to the main subdirectory in the S3 bucket (folder is the same name as the Amplify project), the problem appears to be resolved.

I just came across this issue and it ended up being a safety setting in S3. 1. Go to S3 > Public access settings for this account > Untick those

Related