Short Overview.
I host an Angular Application on an S3 Bucket. I also got an Cloudfront distribution to handle HTTPS and Redirects.
I try to form an querystring parameter depending on which URL the user is connecting to.
2 examples
test.example.com --> example.com?id=test
hello.example.com --> example.com?id?hello
So far i tried to implement an AWS lambda@Edge Function but nothing worked so far. If i try to manipulate the request
it wont have any effects, if i try to manipulate the response
the redirect does not work and i get an S3 bucket error or Cloudfront error.
'use strict';
const remove_suffix = '.example.com';
exports.handler = (event, context, callback) => {
const request = event.Records[0].cf.request;
const headers = request.headers;
const host_header = headers.host[0].value;
if(host_header.endsWith(remove_suffix)){
request.querystring = 'id=' + host_header.substring(0,host_header.length - remove_suffix.length);
}
return callback(null,request);
};
1) Which trigger should I use?
2) Which settings could I be missing on Cloudfront settings?
3) Is my Lambda function wrong?
You may want to ensure, that in the Cloudfront distribution Behavior
settings, option Query String Forwarding and Caching
is not set to None (Improves Caching)
You can find more info regarding that option in the documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With