How to access s3 bucket that has public access disabled?

Viewed 27

I have an s3 bucket which is holding some configuration files for a proxy that I am creating. Through terraform, I am creating an ec2 instance which will run the proxy, and in the instance's launch script, I am trying to access the s3 bucket and copy over the desired files.

In the launch script, I am using this command to copy the files aws s3 cp s3://test-bucket/ . --recursive

Currently, in the iam role that I am creating for the instance, I am giving it the following permissions:

    service_policy_document = {
        SID = "LaunchScriptPermissions"
        actions = [
            "s3:GetObject",
            "s3:ListObjects",
            "s3:ListAllMyBuckets",
            "s3:ListBuckets",
        ]
        resources = ["*"]
    }

I am using a module, which is why the permissions are under service_policy_document, but the things under actions are the permissions the instance are given.

When I try to run the script, it fails with the error [ 113.369327] cloud-init[1581]: fatal error: An error occurred (AccessDenied) when calling the ListObjectsV2 operation: Access Denied

Any idea what else needs to be added to fix this?

Thanks! :)

1 Answers

Try replacing s3:ListBuckets with s3:ListBucket. Just remove the s at the end fo the word.

Related