0

I have an amazon workmail email address setup to automatically forward email to an s3 bucket. I then have a php file that grabs the raw email file from the s3 bucket and then delete it (every 2 minutes).

Anyway my issue is I have the s3 bucket set to public access. however when an object is placed in the bucket it is not automatically given a permission level of public access. So I think i did something wrong??

I am using the Amazon pkp SDK to connect to the bucket with an IAM_KEY and IAM_SECRET . However i am finding that I still have to manually make the objects in the bucket public in order to access them??

Here is my aws sdk code

 //Include the AWS SDK using the Composer autoloader.
require 'awssdk/aws-autoloader.php';

use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;
// AWS Info
$bucketName = 'pipedemail';
$IAM_KEY = '***';
$IAM_SECRET = '***';
// Connect to AWS
try {
    // You may need to change the region. It will say in the URL when the bucket is open
    // and on creation. us-east-2 is Ohio, us-east-1 is North Virgina
    $s3 = S3Client::factory(
        array(
            'credentials' => array(
                'key' => $IAM_KEY,
                'secret' => $IAM_SECRET
            ),
            'version' => 'latest',
            'region'  => 'us-east-1'
        )
    );
} catch (Exception $e) {
    // We use a die, so if this fails. It stops here. Typically this is a REST call so this would
    // return a json object.
    die("Error: " . $e->getMessage());
}
Jay
  • 25
  • 7

1 Answers1

1

I believe you may have public access is list only, but you have to grant read on the object level as well. (This will be open to public, so be careful)

Try checking the bucket policy: https://docs.aws.amazon.com/cli/latest/reference/s3api/get-bucket-policy.html or https://docs.aws.amazon.com/AmazonS3/latest/user-guide/bucket-permissions-check.html

Can you post the policy from something like:

aws s3api get-bucket-policy --bucket pipedemail --query Policy --output text > policy.json
Chris_Work
  • 56
  • 5