How do I use AWS SDK for PHP with Wasabi?

AWS SDK for PHP is validated for use with Wasabi and can be used with Wasabi by simply pointing the endpoint to the Wasabi service URL of https://s3.wasabisys.com   

Note that this example discusses the use of Wasabi's us-east-1 storage region. To use other Wasabi storage regions, please use the appropriate Wasabi service URL as described in this article

To use the PHP SDK execute the following steps:

1) Install the AWS SDK for PHP

2) Configure additional AWS CLI profile for Wasabi account using the Wasabi keys

Below is a sample php file in which you configure the Wasabi endpoint. In this example we have set the profile name as "wasabi" in the "~/.aws/credentials" file.

 

  • The below example shows how to create an S3 Bucket in Wasabi using php

 

<?php

// Include the SDK using the Composer autoloader
require '<path for>/vendor/autoload.php';

use Aws\S3\S3Client;

// Instantiate the S3 client using your Wasabi profile
$s3Client = S3Client::factory(array(
'endpoint' => 'http://s3.wasabisys.com',
'profile' => 'wasabi',
'region' => 'us-east-1',
'version' => 'latest',
));

//Sample to create a bucket
$s3Client->createBucket(array('Bucket' => '<bucket-name>'));

?>

 

------------------------------------------------------------------------------------------------------------

 

  • The below example shows how to create an IAM user in Wasabi using php

 


// Include the SDK using the Composer autoloader
require '<path for>/vendor/autoload.php';


use Aws\Iam\IamClient;

$ch = curl_init();

// Instantiate the S3 client using your Wasabi profile
$client = IamClient::factory(array(
'endpoint' => 'http://s3.wasabisys.com',
'profile' => 'wasabi',
'region' => 'us-east-1',
'version' => 'latest',
));


try {
$result = $client->createUser(array(
// UserName is required, for e.g we are creating a user called Bob
'UserName' => 'Bob',
));
var_dump($result);
} catch (AwsException $e) {
// output error message if fails
error_log($e->getMessage());
}


?>

 

Note that this example discusses the use of Wasabi's us-east-1 storage region. To use other Wasabi storage regions, please use the appropriate Wasabi service URL as described in this article

Have more questions? Submit a request