CloudFront Functions 뷰어 요청 이벤트에서 새 URL로 리디렉션 - Amazon CloudFront

CloudFront Functions 뷰어 요청 이벤트에서 새 URL로 리디렉션

다음 코드 예제에서는 CloudFront Functions 뷰어 요청 이벤트에서 새 URL로 리디렉션하는 방법을 보여줍니다.

JavaScript
CloudFront Functions를 위한 JavaScript 런타임 2.0
참고

GitHub에 더 많은 내용이 있습니다. CloudFront Functions 예제 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

async function handler(event) { var request = event.request; var headers = request.headers; var host = request.headers.host.value; var country = 'DE' // Choose a country code var newurl = `https://${host}/de/index.html`; // Change the redirect URL to your choice if (headers['cloudfront-viewer-country']) { var countryCode = headers['cloudfront-viewer-country'].value; if (countryCode === country) { var response = { statusCode: 302, statusDescription: 'Found', headers: { "location": { "value": newurl } } } return response; } } return request; }

AWS SDK 개발자 가이드 및 코드 예시의 전체 목록은 AWS SDK와 함께 CloudFront 사용 섹션을 참조하세요. 이 주제에는 시작하기에 대한 정보와 이전 SDK 버전에 대한 세부 정보도 포함되어 있습니다.