Moving files to a new location may appear straightforward, but when considering the impact on your site’s SEO performance, it becomes a delicate and time-sensitive task. This is especially true when dealing with files hosted on an external service such as AWS S3.
Here are a couple of possible scenarios by clients’ requests:
- Modify file URIs, adding or removing slugs
- Programmatically rename files based on their parent names (our case)
- Implement changes related to the domain
When the files are hosted on your own server through your CMS, such as Craft or Drupal, you have the option to utilize plugins or modules to create 301 redirects (permanently moved) and monitor any broken links that end users might encounter.
In this particular case study, the client has their files stored in an AWS S3 bucket and using a CloudFront distribution. We explored two potential solutions: AWS Lambda@Edge Functions and CloudFront Functions.
CloudFront Functions #
Pros:
- Fast Response
- Cheaper, it has a free tier available
- Easier to set up
- Easier to test
- More intuitive dashboard
Cons:
- Limited file size
- Shorter function duration (timeout: within milliseconds)
- Javascript-based
Lambda@Edge Functions #
Pros:
- Possible to have multiple files
- JSON files are an option
- Multiple Languages available (Node.js, .NET, Python, Java, Ruby)
- Possible to have larger functions
Cons:
- Dashboard is tricky
- You need to connect the function with CloudFront
- More Expensive: Charged per request ($0.60 USD per 1 million requests)
We started with CloudFront Functions but had to move to Lambda@Edge Functions because of the file size limit of CloudFront Functions.
CloudFront Function Sample using Javascript.
Lambda@Edge Functions Sample using Javascript and JSON.
Keep into consideration the pros and cons for your specific needs and visit 301 redirects for files hosted in Amazon S3 using CloudFront Functions or 301 redirects for files hosted in Amazon S3 using Lambda@Edge Functions to get started.
If you have any questions, feel free to contact me.