How to configure Spaces lifecycle policies on DigitalOcean

intermediate 8 min read Updated 2026-04-20
Quick Answer

DigitalOcean Spaces lifecycle policies are configured using S3-compatible tools like AWS CLI or s3cmd since the control panel doesn't have native lifecycle management. You'll need to create XML policy files and apply them via command line tools.

Prerequisites

  • A DigitalOcean account with billing enabled
  • An existing Spaces bucket
  • Basic understanding of S3-compatible APIs
  • AWS CLI or s3cmd tool installed

Step-by-Step Instructions

1

Install and Configure AWS CLI

Install AWS CLI on your system using pip install awscli or download from the official AWS website. Configure it for DigitalOcean Spaces by running aws configure and enter your Spaces access key and secret key. Set the default region to your Space's region (e.g., nyc3, ams3, sgp1).
You can find your Spaces access keys in the DigitalOcean control panel under API > Spaces Keys.
2

Create Your Lifecycle Policy XML File

Create a new file called lifecycle-policy.xml with your desired lifecycle rules. A basic policy to delete objects after 30 days looks like:
<?xml version="1.0" encoding="UTF-8"?>
<LifecycleConfiguration>
  <Rule>
    <ID>DeleteAfter30Days</ID>
    <Status>Enabled</Status>
    <Filter>
      <Prefix></Prefix>
    </Filter>
    <Expiration>
      <Days>30</Days>
    </Expiration>
  </Rule>
</LifecycleConfiguration>
You can add multiple rules within the same LifecycleConfiguration for different prefixes or actions.
3

Set the Endpoint URL for DigitalOcean Spaces

When using AWS CLI with DigitalOcean Spaces, you must specify the correct endpoint. Use --endpoint-url https://[region].digitaloceanspaces.com where [region] is your Space's region. For example, for NYC3: --endpoint-url https://nyc3.digitaloceanspaces.com.
Create an alias in your shell configuration to avoid typing the endpoint URL repeatedly.
4

Apply the Lifecycle Policy to Your Space

Use the AWS CLI to apply your lifecycle policy with the command:
aws s3api put-bucket-lifecycle-configuration --bucket your-space-name --lifecycle-configuration file://lifecycle-policy.xml --endpoint-url https://[region].digitaloceanspaces.com
Replace your-space-name with your actual Space name and [region] with your Space's region.
5

Verify the Lifecycle Policy

Confirm your lifecycle policy was applied successfully by retrieving it with:
aws s3api get-bucket-lifecycle-configuration --bucket your-space-name --endpoint-url https://[region].digitaloceanspaces.com
This will display the currently active lifecycle configuration for your Space.
If no lifecycle policy exists, this command will return an error stating no lifecycle configuration was found.
6

Monitor Policy Execution

DigitalOcean automatically executes lifecycle policies daily. Monitor your Space's usage in the Spaces section of your DigitalOcean control panel to see the effects of your policy. Objects matching your policy rules will be automatically deleted according to the schedule you defined.
Lifecycle policy changes may take up to 24 hours to take effect.
7

Update or Remove Lifecycle Policies

To modify an existing policy, edit your XML file and rerun the put-bucket-lifecycle-configuration command. To remove all lifecycle policies, use:
aws s3api delete-bucket-lifecycle --bucket your-space-name --endpoint-url https://[region].digitaloceanspaces.com
Always test lifecycle policies on non-critical data first to ensure they work as expected.

Common Issues & Troubleshooting

AWS CLI returns 'Invalid endpoint' error

Verify you're using the correct endpoint URL format: https://[region].digitaloceanspaces.com and that your region matches your Space's actual region.

Access denied when applying lifecycle policy

Ensure your Spaces access key has the necessary permissions. The key must have write permissions for the specific Space you're configuring.

Lifecycle policy XML validation fails

Check your XML syntax carefully. Common issues include missing closing tags, incorrect element nesting, or invalid values in the Days field (must be positive integers).

Objects aren't being deleted according to the policy

Lifecycle policies execute once daily and may take 24-48 hours to start working. Verify your policy syntax and ensure the Status is set to Enabled in your XML configuration.

Prices mentioned in this guide are pulled from current plan data and may change. Always verify on the official DigitalOcean website before purchasing.