{"id":534,"date":"2015-08-22T14:40:07","date_gmt":"2015-08-22T21:40:07","guid":{"rendered":"https:\/\/traverstodd.com\/?p=534"},"modified":"2019-07-11T11:20:44","modified_gmt":"2019-07-11T18:20:44","slug":"creating-website-redirect-locations-for-s3-with-node-js-and-the-aws-sdk","status":"publish","type":"post","link":"https:\/\/traverstodd.com\/creating-website-redirect-locations-for-s3-with-node-js-and-the-aws-sdk\/","title":{"rendered":"Creating Website Redirect Locations for S3 with Node.js and the aws-sdk"},"content":{"rendered":"
Recently, we migrated a client from a LAMP stack WordPress instance, which was load balanced across multiple EC2 VMs, to a single flattened Amazon S3 bucket. At the 11th hour, a hidden requirement presented itself. Unknown to the client’s marketing team and us, IT had been adding hundreds of 301 redirects, all contained within a included .conf file. The challenge here was to architect an elegant solution where IT would manage the redirect, and Marketing would retain their push button deployment process. S3 has an interesting<\/em> way of providing this feature – you set metadata to the object header that has a specific key of “Website Redirect Location”.<\/p>\n A short background… Our client is a tech company in the valley and this is their marketing website. Primarily a brochure site, this presented an opportunity to save our client a substantial amount of money as well as construct more secure site. S3 was the simple choice for hosting. In terms of infrastructure, the costs would roughly go from over $20k per year for multiple EC2 VMs to under $4k for some S3 buckets. Although we take every precaution to harden our WordPress instances, nothing beats a flattened site for security. Our client had 1 requirement… 1-button deployment. Well, we got pretty close out the gate, but we are still working on configuring everything that needs to happen down to 1-button. Currently its a 2-button process… Jenkins is indispensable.<\/p>\n Now on to why you are reading this… if you have worked with S3 at all, then you know there are practically an infinite number of ways to create an object programmatically (at least when googling it seems like there is a new utility or sdk out every week). After my own bit of research I decided that there was one elegant way we could add redirects to our deployment process.<\/p>\n