PHP code example of saeven / laminas-aws-sdk

1. Go to this page and download the library: Download saeven/laminas-aws-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

saeven / laminas-aws-sdk example snippets


return array(
    /* ... */
    'modules' => array(
        /* ... */
        'AwsModule'
    ),
    /* ... */
);



return [
    'aws' => [
        'credentials' => [
            'key'    => '<your-aws-access-key-id>',
            'secret' => '<your-aws-secret-access-key>',
        ]
        'region' => 'us-west-2'
    ]
];

use Aws\Sdk;

public function indexAction()
{
    $aws    = $this->getServiceLocator()->get(Sdk::class);
    $client = $aws->createDynamoDb();

    $table = 'posts';

    // Create a "posts" table
    $result = $client->createTable(array(
        'TableName' => $table,
        'KeySchema' => array(
            'HashKeyElement' => array(
                'AttributeName' => 'slug',
                'AttributeType' => 'S'
            )
        ),
        'ProvisionedThroughput' => array(
            'ReadCapacityUnits'  => 10,
            'WriteCapacityUnits' => 5
        )
    ));

    // Wait until the table is created and active
    $client->waitUntilTableExists(array('TableName' => $table));

    echo "The {$table} table has been created.\n";
}

 echo $this->s3Link('my-object', 'my-bucket');


    $this->plugin('s3Link')->setDefaultBucket('my-bucket');
    echo $this->s3Link('my-object');

 echo $this->s3Link('my-object', 'my-bucket', '+10 minutes');

 echo $this->cloudFrontLink('my-object', 'my-domain');


    $this->plugin('cloudFrontLink')->setDefaultDomain('my-domain');
    echo $this->cloudFrontLink('my-object');

 echo $this->cloudFrontLink('my-object', 'my-bucket', time() + 60);

$request = new Request();
$files   = $request->getFiles();
// e.g., $files['my-upload']['tmp_name'] === '/tmp/php5Wx0aJ'
// e.g., $files['my-upload']['name'] === 'profile-picture.jpg'

// Fetch the filter from the Filter Plugin Manager to automatically handle dependencies
$filter = $serviceLocator->get('FilterManager')->get('S3RenameUpload');

$filter->setOptions(’[
    'bucket'    => 'my-bucket',
    'target'    => 'users/5/profile-picture.jpg',
    'overwrite' => true
]);

$filter->filter($files['my-upload']);

// File has been renamed and moved to 'my-bucket' bucket, inside the 'users/5' path

use AwsModule\Session\SaveHandler\DynamoDb as DynamoDbSaveHandler;
use Laminas\Session\SessionManager;

// Assume we are in a context where $serviceLocator is a ZF2 service locator.

$saveHandler = $serviceLocator->get(DynamoDbSaveHandler::class);

$manager = new SessionManager();
$manager->setSaveHandler($saveHandler);
json
{
    "ws/aws-sdk-php-zf2": "4.*"
    }
}
json
{
    "ws/aws-sdk-php-zf2": "3.*"
    }
}