{"id":604,"date":"2020-01-19T10:00:00","date_gmt":"2020-01-19T01:00:00","guid":{"rendered":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2020\/01\/19\/lambda_at_edge_redirect"},"modified":"2020-01-19T10:00:00","modified_gmt":"2020-01-19T01:00:00","slug":"lambda_at_edge_redirect","status":"publish","type":"post","link":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2020\/01\/19\/lambda_at_edge_redirect\/","title":{"rendered":"\u30b5\u30a4\u30c8\u30ea\u30cb\u30e5\u30fc\u30a2\u30eb\u6642\u306eURL\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3092Lambda@Edge\u3067\u5b9f\u73fe\u3059\u308b"},"content":{"rendered":"
\u5f0a\u793e\u3067\u306f\u6628\u5e749\u6708\u306b\u30b3\u30fc\u30dd\u30ec\u30fc\u30c8\u30b5\u30a4\u30c8\u3092\u30ea\u30cb\u30e5\u30fc\u30a2\u30eb\u3057\u307e\u3057\u305f\u3002<\/p>\n
\u30ea\u30cb\u30e5\u30fc\u30a2\u30eb\u306e\u7d4c\u7def\u306a\u3069\u306b\u3064\u3044\u3066\u306fMMM\u306e\u30b5\u30a4\u30c8\u30ea\u30cb\u30e5\u30fc\u30a2\u30eb\u306e\u7d4c\u7def<\/a>\u306b\u66f8\u3044\u3066\u3042\u308b\u306e\u3067\u3059\u304c\u3001\u30ea\u30cb\u30e5\u30fc\u30a2\u30eb\u306b\u4f34\u3044\u30b3\u30f3\u30c6\u30f3\u30c4\u306e\u69cb\u6210\u304c\u5909\u66f4\u306b\u306a\u308b\u305f\u3081\u3001URL\u3082\u5909\u66f4\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3057\u305f\u3002<\/p>\n URL\u306e\u5909\u66f4\u306f\u30b3\u30f3\u30c6\u30f3\u30c4\u306e\u5909\u66f4\u3092\u4f34\u3063\u305f\u30b5\u30a4\u30c8\u30ea\u30cb\u30e5\u30fc\u30a2\u30eb\u6642\u306b\u306f\u3057\u3070\u3057\u3070\u767a\u751f\u3057\u307e\u3059\u3002<\/p>\n \u305d\u306e\u969b\u3001\u691c\u7d22\u30a8\u30f3\u30b8\u30f3\u306b\u3057\u3070\u3089\u304f\u65e7URL\u304c\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3055\u308c\u3066\u3044\u305f\u308a\u3001\u65e7URL\u306e\u30d6\u30c3\u30af\u30de\u30fc\u30af\u304b\u3089\u76f4\u63a5\u30a2\u30af\u30bb\u30b9\u3055\u308c\u305f\u308a\u3059\u308b\u3053\u3068\u304c\u3042\u308b\u306e\u3067\u3001\u65b0URL\u3078\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3059\u308b\u8a2d\u5b9a\u3092\u3057\u3066\u304a\u304d\u305f\u3044\u3067\u3059\u3002<\/p>\n \u4eca\u56de\u306f\u3001\u30b5\u30a4\u30c8\u30b3\u30f3\u30c6\u30f3\u30c4\u306e\u30ea\u30cb\u30e5\u30fc\u30a2\u30eb\u6642\u306b\u95a2\u9023\u3059\u308bURL\u306b\u30ea\u30c0\u30a4\u30ec\u30af\u30c8 (\u8ee2\u9001) \u3059\u308b\u65b9\u6cd5\u306b\u3064\u3044\u3066\u66f8\u3044\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n \u307e\u305a\u3001\u5927\u524d\u63d0\u3068\u3057\u3066\u65e7URL\u3068\u65b0URL\u306e\u30de\u30c3\u30d4\u30f3\u30b0\u304c\u5fc5\u8981\u3067\u3059\u3002\u4f8b\u3048\u3070<\/p>\n \u65e7\u30b5\u30a4\u30c8URL: https:\/\/mmmcorp.co.jp\/solutions\/aws_lambda\/<\/a> \u306e\u3088\u3046\u306a\u30de\u30c3\u30d4\u30f3\u30b0\u3092\u30a8\u30af\u30bb\u30eb\u306a\u3069\u3067\u6574\u7406\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n \u305d\u306e\u4e0a\u3067\u306e\u6280\u8853\u7684\u306a\u8a71\u3068\u306a\u308a\u307e\u3059\u304c\u3001\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u306e\u4e00\u822c\u7684\u306a\u5bfe\u5fdc\u65b9\u6cd5\u3068\u3057\u3066\u306fWeb\u30b5\u30fc\u30d0\u30fc\u3067\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3092\u304b\u3051\u308b\u3053\u3068\u304c\u591a\u3044\u304b\u3068\u601d\u3044\u307e\u3059\u3002Web\u30b5\u30fc\u30d0\u30fc\u304c\u4f8b\u3048\u3070Apache\u3067\u3042\u308c\u3070.htaccess\u30d5\u30a1\u30a4\u30eb\u306a\u3069\u3067\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n \u3057\u304b\u3057\u3001\u65b0\u30b3\u30fc\u30dd\u30ec\u30fc\u30c8\u30b5\u30a4\u30c8\u306b\u304a\u3044\u3066\u306fAWS\u306eS3\u304a\u3088\u3073CloudFront\u3092\u5229\u7528\u3057\u3066\u9759\u7684\u306a\u30b3\u30f3\u30c6\u30f3\u30c4\u914d\u4fe1\u3092\u5b9f\u65bd\u3057\u3066\u3044\u307e\u3059\u3002\u9759\u7684\u30b3\u30f3\u30c6\u30f3\u30c4\u914d\u4fe1\u306f\u30b5\u30a4\u30c8\u30b9\u30d4\u30fc\u30c9\u5411\u4e0a\u30fb\u53ef\u7528\u6027\u5411\u4e0a\u30fb\u904b\u7528\u30b3\u30b9\u30c8\u524a\u6e1b\u306a\u3069\u30e1\u30ea\u30c3\u30c8\u304c\u975e\u5e38\u306b\u5927\u304d\u3044\u306e\u3067\u3059\u304c\u3001\u305d\u308c\u3060\u3051\u3067\u306fWeb\u30b5\u30fc\u30d0\u30fc\u3067\u306e\u8ee2\u9001\u304c\u3067\u304d\u306a\u3044\u3068\u3044\u3046\u554f\u984c\u304c\u3042\u308a\u307e\u3059\u3002\u305d\u3053\u3067\u3001\u672c\u30b1\u30fc\u30b9\u306b\u304a\u3044\u3066\u6709\u52b9\u306aLambda@Edge\u3092\u5229\u7528\u3057\u305f\u8ee2\u9001\u3092\u5b9f\u65bd\u3059\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n Lambda@Edge\u306e\u8aad\u307f\u65b9\u306f\u30e9\u30e0\u30c0\u30a2\u30c3\u30c8\u30a8\u30c3\u30b8\u3060\u3068\u601d\u3044\u307e\u3059\u3002(\u305f\u3060\u3001\u79c1\u306f\u30e9\u30e0\u30c0\u30a8\u30c3\u30b8\u3068\u547c\u3093\u3067\u3044\u307e\u3059\u3002)<\/p>\n Lambda@Edge\u3068\u306fAWS\u306eCDN\u30b5\u30fc\u30d3\u30b9\u3067\u3042\u308bAmazon CloudFront\u306e\u6a5f\u80fd\u3067\u3001CloudFront\u306e\u30a8\u30c3\u30b8\u30ed\u30b1\u30fc\u30b7\u30e7\u30f3\u306b\u304a\u3044\u3066\u30a2\u30af\u30bb\u30b9\u306b\u5bfe\u3057\u3066\u4efb\u610f\u306e\u30d7\u30ed\u30b0\u30e9\u30e0 (AWS Lambda) \u3092\u5b9f\u884c\u3067\u304d\u308b\u4ed5\u7d44\u307f\u3067\u3059\u3002\u30b5\u30fc\u30d0\u30fc\u30ec\u30b9\u306a\u4ed5\u7d44\u307f\u3067\u3042\u308a\u3001\u81ea\u524d\u3067\u30b5\u30fc\u30d0\u30fc\u3092\u7528\u610f\u3059\u308b\u5fc5\u8981\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n CloudFront\u306f\u9759\u7684\u306a\u30b3\u30f3\u30c6\u30f3\u30c4\u914d\u4fe1\u306e\u30b5\u30fc\u30d3\u30b9\u3067\u3042\u308a\u3001Web\u30b5\u30fc\u30d0\u30fc\u3067\u5b9f\u73fe\u3067\u304d\u308b\u52d5\u7684\u306a\u5236\u5fa1\u304c\u96e3\u3057\u3044\u306e\u3067\u3059\u304c\u3001Lambda@Edge\u306f\u305d\u306e\u554f\u984c\u3092\u89e3\u6c7a\u3067\u304d\u307e\u3059\u3002<\/p>\n \u4eca\u56de\u306eURL\u306e\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u4ee5\u5916\u306b\u3082\u975e\u5e38\u306b\u69d8\u3005\u306a\u3053\u3068\u304c\u5b9f\u73fe\u3067\u304d\u307e\u3059\u3002<\/p>\n \u305d\u308c\u3067\u306f\u5b9f\u969b\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u4f8b\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n \u30b5\u30a4\u30c8\u30a2\u30af\u30bb\u30b9 (CloudFront\u3078\u306e\u30a2\u30af\u30bb\u30b9) \u6642\u306b\u4e0a\u8a18\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b9f\u884c\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u304a\u308a\u3001\u30de\u30c3\u30d4\u30f3\u30b0\u306b\u5408\u81f4\u3059\u308bURL\u3078\u306e\u30a2\u30af\u30bb\u30b9\u3067\u3042\u308c\u3070\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3001\u5408\u81f4\u3057\u306a\u3044URL\u3067\u3042\u308c\u3070\u305d\u306e\u307e\u307e\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n Lambda@Edge\u306f\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u66f8\u3044\u3066\u52d5\u4f5c\u3055\u305b\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u306e\u3067\u3001\u5f53\u7136\u30d0\u30b0\u3092\u4f5c\u308a\u8fbc\u3093\u3067\u3057\u307e\u3046\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n Lambda@Edge\u306f\u30b5\u30a4\u30c8\u30a2\u30af\u30bb\u30b9\u6642\u306b\u5fc5\u305a\u52d5\u4f5c\u3055\u305b\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u306b\u306a\u308a\u307e\u3059\u306e\u3067\u3001\u30b5\u30a4\u30c8\u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u306a\u304f\u306a\u3063\u3066\u3057\u307e\u3046\u3068\u3044\u3046\u3088\u3046\u306a\u91cd\u5927\u30d0\u30b0\u3092\u4f5c\u308a\u8fbc\u3093\u3067\u3057\u307e\u3046\u53ef\u80fd\u6027\u3082\u5927\u3044\u306b\u3042\u308a\u307e\u3059\u3002<\/p>\n \u30d0\u30b0\u3092\u4f5c\u308a\u8fbc\u307e\u306a\u3044\u3088\u3046\u306b\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u5bfe\u5fdc\u304c\u8003\u3048\u3089\u308c\u307e\u3059\u3002\u5b9f\u969b\u5f0a\u793e\u3067\u3082\u5f8c\u80052\u3064\u306e\u5bfe\u5fdc\u3092\u5b9f\u65bd\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n \u30c6\u30b9\u30c8\u30b3\u30fc\u30c9\u3092\u66f8\u304f: \u3053\u308c\u306f\u304b\u306a\u308a\u9762\u5012\u3067\u3001\u4eca\u56de\u306f\u81ea\u793e\u30b3\u30fc\u30dd\u30ec\u30fc\u30c8\u30b5\u30a4\u30c8\u3068\u3044\u3046\u30b5\u30fc\u30d3\u30b9\u306e\u4e8b\u60c5\u3082\u8e0f\u307e\u3048\u3001\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9\u306f\u66f8\u3044\u3066\u3044\u307e\u305b\u3093\u3002<\/p>\n<\/li>\n \u30b9\u30c6\u30fc\u30b8\u30f3\u30b0\u74b0\u5883\u3067\u30c6\u30b9\u30c8\u3059\u308b: \u672c\u756a\u3068\u540c\u69d8\u306e\u74b0\u5883\u3092\u7528\u610f\u3057\u3001\u671f\u5f85\u901a\u308a\u306e\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u304c\u52d5\u3044\u3066\u3044\u308b\u304b\u30c6\u30b9\u30c8\u3092\u3057\u3066\u304b\u3089\u672c\u756a\u306b\u30ea\u30ea\u30fc\u30b9\u3057\u307e\u3059\u3002<\/p>\n<\/li>\n \u672c\u756a\u30b5\u30a4\u30c8\u3092\u76e3\u8996\u3059\u308b: \u4e07\u304c\u4e00\u3001\u672c\u756a\u306eLambda@Edge\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u9593\u9055\u3063\u3066\u66f8\u3044\u3066\u3001\u30b5\u30a4\u30c8\u30a2\u30af\u30bb\u30b9\u3067\u304d\u306a\u3044\u4e8b\u614b\u306b\u306a\u3063\u3066\u3057\u307e\u3063\u3066\u3082\u3001\u305d\u308c\u3092\u3059\u3050\u306b\u691c\u77e5\u3067\u304d\u308b\u3088\u3046\u306b\u76e3\u8996\u3057\u307e\u3059\u3002\u5f0a\u793e\u3067\u306fDatadog\u3092\u5229\u7528\u3057\u305f\u76e3\u8996\u3092\u5b9f\u65bd\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<\/li>\n<\/ul>\n \u4eca\u56de\u3001\u30b5\u30a4\u30c8\u30ea\u30cb\u30e5\u30fc\u30a2\u30eb\u6642\u306bLambda@Edge\u3067URL\u306e\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3092\u5b9f\u73fe\u3059\u308b\u65b9\u6cd5\u3092\u3054\u7d39\u4ecb\u3044\u305f\u3057\u307e\u3057\u305f\u3002<\/p>\n \u5f0a\u793e\u3067\u30b5\u30a4\u30c8\u30ea\u30cb\u30e5\u30fc\u30a2\u30eb\u306e\u304a\u624b\u4f1d\u3044\u3092\u3059\u308b\u5834\u5408\u3001\u30b5\u30a4\u30c8\u306e\u9ad8\u901f\u5316\u3084\u53ef\u7528\u6027\u3001\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u30b3\u30b9\u30c8\u306e\u524a\u6e1b\u306e\u305f\u3081\u3001\u8981\u4ef6\u3092\u8e0f\u307e\u3048\u305f\u4e0a\u3067\u53ef\u80fd\u306a\u9650\u308aS3, CloudFront\u3092\u5229\u7528\u3057\u305f\u9759\u7684\u306a\u30b5\u30a4\u30c8\u30db\u30b9\u30c6\u30a3\u30f3\u30b0\u3092\u3054\u63d0\u6848\u3055\u305b\u3066\u3044\u305f\u3060\u3044\u3066\u304a\u308a\u307e\u3059\u3002<\/p>\n \u3053\u308c\u307e\u3067\u52d5\u7684\u306a\u90e8\u5206\u304c\u5fc5\u8981\u306a\u305f\u3081\u306bS3, CloudFront\u3067\u306e\u9759\u7684\u30db\u30b9\u30c6\u30a3\u30f3\u30b0\u304c\u4e0d\u53ef\u80fd\u3060\u3063\u305f\u6848\u4ef6\u306b\u304a\u3044\u3066\u3082\u3001Lambda@Edge\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u3067\u53ef\u80fd\u306b\u306a\u308b\u30b1\u30fc\u30b9\u3082\u5897\u3048\u3066\u304f\u308b\u3068\u8003\u3048\u3066\u3044\u307e\u3059\u3002<\/p>\n AWS Lambda\u3092\u4f7f\u3063\u305f\u6700\u9069\u306a\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u3084\u3001\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u30b3\u30b9\u30c8\u3092\u8003\u616e\u3057\u305f\u30b5\u30a4\u30c8\u30ea\u30cb\u30e5\u30fc\u30a2\u30eb\u306b\u3064\u3044\u3066\u3001\u4ee5\u4e0b\u306e\u30da\u30fc\u30b8\u3067\u3054\u6848\u5185\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n
\n\u65b0\u30b5\u30a4\u30c8\u306b\u304a\u3051\u308b\u985e\u4f3c\u30b3\u30f3\u30c6\u30f3\u30c4\u306eURL: https:\/\/mmmcorp.co.jp\/service\/serverlessarchitecture\/<\/a><\/p>\nLambda@Edge\u3068\u306f<\/h1>\n
\n
\u5b9f\u969b\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u4f8b<\/h1>\n
'use strict';\n\nconst baseURL = "https:\/\/mmmcorp.co.jp";\nconst urlMap = {\n "https:\/\/mmmcorp.co.jp\/services\/aws\/": "https:\/\/mmmcorp.co.jp\/service\/development\/",\n "https:\/\/mmmcorp.co.jp\/solutions\/aws_lambda\/": "https:\/\/mmmcorp.co.jp\/service\/serverlessarchitecture\/",\n "https:\/\/mmmcorp.co.jp\/services\/aws\/migration\/": "https:\/\/mmmcorp.co.jp\/service\/migration\/",\n ... (\u3053\u3053\u306bURL\u306e\u30de\u30c3\u30d4\u30f3\u30b0\u3092\u611a\u76f4\u306b\u8a2d\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002)\n};\n\nexports.handler = (event, context, callback) => {\n const request = event.Records[0].cf.request;\n let uri = request.uri;\n\n if (request.uri.slice(-1) !== '\/') {\n uri += '\/';\n }\n\n const key = `${baseURL}${uri}`;\n let val = urlMap[key];\n if (val == null) {\n callback(null, request);\n return;\n }\n\n const response = {\n status: '302',\n statusDescription: 'Found',\n headers: {\n location: [{\n key: 'Location',\n value: val,\n }],\n },\n };\n\n callback(null, response);\n};\n<\/code><\/pre>\n
Lambda@Edge\u3067\u30da\u30fc\u30b8\u3092\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3059\u308b\u969b\u306e\u6ce8\u610f\u4e8b\u9805<\/h1>\n
\n
\u307e\u3068\u3081<\/h1>\n