Categories
Uncategorized

S3 CLI Jobs

Move batch of files with a pattern. (Delete –dry-run to do it for real)

aws s3 mv s3://mybucket/path/ s3://mybucket/newpath/ --recursive --exclude "*" --include "my_pattern*.gz" --dryrun 

Find some objects with the deprecated Reduced Redundancy Storage type to migrate

aws s3api list-objects-v2 --bucket mybucket --max-item 200 --start-after "somepath" --query 'Contents[?StorageClass==`REDUCED_REDUNDANCY`][Key]'
Categories
Servers

Uploading to AWS S3

101 Demo

[code]
<?php
// Instantiate an Amazon S3 client.
$s3 = new S3Client([
‘version’ => ‘latest’,
‘region’ => ‘ap-southeast-2’,  //Sydney
‘scheme’ => ‘http’, //omit, or https on servers that support it
‘credentials’ => [
‘key’ => ‘ YOUR KEY ‘,
‘secret’ => ‘ YOUR SECRET ‘
]
]);

// Upload a publicly accessible file. The file size and type are determined by the SDK.
try {
$s3->putObject([
‘Bucket’ => ‘yourbucket’,
‘Key’ => ‘path/to/key.png’,
‘Body’ => fopen(‘my-picture.png’, ‘r’),
‘ACL’ => ‘public-read’,
]);

echo "<p>Picture uploaded [tick]</p>";

} catch (Aws\Exception\S3Exception $e) {
echo "There was an error uploading the file.\n";
}
?>

[/code]