I want to set an expiration date for an object on s3 I create the object like this:
$this->s3->putObject(array(
'Bucket' => BUCKET,
'Key'=> "path",
'SourceFile' => $fileTmp,
'Expires' => time()+2*60,
'ACL' => 'private'
));
But when I check file on aws S3 Console the object keeps:
Expiry Date: None
Expiration Rule: N/A
How can I set object expiration?
Use the putBucketLifecycle
method like that:
$result = $client->putBucketLifecycleConfiguration([
'Bucket' => '<string>', // REQUIRED
'LifecycleConfiguration' => [
'Rules' => [ // REQUIRED
[
'Expiration' => [
'Date' => <integer || string || DateTime>,
'Days' => <integer>,
'ExpiredObjectDeleteMarker' => true || false,
],
'ID' => '<string>',
'Prefix' => '<string>',
'Status' => 'Enabled|Disabled', // REQUIRED
],
// ...
],
],
]);
Note
getBucketLifecycleConfiguration
before and merge the previous rules with the new one.Resources
Lifecycle policies are set per bucket, not per file.
Here's how to set a Lifecycle policy for a bucket:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.