---
title: Use DigitalOcean Spaces with AWS S3 SDKs
description: Configure AWS S3 SDKs to work with DigitalOcean Spaces and run compatible S3 API operations.
product: Spaces
url: https://docs.digitalocean.com/products/spaces/reference/aws-sdks/
last_updated: "2026-07-13"
---

> **For AI agents:** The documentation index is at [https://docs.digitalocean.com/llms.txt](https://docs.digitalocean.com/llms.txt). Markdown versions of pages use the same URL with `index.html.md` in place of the HTML page (for example, append `index.html.md` to the directory path instead of opening the HTML document).

# Use DigitalOcean Spaces with AWS S3 SDKs

Spaces Object Storage is an S3-compatible service for storing and serving large amounts of data. The built-in Spaces CDN minimizes page load times, improves performance, and reduces bandwidth and infrastructure costs.

The Spaces API is compatible with the AWS S3 API, so you can use many existing S3 tools and libraries with Spaces. One common use case is managing Spaces buckets programmatically with AWS S3 software development kits (SDKs).

AWS provides S3 SDKs for a [variety of languages](#usage-examples), and many of them are compatible with the Spaces API. For more information about Spaces compatibility with the S3 API, see the [Spaces API documentation](https://docs.digitalocean.com/reference/api/spaces/index.html.md).

In S3-compatible tools, a key is the name of an object in a bucket.

For complete SDK reference documentation, see:

- [AWS SDK for JavaScript Reference](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html)
- [AWS SDK for Go Reference](https://docs.aws.amazon.com/sdk-for-go/api/service/s3/)
- [AWS SDK for PHP Reference](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-s3-2006-03-01.html)
- [Boto 3 Documentation (Python 3)](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html)
- [AWS SDK for Ruby Reference](https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/S3.html)
- [AWS SDK for .NET Reference](https://docs.aws.amazon.com/sdk-for-net/v3/developer-guide/s3-apis-intro.html)

## Install the SDK

Install the AWS SDK for your language with its package manager.

### JavaScript (ES6+)

```bash
npm install @aws-sdk/client-s3
```

### Go

```bash
go get -u github.com/aws/aws-sdk-go
```

### PHP

```bash
php composer.phar require aws/aws-sdk-php
```

### Python 3

```bash
pip install boto3
```

### Ruby

```bash
gem install aws-sdk-s3
```

### C#

```bash
dotnet add package AWSSDK.S3
```

## Create Access Keys

To use the Spaces API, [create an access key and secret key for your bucket](https://docs.digitalocean.com/products/spaces/how-to/manage-access/index.html.md#access-keys).

Copy and securely store your spaces key and its secret to use in your environment so that they’re available to your code.

## Configure a Client

To use Spaces with tools or libraries designed for the S3 API, configure the `endpoint` setting to point to your bucket region.

Use the format `$<your-region>.digitaloceanspaces.com`, where `$<your-region>` is the DigitalOcean datacenter region, such as `nyc3`, where the bucket is located.

Using presigned URLs does not allow transferred files to be cached when using the Spaces CDN. Attempting to do so may result in double the bandwidth charge without the CDN’s performance benefit.

**Warning**:

  Because of AWS-specific behavior in all SDKs except Python 3, bucket creation requires an AWS region such as `us-east-1` in the client configuration. When a custom region is specified during bucket creation, these SDKs send a different payload, which causes an error.

  Setting `us-east-1` doesn’t reduce performance, regardless of the bucket location. The SDK uses the region for validation only. It sends the request to the configured custom endpoint instead.

### JavaScript (ES6+)

**Note**:

  To create a bucket successfully with this SDK, set `region` to `us-east-1`, which is an AWS region name. The DigitalOcean datacenter region is determined by the `endpoint` value.

```javascript
import { S3 } from "@aws-sdk/client-s3";

const s3Client = new S3({
    forcePathStyle: false,
    endpoint: "https://<your-region>.digitaloceanspaces.com",
    region: "us-east-1",
    credentials: {
      accessKeyId: process.env.SPACES_KEY,
      secretAccessKey: process.env.SPACES_SECRET
    }
});

export { s3Client };
```

Set `forcePathStyle` to `false` to use subdomain-style, or virtual-hosted-style requests.

### Go

**Note**:

  To create a bucket successfully with this SDK, set `region` to `us-east-1`, which is an AWS region name. The DigitalOcean datacenter region is determined by the `endpoint` value.

The following example includes additional imports after importing `os` required by later Go examples below.

```go
package main

import (
    "os"
    "fmt"
    "io"
    "strings"
    "time"

    "github.com/aws/aws-sdk-go/aws"
    "github.com/aws/aws-sdk-go/aws/credentials"
    "github.com/aws/aws-sdk-go/aws/session"
    "github.com/aws/aws-sdk-go/service/s3"
)

func main() {
    key := os.Getenv("SPACES_KEY")
    secret := os.Getenv("SPACES_SECRET")

    s3Config := &aws.Config{
        Credentials: credentials.NewStaticCredentials(key, secret, ""),
        Endpoint:    aws.String("https://<your-region>.digitaloceanspaces.com"),
        Region:      aws.String("us-east-1"),
        S3ForcePathStyle: aws.Bool(false),
    }

    newSession := session.New(s3Config)
    s3Client := s3.New(newSession)

    ...
```

Set `S3ForcePathStyle` to `false` to use subdomain-style, or virtual-hosted-style requests.

### PHP

**Note**:

  To create a bucket successfully with this SDK, set `region` to `us-east-1`, which is an AWS region name. The DigitalOcean datacenter region is determined by the `endpoint` value.

This example loads the AWS SDK for PHP with Composer’s autoloader.

```php
<?php

require 'vendor/autoload.php';
use Aws\S3\S3Client;

$client = new Aws\S3\S3Client([
        'version' => 'latest',
        'region'  => 'us-east-1',
        'endpoint' => 'https://<your-region>.digitaloceanspaces.com',
        'use_path_style_endpoint' => false,
        'credentials' => [
                'key'    => getenv('SPACES_KEY'),
                'secret' => getenv('SPACES_SECRET'),
            ],
]);
```

Set `use_path_style_endpoint` to `false` to use subdomain-style, or virtual-hosted-style requests.

### Python 3

```python
import os
import boto3

session = boto3.session.Session()
client = session.client('s3',
                        region_name='<your-region>',
                        endpoint_url='https://<your-region>.digitaloceanspaces.com',
                        aws_access_key_id=os.getenv('SPACES_KEY'),
                        aws_secret_access_key=os.getenv('SPACES_SECRET'))
```

### Ruby

**Note**:

  To create a bucket successfully with this SDK, set `region` to `us-east-1`, which is an AWS region name. The DigitalOcean datacenter region is determined by the `endpoint` value.

```ruby
require 'aws-sdk-s3'

client = Aws::S3::Client.new(
  access_key_id: ENV['SPACES_KEY'],
  secret_access_key: ENV['SPACES_SECRET'],
  endpoint: 'https://<your-region>.digitaloceanspaces.com',
  force_path_style: false,
  region: 'us-east-1'
)
```

Set `force_path_style` to `false` to use subdomain-style, or virtual-hosted-style requests.

### C#

```c#
using System;
using Amazon;
using Amazon.S3;
using Amazon.S3.Model;

string accessKey = Environment.GetEnvironmentVariable("SPACES_KEY");
string secretKey = Environment.GetEnvironmentVariable("SPACES_SECRET");

AmazonS3Config config = new AmazonS3Config();
config.ServiceURL = "https://<your-region>.digitaloceanspaces.com";

AmazonS3Client s3Client = new AmazonS3Client(
        accessKey,
        secretKey,
        config
        );
```

## Calling S3 API Commands

After you configure the client, you can call supported S3 commands against Spaces.

The following examples create a bucket, and then list all buckets in the account.

### JavaScript (ES6+)

```javascript
import { S3Client, CreateBucketCommand, ListBucketsCommand } from '@aws-sdk/client-s3';

async function main() {
  const client = new S3Client({
    endpoint: 'https://<your-region>.digitaloceanspaces.com',
    region: 'us-east-1',
    forcePathStyle: false,
    credentials: {
      accessKeyId: process.env.SPACES_KEY,
      secretAccessKey: process.env.SPACES_SECRET
    }
  });

  await client.send(new CreateBucketCommand({ Bucket: '<your-new-space>' }));
  const { Buckets } = await client.send(new ListBucketsCommand({}));
  console.log(Buckets?.map(b => b.Name));
}
main().catch(console.error);
```

### Go

```go
package main

import (
    "fmt"
    "log"
    "os"

    "github.com/minio/minio-go"
)

func main() {
    accessKey := os.Getenv("SPACES_KEY")
    secKey := os.Getenv("SPACES_SECRET")
    endpoint := "<your-region>.digitaloceanspaces.com"
    spaceName := "<your-new-space>"
    ssl := true

    client, err := minio.New(endpoint, accessKey, secKey, ssl)
    if err != nil { log.Fatal(err) }

    if err := client.MakeBucket(spaceName, "us-east-1"); err != nil {
        log.Fatal(err)
    }

    spaces, err := client.ListBuckets()
    if err != nil { log.Fatal(err) }
    for _, space := range spaces {
        fmt.Println(space.Name)
    }
}
```

### Python 3

```python
import boto3, os
from botocore.client import Config

session = boto3.session.Session()
client = session.client(
    's3',
    region_name='<your-region>',
    endpoint_url='https://<your-region>.digitaloceanspaces.com',
    aws_access_key_id=os.getenv('SPACES_KEY'),
    aws_secret_access_key=os.getenv('SPACES_SECRET'),
    config=Config(s3={'addressing_style': 'virtual'})
)

client.create_bucket(Bucket='<your-new-space>')
print([b['Name'] for b in client.list_buckets()['Buckets']])
```

### Ruby

```ruby
require 'aws-sdk-s3'

client = Aws::S3::Client.new(
  access_key_id: ENV['SPACES_KEY'],
  secret_access_key: ENV['SPACES_SECRET'],
  endpoint: 'https://<your-region>.digitaloceanspaces.com',
  force_path_style: false,
  region: 'us-east-1'
)

client.create_bucket(bucket: '<your-new-space>')
client.list_buckets.buckets.each { |b| puts b.name }
```

### PHP

```php
<?php
require 'vendor/autoload.php';
use Aws\S3\S3Client;

$client = new S3Client([
  'version' => 'latest',
  'region' => 'us-east-1',
  'endpoint' => 'https://<your-region>.digitaloceanspaces.com',
  'use_path_style_endpoint' => false,
  'credentials' => [
    'key'    => getenv('SPACES_KEY'),
    'secret' => getenv('SPACES_SECRET'),
  ],
]);

$client->createBucket(['Bucket' => '<your-new-space>']);
$result = $client->listBuckets();
foreach ($result['Buckets'] as $b) { echo $b['Name'], PHP_EOL; }
```