{"id":550,"date":"2019-06-08T12:41:45","date_gmt":"2019-06-08T03:41:45","guid":{"rendered":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2019\/06\/08\/redirect_to_country_specific_uri"},"modified":"2019-06-08T12:41:45","modified_gmt":"2019-06-08T03:41:45","slug":"redirect_to_country_specific_uri","status":"publish","type":"post","link":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2019\/06\/08\/redirect_to_country_specific_uri\/","title":{"rendered":"Lambda@Edge\u3067\u30a2\u30af\u30bb\u30b9\u5143\u306e\u56fd\u3092\u5224\u5225\u3057\u3066\u30ea\u30c0\u30a4\u30ec\u30af\u30c8"},"content":{"rendered":"
\u3064\u3044\u5148\u65e5\u304a\u5ba2\u69d8\u304b\u3089\u3001<\/p>\n
\u300c\u7279\u5b9a\u306e\u30d1\u30b9\u306b\u5bfe\u3057\u3066\u3001\u7279\u5b9a\u306e\u56fd\u304b\u3089\u306e\u30a2\u30af\u30bb\u30b9\u304c\u3042\u3063\u305f\u5834\u5408\u306b\u3001\u5225\u306e\u30d1\u30b9\u306b\u8ee2\u9001\u3059\u308b\u3053\u3068\u306f\u53ef\u80fd\u304b\uff1f\u300d<\/p>\n
\u3068\u3044\u3046\u3054\u76f8\u8ac7\u3092\u3044\u305f\u3060\u3044\u305f\u3002<\/p>\n
\u4eca\u56de\u306f\u3001\u3053\u306e\u30b1\u30fc\u30b9\u306b\u3064\u3044\u3066\u3001 \u3010\u53c2\u8003URL\u3011 \u307e\u305a\u306f\u3001\u691c\u8a3c\u7528\u306e\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u3092 \u3092\u7f6e\u304f\u5f62\u306b\u3057\u3066\u307f\u305f\u3002<\/p>\n <\/p>\n \u7d9a\u3044\u3066\u9759\u7684\u30a6\u30a7\u30d6\u30db\u30b9\u30c6\u30a3\u30f3\u30b0\u306e\u8a2d\u5b9a\u3092\u3059\u308b\u3002 \u7d9a\u3044\u3066 \u4eca\u56de\u306e\u30dd\u30a4\u30f3\u30c8\u3068\u3057\u3066\u306f\u3001<\/p>\n \u3068\u3044\u3046\u3053\u3068\u3002<\/p>\n \u8a2d\u5b9a\u4f8b\u3068\u3057\u3066\u306f\u3001\u4e0b\u8a18\u306e\u3068\u304a\u308a\u3001 <\/p>\n \u305b\u3063\u304b\u304f\u306a\u306e\u3067\u3001 \u4eca\u56de\u306f\u3001\u30c9\u30a4\u30c4\u304b\u3089\u306e\u30a2\u30af\u30bb\u30b9\u3060\u3051\u3001\u5225\u306e\u30d1\u30b9\u306b\u8ee2\u9001\u3057\u3066\u307f\u305f\u3044\u306e\u3067\u3001 \u305d\u3053\u306b\u3001 <\/p>\n \u3010\u53c2\u8003URL\u3011 \u306b\u8a18\u8f09\u306e\u3042\u308b\u4f8b\u3092\u30d9\u30fc\u30b9\u306b\u3001\u4eca\u56de\u306f<\/p>\n http:\/\/genetest.test.mmmcorp.co.jp\/<\/a> \u6765\u305f\u30a2\u30af\u30bb\u30b9\u3092\u3001<\/p>\n \u3059\u308b\u3088\u3046\u306b\u5909\u66f4\u3057\u3066\u8a2d\u5b9a\u3002<\/p>\n \u4eca\u56de\u306f\u3001 \u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b<\/p>\n \u3053\u306e\u4f8b\u3092\u4f7f\u7528\u3059\u308b\u306b\u306f\u3001\u30aa\u30ea\u30b8\u30f3\u30ea\u30af\u30a8\u30b9\u30c8\u30a4\u30d9\u30f3\u30c8\u306e\u30c8\u30ea\u30ac\u30fc\u3092\u4f5c\u6210\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<\/blockquote>\n \u3068\u3042\u308b\u3068\u304a\u308a\u3001 <\/p>\n \u307e\u305a\u306f\u3001\u666e\u901a\u306b http:\/\/genetest.test.mmmcorp.co.jp\/<\/a> \u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3002<\/p>\n <\/p>\nLambda@Edge<\/code> \u3067\u884c\u3046\u65b9\u6cd5\u304c AWS \u516c\u5f0f\u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u4f8b\u3068\u3057\u3066\u4e0a\u304c\u3063\u3066\u3044\u305f\u306e\u3067\u3001\u5b9f\u969b\u306b\u8a66\u3057\u3066\u307f\u308b\u3002<\/p>\n
\u56fd\u307e\u305f\u306f\u30c7\u30d0\u30a4\u30b9\u30bf\u30a4\u30d7\u30d8\u30c3\u30c0\u30fc\u5225\u306e\u30d1\u30fc\u30bd\u30ca\u30e9\u30a4\u30ba - \u4f8b<\/a><\/p>\n\u4e0b\u6e96\u5099<\/h2>\n
Amazon S3 \u3067\u9759\u7684\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u4f5c\u6210<\/h3>\n
Amazon S3<\/code> \u3067\u30b5\u30af\u30c3\u3068\u8a2d\u5b9a\u3059\u308b\u3002<\/p>\n
mmm-eugene-test<\/code> \u30d0\u30b1\u30c3\u30c8\u3092\u4f5c\u6210\u3057\u3066\u3001\u305d\u3053\u306b<\/p>\n
index.html<\/code>
english\/index.html<\/code>
german\/index.html<\/code> <\/p>\n
http:\/\/mmm-eugene-test.s3-website-ap-northeast-1.amazonaws.com\/<\/code> \u3067\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u3053\u3068\u3092\u78ba\u8a8d\u3002<\/p>\n
Amazon CloudFront \u8a2d\u5b9a<\/h3>\n
Amazon CloudFront<\/code> \u3092\u8a2d\u5b9a\u3059\u308b\u3002<\/p>\n
Origin<\/code> \u306b\u306f\u3001\u5148\u307b\u3069\u4f5c\u6210\u3057\u305f\u9759\u7684\u306a\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u3001
http:\/\/mmm-eugene-test.s3-website-ap-northeast-1.amazonaws.com\/<\/code> \u3092\u8a2d\u5b9a\u3059\u308b\u3002<\/p>\n
\n
CloudFront-Viewer-Country<\/code> \u30d8\u30c3\u30c0\u30fc\u306b\u57fa\u3065\u3044\u3066\u30ad\u30e3\u30c3\u30b7\u30e5\u3059\u308b\u3088\u3046\u306b\u30c7\u30a3\u30b9\u30c8\u30ea\u30d3\u30e5\u30fc\u30b7\u30e7\u30f3\u3092\u8a2d\u5b9a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b<\/li>\n<\/ul>\n
Cache Based on Selected Request Headers<\/code> \u3067
Whitelist<\/code> \u3092\u9078\u629e\u3057\u305f\u4e0a\u3067\u3001
CloudFront-Viewer-Country<\/code> \u3092\u30db\u30ef\u30a4\u30c8\u30ea\u30b9\u30c8\u306b\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n
Route53<\/h3>\n
Amazon Route 53<\/code> \u3082\u5408\u308f\u305b\u3066\u8a2d\u5b9a\u3059\u308b\u3002<\/p>\n
genetest.test.mmmcorp.co.jp<\/code> \u3068\u8a2d\u5b9a\u3057\u3066\u307f\u305f\u3002<\/p>\n
\u6d77\u5916\u304b\u3089\u30a2\u30af\u30bb\u30b9\u3059\u308b\u305f\u3081\u306b\u3001\u30d7\u30ed\u30ad\u30b7\u30b5\u30fc\u30d0\u30fc\u69cb\u7bc9<\/h2>\n
eu-central-1<\/code> (\u30d5\u30e9\u30f3\u30af\u30d5\u30eb\u30c8\u30ea\u30fc\u30b8\u30e7\u30f3)\u306b
Amazon EC2<\/code> \u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u4f5c\u6210\u3059\u308b\u3002 <\/p>\n
Squid<\/code> \u3092\u4f7f\u3063\u3066\u30d7\u30ed\u30ad\u30b7\u30b5\u30fc\u30d0\u30fc\u3092\u69cb\u7bc9\u3002<\/p>\n
Chrome<\/code> \u306e\u30d7\u30ed\u30ad\u30b7\u30b5\u30fc\u30d0\u30fc\u5207\u308a\u66ff\u3048\u62e1\u5f35\u306b\u3066\u3001\u4e0a\u8a18\u3067\u69cb\u7bc9\u3057\u305f\u30d7\u30ed\u30ad\u30b7\u30b5\u30fc\u30d0\u30fc\u306e\u8a2d\u5b9a\u3092\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n
Lambda@Edge \u8a2d\u5b9a<\/h2>\n
\u56fd\u307e\u305f\u306f\u30c7\u30d0\u30a4\u30b9\u30bf\u30a4\u30d7\u30d8\u30c3\u30c0\u30fc\u5225\u306e\u30d1\u30fc\u30bd\u30ca\u30e9\u30a4\u30ba - \u4f8b<\/a><\/p>\n\n
Lambda@Edge<\/code> \u3092\u5229\u7528\u3059\u308b\u306e\u3067\u3001
us-east-1<\/code> (\u30d0\u30fc\u30b8\u30cb\u30a2\u5317\u90e8\u30ea\u30fc\u30b8\u30e7\u30f3)\u306b\u8a2d\u5b9a\u304c\u5fc5\u8981\u306a\u306e\u3067\u8981\u6ce8\u610f\u3002<\/p>\n
'use strict';\n\n\/* This is an origin request function *\/\nexports.handler = (event, context, callback) => {\n const request = event.Records[0].cf.request;\n const headers = request.headers;\n console.log(request.uri);\n\n if (request.uri !== '\/') {\n callback(null, request);\n };\n\n let url = 'http:\/\/genetest.test.mmmcorp.co.jp\/english\/';\n if (headers['cloudfront-viewer-country']) {\n const countryCode = headers['cloudfront-viewer-country'][0].value;\n console.log(countryCode);\n if (countryCode === 'DE') {\n url = 'http:\/\/genetest.test.mmmcorp.co.jp\/german\/';\n }\n }\n\n const response = {\n status: '302',\n statusDescription: 'Found',\n headers: {\n location: [{\n key: 'Location',\n value: url,\n }],\n },\n };\n\n callback(null, response);\n};<\/code><\/pre>\n
\n
CloudFront<\/code> \u306e
Origin Request<\/code> \u306b\u8a2d\u5b9a\u3059\u308b\u3002<\/p>\n
\u52d5\u4f5c\u78ba\u8a8d<\/h2>\n