I'm working in a template animation system, so I have different folders in S3 with different files inside (html, imgs, etc.)
What I do is:
I change the folder policy like that:
function changeFolderPolicy($folderPath, $client=null, $public) { if (!$client) { $client = getClientS3(); } $effect = 'Allow'; if (!$public) { $effect = 'Deny'; } $policy = json_encode(array( 'Statement' => array( array( 'Sid' => 'AllowPublicRead', 'Action' => array( 's3:GetObject' ), 'Effect' => $effect, 'Resource' => array( "arn:aws:s3:::".__bucketS3__."/".$folderPath."*" ), 'Principal' => array( 'AWS' => array( "*" ) ) ) ) )); $client->putBucketPolicy(array( 'Bucket' => __bucketS3__, 'Policy' => $policy )); }
After changing the policy, the frontend gets all the necessary files.
However, sometimes, some files aren't loaded because of a forbidden 403. It's not always the same files, sometimes ara all loaded, sometimes none... I don't have a clue since putBucketPolicy is a synchronous call.
Thank you very much.