Search code examples
amazon-s3deploymentversion-control

How to deploy web library to S3 with versioning?


I have a web library made under JavaScript and I'd like to automatically deploy it to a repository on Amazon S3, and keeping versioning. My current process is manually assigning a variable with the version I'm deploying and then uploading everything to S3 as a static web site. However, under that process I cannot keep multiple version on my repository at the same time.

I need a way where I could pass a parameter as version and deploy everything to my repository.

What would be the best way to achieve such deployment?


Solution

  • Amazon S3 is simply an object storage and while it offers object versioning that allows you to store multiple versions of the same object it's not what you're looking for as it's intended to protect from the consequences of unintended overwrites and deletions, additionally static hosting will serve only the version of the same object that has been promoted as current.

    What you're trying to achieve can be solved by simply working with prefixes:

    bucket_name/v1/my_library.js
    bucket_name/v2/my_library.js
    bucket_name/v3/my_library.js
    

    This can be handled by you manually, if you're doing the upload yourself, or programmatically by keeping track of which was the last version or querying the bucket and incrementing the count.