Appending /index.html to cloudfront/s3. Trigger not working

0

Hi,

I have a gatsby served page and like many before me I have the issue of when URI does not include index.html it does not find the page to serve. I've followed countless guides now from adding a function to alter the viewer request and lambda@edge to trigger change of origin request.

I've tried both node and python handlers and my current one is python

def lambda_handler(event, context):
    request = event['Records'][0]['cf']['request']
    if request['uri'].endswith("/"):
        request['uri'] = f"{request['uri']}index.html"
    return request

If I return a bad value my cloudfront complains and refuses to load, but when i have the code as above the page loads fine but the trigger does not happen, i cannot find execution of the trigger in any region - only when it's generating an error.

Why is the function not triggerning/alerting the request uri?

asked 6 months ago206 views
1 Answer
0

If you don't fancy tinkering with all configuration details and debugging lambda@edge, there is an easier way to host Gatsby using AWS Amplify. It takes care of many low-level details for you.

https://docs.amplify.aws/guides/hosting/gatsby/q/platform/js/#deploying-the-site-to-amplify-console-hosting

profile picture
EXPERT
Kallu
answered 6 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions