How to use DigitalOcean Spaces with the AWS S3 SDKs?

DigitalOcean Spaces was designed to be inter-operable with the AWS S3 API in order allow users to continue using the tools they are already working with. In most cases, using Spaces with an existing S3 library requires configuring the endpoint value to be ${REGION} Though often how to change that setting is not well documented as examples tend to use the default AWS values. Third-party libraries tend to be better with this as they will support alternative, self-hosted object storage implementations like Mino or Ceph.

In the answers, let’s share some basic examples of working with Spaces using the AWS SDKs in various languages.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Andrew SB
DigitalOcean Employee
DigitalOcean Employee badge
November 10, 2017
Accepted Answer

PHP - (AWS docs)


// Included aws/aws-sdk-php via Composer's autoloader
// Installed with: composer.phar require aws/aws-sdk-php
require 'vendor/autoload.php';
use Aws\S3\S3Client;

// Configure a client using Spaces
$client = new Aws\S3\S3Client([
        'version' => 'latest',
        'region'  => 'nyc3',
        'endpoint' => '',
        'credentials' => [
                'key'    => 'ACCESS_KEY',
                'secret' => 'SECRET_KEY',

// Create a new Space
    'Bucket' => 'my-new-space-with-a-unique-name',

// Listing all Spaces in the region
$spaces = $client->listBuckets();
foreach ($spaces['Buckets'] as $space){
    echo $space['Name']."\n";

// Upload a file to the Space
$insert = $client->putObject([
     'Bucket' => 'my-new-space-with-a-unique-name',
     'Key'    => 'file.ext',
     'Body'   => 'The contents of the file'
Andrew SB
DigitalOcean Employee
DigitalOcean Employee badge
November 10, 2017

JavaScript - (AWS docs)

const AWS = require('aws-sdk')

// Configure client for use with Spaces
const spacesEndpoint = new AWS.Endpoint('');
const s3 = new AWS.S3({
    endpoint: spacesEndpoint,
    accessKeyId: 'ACCESS_KEY',
    secretAccessKey: 'SECRET_KEY'

// Create a new Space
var params = {
    Bucket: "my-new-space-with-a-unique-name"

s3.createBucket(params, function(err, data) {
    if (err) console.log(err, err.stack);
    else     console.log(data);

// List all Spaces in the region
s3.listBuckets({}, function(err, data) {
    if (err) console.log(err, err.stack);
        else {
            data['Buckets'].forEach(function(space) {

// Add a file to a Space
var params = {
    Body: "The contents of the file",
    Bucket: "my-new-space-with-a-unique-name",
    Key: "file.ext",

s3.putObject(params, function(err, data) {
    if (err) console.log(err, err.stack);
    else     console.log(data);

Working C# example using Amazon AWSSDK (V2.x).

IAmazonS3 amazonS3Client = 
	AWSClientFactory.CreateAmazonS3Client("your-spaces-key", "your-spaces-key-secrete",
	new AmazonS3Config
	   ServiceURL = ""
var myBuckets = amazonS3Client.ListBuckets();

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel