I am currently hosting a static website on S3 which is using redirection rules to re-route the request to a lambda function.
The problem is I have two buckets that are both acting as static websites (sandbox vs production) and I need to be able to point them to the same lambda function but be able to tell them apart when the function is run. Whether it's a header, a GET
parameter, string manipulation, anything I can use to determine which bucket the request came from.
Does anyknow know how inside the lambda function I can identify that the request came from one bucket over the other? This is the current redirect rules I am using:
<RoutingRules>
<RoutingRule>
<Condition>
<KeyPrefixEquals/>
<HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
</Condition>
<Redirect>
<Protocol>https</Protocol>
<HostName>removed.execute-api.us-east-2.amazonaws.com</HostName>
<ReplaceKeyPrefixWith>prod/func?key=</ReplaceKeyPrefixWith>
<HttpRedirectCode>307</HttpRedirectCode>
</Redirect>
</RoutingRule>
</RoutingRules>
From what I understand I cannot set and headers or GET
parameters from this routing ruleset as the validation for the rules fails and my only option as it stands is to duplicate the lambda function, which I really don't want to do as it feels verbose.
I have also done JSON.stringify()
on the event
& context
parameters within the Lambda function and cannot seem to see any item to help me uniquely identify the origin bucket.
Appreciate any help with this.