Is it possible to set Amazon S3 CORS programmatically (from Apex)?

I'm coming up with a salesforce (force.com) app that allows to upload files from salesforce to amazon s3 (using drag and drop feature).

As part of setup for this app, I'm asking user to create bucket first (which I've handled programmatically ie user clicks a button and via API bucket is created) and next step is to enable CORS for this bucket, which I'm not able to do programmatically. Is it possible to set Amazon S3 CORS programmatically (from Apex) ?

As of now, I have to ask user to manually login to S3, find bucket, edit properties and save CORS which is a tedious process and will be hard for any business/admin user.

Any help in this direction will be greatly appreciated!

  • 1
    This looks like it's more of an AWS question, rather than Salesforce one (and therefore more suited to Stack Overflow. However a quick Google shows that you can setup CORS using the Amazon REST API, which you should be able to call from Apex - docs.aws.amazon.com/AmazonS3/latest/dev/… Commented Sep 29, 2014 at 10:30
  • @AlexTennant Sounds like an answer, thanks a lot. Will try! Can you please post this as a answer, so that I can select same as Solution/Answer. Commented Sep 29, 2014 at 10:43

1 Answer 1


You can setup CORS for a bucket using the Amazon S3 REST API.

It should be reasonably easy to call this from Apex using the HttpRequest class which is covered in the Invoking HTTP Callouts documentation.

Invoking HTTP Callouts

Apex provides several built-in classes to work with HTTP services and create HTTP requests like GET, POST, PUT, and DELETE.

You can use these HTTP classes to integrate to REST-based services. They also allow you to integrate to SOAP-based web services as an alternate option to generating Apex code from a WSDL. By using the HTTP classes, instead of starting with a WSDL, you take on more responsibility for handling the construction of the SOAP message for the request and response.

The Force.com Toolkit for Google Data APIs makes extensive use of HTTP callouts.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .