cardi777
cardi777

Reputation: 563

Setting Storage class on Amazon s3 upload (ver 3)

I can't work out how to make this upload as 'reduced redundancy'

Iv added it in there twice, but it doesn't do anything. I think the way I have applied is useless.

I think i need to use this line but it seems i need to rebuild this?

setOption('StorageClass', 'REDUCED_REDUNDANCY')

require_once __DIR__ .'/vendor/autoload.php';

$options = [
    'region' => $region,
    'credentials' => [
        'key' => $accessKeyId,
        'secret' => $secretKey
    ],
    'version' => '2006-03-01',
    'signature_version' => 'v4',
    'StorageClass' => 'REDUCED_REDUNDANCY',
];

$s3Client = new \Aws\S3\S3Client($options);

$uploader = new \Aws\S3\MultipartUploader($s3Client, $filename_dir , [
    'bucket' => $bucket,
    'key'    => $filename,
    'StorageClass' => 'REDUCED_REDUNDANCY',
]);

try {
    $result = $uploader->upload();
    echo "Upload complete: {$result['ObjectURL']}\n";
} catch (\Aws\Exception\MultipartUploadException $e) {
    echo $e->getMessage() . "\n";
}

Upvotes: 1

Views: 1343

Answers (2)

John Rotenstein
John Rotenstein

Reputation: 269550

Reduced Redundancy Storage used to be about 20% lower cost, in exchange for only storing 2 copies of the data instead of 3 copies (1 redundant copy instead of 2 redundant copies).

However, with the December 2016 pricing changes to Amazon S3, it is no longer beneficial to use Reduced Redundancy Storage.

Using pricing from US Regions:

  • Reduced Redundancy Storage = 2.4c/GB
  • Standard storage = 2.3c/GB
  • Standard-Infrequent Access storage = 1.25c/GB + 1c/GB retrievals

Therefore, RRS is now more expensive than Standard storage. It is now cheaper to choose Standard or Standard-Infrequent Access.

Upvotes: 1

Joshua Briefman
Joshua Briefman

Reputation: 4031

Setting "StorageClass" like this won't work.

$s3Client = new \Aws\S3\S3Client($options);

Because the StorageClass is only set when the object is uploaded, you can not default all of your requests to a specific configuration during the initialization of the SDK. Each individual PUT request must have it's own options specified for it.

To use the "SetOption" line you mentioned, you may need to update your code to follow the following example found in the AWS PHP SDK Documentation.

Using the AWS PHP SDK for Multipart Upload (High-Level API) Documentation

The following PHP code sample demonstrates how to upload a file using the high-level UploadBuilder object.

<?php

// Include the AWS SDK using the Composer autoloader.
require 'vendor/autoload.php';

use Aws\Common\Exception\MultipartUploadException;
use Aws\S3\Model\MultipartUpload\UploadBuilder;
use Aws\S3\S3Client;

$bucket = '*** Your Bucket Name ***';
$keyname = '*** Your Object Key ***';

// Instantiate the client.
$s3 = S3Client::factory();

// Prepare the upload parameters.
$uploader = UploadBuilder::newInstance()
    ->setClient($s3)
    ->setSource('/path/to/large/file.mov')
    ->setBucket($bucket)
    ->setKey($keyname)
    ->setMinPartSize(25 * 1024 * 1024)
    ->setOption('Metadata', array(
        'param1' => 'value1',
        'param2' => 'value2'
    ))
    ->setOption('ACL', 'public-read')
    ->setConcurrency(3)
    ->build();

// Perform the upload. Abort the upload if something goes wrong.
try {
    $uploader->upload();
    echo "Upload complete.\n";
} catch (MultipartUploadException $e) {
    $uploader->abort();
    echo "Upload failed.\n";
    echo $e->getMessage() . "\n";
}

So in this case you need to add 'StorageClass' as follows, the position isn't important, only the usage of setOption to set it:

->setOption('ACL', 'public-read')
->setOption('StorageClass', 'REDUCED_REDUNDANCY')
->setConcurrency(3)
->build();

Upvotes: 1

Related Questions