Two options, with different levels of complexity:
Canonical URL
Use a <link>
tag to tell Google what's the canonical URL for a given document:
<link rel="canonical" href="https://example.com/">
Redirect using Lambda@Edge
You can use a simple Lambda function deployed to CloudFront's edge servers. Follow this tutorial, and the function body you want (Node.js 8.10) is:
exports.handler = (event, context, callback) => {
const { request } = event.Records[0].cf;
const isIndex = request.uri.endsWith('/index.html');
if (isIndex) {
const withoutIndex = request.uri.replace(/\/index\.html$/, '');
callback(null, redirect(withoutIndex));
} else
callback(null, request);
};
function redirect(url) {
return {
status: '301',
statusDescription: 'Moved Permanently',
headers: {
location: [{
key: 'Location',
value: url
}]
}
};
}