How to configure Spaces lifecycle policies on DigitalOcean
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
Install and Configure AWS CLI
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).Create Your Lifecycle Policy XML File
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>Set the Endpoint URL for DigitalOcean Spaces
--endpoint-url https://[region].digitaloceanspaces.com where [region] is your Space's region. For example, for NYC3: --endpoint-url https://nyc3.digitaloceanspaces.com.Apply the Lifecycle Policy to Your Space
aws s3api put-bucket-lifecycle-configuration --bucket your-space-name --lifecycle-configuration file://lifecycle-policy.xml --endpoint-url https://[region].digitaloceanspaces.comReplace your-space-name with your actual Space name and [region] with your Space's region.
Verify the Lifecycle Policy
aws s3api get-bucket-lifecycle-configuration --bucket your-space-name --endpoint-url https://[region].digitaloceanspaces.comThis will display the currently active lifecycle configuration for your Space.
Monitor Policy Execution
Update or Remove Lifecycle Policies
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.comCommon 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.