I have created one bucket and one cloudfront distribution. I followed this resource https://opsdocks.com/posts/multiple-websites-one-s3/ because I am going to host 3 different domains with only one bucket.
I have this folder structure in my bucket:
folder1 (domain1)
--- index
--- web1
--- web2
folder2 (domain2)
--- index
--- web1
--- web2
folder3 (domain3)
--- index
--- web1
--- web2
I used the lambda@edge function of the resource:
def lambda_handler(event, context):
request = event['Records'][0]['cf']['request']
request['origin']['s3']['path'] = "/"+request['headers']['host'][0]['value']
request['headers']['host'][0]['value'] = request['origin']['s3']['domainName']
return request
It works correctly with the path of the following type: folder1/web1. However, I have tried so hard to include in the script a behavior when accessing to folder1/ gets a redirection to folder1/index but it downloads an empty file all of the time.
I have made a lot of tests changing the function in so many ways but I do not know why is still doing the same behavior. Thank you