2 Answers
- Newest
- Most votes
- Most comments
1
Hi
Just a hint, it's written by hand so there could be a typos or logic errors, CloudFront Function attached to CloudFront distribution as Function associations / Viewer request:
function handler(event) {
var request = event.request;
var uri = request.uri;
if (uri.endsWith('/something.txt')) {
statusCode: 404,
statusDescription: "Not Found",
}
return request;
}
Thanks,
answered 3 months ago
0
Hello everyone,
I wanted to provide the solution for this problem.
I created a Lambda Edge function (this needs to be in us-east-1):
``export async function handler(event) { const request = event.Records[0].cf.request;
// Check if request path is /something.txt
if (request.uri === '/something.txt') {
// Return a 404 response
return {
status: '404',
body: 'Not found',
statusDescription: 'Not Found'
};
}
// If request path is not /something.txt, pass through to the origin
return request;
};``
Then return back to CloudFront distribution and in the Behaviour part add path for /something.txt.
Inside of configuration for /something.txt in the Function Association add Origin request for your version of Lambda and arn of Lambda.
Hopefully this will be helpful for someone.
answered 3 months ago
Relevant content
- Accepted Answerasked 2 years ago
- asked 3 years ago
- asked 2 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago