For my small home backup I am building I wanted to use Amazon Web Services javascript SDK. The cool part of using it is that I can easily reuse the same code from both the small CLI and the frontend I am building, and since I am planning to use other other services than S3 their integration will be very easy, no need to specify credentials again.

But the drawback is the size of the resulting file. By default browserify is instructed by AWS to load a bunch of services when requiring the root module. Loading services one by one does not look like an easy option because of the way the API is built, but one can select the services to include (and their versions) in the bundle using environment variable AWS_SERVICES as documented on the official page:

AWS_SERVICES=s3-2006-03-01 browserify webapp/app.js --outfile _gh-pages/app.js

This still produces a very large package so in the end I might switch to smaller dependencies targetting specific services or even craft HTTP requests myself.

The second issue I encountered was OPTIONS HTTP requests failing from the browser with 403 Forbidden. Those requests qre actually sent by S3 SDK prior to making actual API related requests to ensure that CORS is correctly configured for the current host. In my case I was missing allowed headers in my bucket. I thus set the following configuration:

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <AllowedMethod>HEAD</AllowedMethod>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
</CORSConfiguration>

This can be set from the console, under bucket permissions, or by using the SDK itself from Node.js (which I now do on each synchronization).