Serve Private Spaces Object to Browser via CDN

I am trying to access files uploaded to my Spaces bucket. They are private and associated with my users account. I authenticate on my server and was hoping to redirect to a URL where they can see the file.

I have this working with a pre-signed getObject URL. However, I would really prefer to gain the benefits of serving my files from the CDN. Here is what I am doing successfully now:

  accessKeyId: KEY,                                                    
  secretAccessKey: SECRET,                                             
  region: 'nyc3',                                                      
  signatureVersion: 'v4',                                              
const options = {                                                      
  signatureVersion: 'v4',                                              
  region: 'nyc3',                                                      
  endpoint: new AWS.Endpoint(''),
const client = new AWS.S3(options);                                    
const url = client.getSignedUrl('getObject', {                         
  Bucket: 'myBucket',                                                
  Key: 'theObjectKey',                                                    
  Expires: 5 * 60, // 5 minutes                                        

This provides me with a URL like:

This works well.

Is there any possible way to do this, but using my Spaces CDN? It appears that AWS’ Cloudfront has a completely different lib for signing CF objects (seen here:

Any help is much appreciated. Happy to answer any questions.

Show comments

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

You can use a pre-signed URL with the CDN as shown in the following documentation

Please let me know if this helps you out.

Assuming that you have already enabled your CDN, have you tried using the same URL that getSignedUrl returns, but with the domain changed to point to the CDN?

E.g., instead of: