{"id":29743,"date":"2026-01-05T09:00:56","date_gmt":"2026-01-05T00:00:56","guid":{"rendered":"https:\/\/www.skyarch.net\/blog\/?p=29743"},"modified":"2025-12-17T12:50:46","modified_gmt":"2025-12-17T03:50:46","slug":"cloudwatch%e3%82%b5%e3%83%96%e3%82%b9%e3%82%af%e3%83%aa%e3%83%97%e3%82%b7%e3%83%a7%e3%83%b3%e3%83%95%e3%82%a3%e3%83%ab%e3%82%bf%e3%83%bc%e3%81%a7%e7%89%b9%e5%ae%9a%e3%83%ad%e3%82%b0%e3%81%ae%e3%81%bf","status":"publish","type":"post","link":"https:\/\/www.skyarch.net\/blog\/cloudwatch%e3%82%b5%e3%83%96%e3%82%b9%e3%82%af%e3%83%aa%e3%83%97%e3%82%b7%e3%83%a7%e3%83%b3%e3%83%95%e3%82%a3%e3%83%ab%e3%82%bf%e3%83%bc%e3%81%a7%e7%89%b9%e5%ae%9a%e3%83%ad%e3%82%b0%e3%81%ae%e3%81%bf\/","title":{"rendered":"CloudWatch\u30b5\u30d6\u30b9\u30af\u30ea\u30d7\u30b7\u30e7\u30f3\u30d5\u30a3\u30eb\u30bf\u30fc\u3067\u7279\u5b9a\u30ed\u30b0\u306e\u307f\u30e1\u30fc\u30eb\u901a\u77e5\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<h2>\u306f\u3058\u3081\u306b<\/h2>\n<p>CloudWatch\u30ed\u30b0\u306b\u51fa\u529b\u3055\u308c\u308b\u30ed\u30b0\u306e\u4e2d\u3067\u3001\u7279\u5b9a\u306e\u6761\u4ef6\uff08\u4f8b\u3048\u3070\u3001\u901a\u77e5\u3059\u308b\u30d5\u30e9\u30b0=true\uff09\u3092\u6e80\u305f\u3057\u305f\u5834\u5408\u306e\u307f\u3001SNS\u3092\u901a\u3058\u3066\u62c5\u5f53\u8005\u306b\u30e1\u30fc\u30eb\u901a\u77e5\u3092\u9001\u308b\u4ed5\u7d44\u307f\u3092\u3084\u3063\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<h2>\u76ee\u6b21<\/h2>\n<ul>\n<li><a href=\"#overview\">\u4eca\u56de\u306e\u69cb\u6210<\/a><\/li>\n<li><a href=\"#letstry\">\u3084\u3063\u3066\u307f\u3088\u3046\uff01<\/a><\/li>\n<li><a href=\"#vs\">\u30b5\u30d6\u30b9\u30af\u30ea\u30d7\u30b7\u30e7\u30f3\u30d5\u30a3\u30eb\u30bf\u30fc vs CloudWatch\u30a2\u30e9\u30fc\u30e0<\/a><\/li>\n<li><a href=\"#matome\">\u307e\u3068\u3081<\/a><\/li>\n<\/ul>\n<p><a id=\"overview\"><\/a><\/p>\n<h2>\u4eca\u56de\u306e\u69cb\u6210<\/h2>\n<p>CloudwatchLog\u306b\u51fa\u529b\u3055\u308c\u305f\u30ed\u30b0\u306e\u4e2d\u304b\u3089\u3001\u6761\u4ef6\u306b\u4e00\u81f4\u3057\u305f\u30ed\u30b0\u3092\u53d6\u5f97\u3057\u3066\u3001SNS\u3092\u901a\u3058\u3066\u30e1\u30fc\u30eb\u901a\u77e5\u3059\u308b\u3002<\/p>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2025\/11\/kousei.png\"><img decoding=\"async\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2025\/11\/kousei.png\" alt=\"\" \/><\/a>\n<p><a id=\"letstry\"><\/a><\/p>\n<h2>\u3084\u3063\u3066\u307f\u3088\u3046\uff01<\/h2>\n<p>\u3067\u306f\u3001\u3084\u3063\u3066\u307f\u307e\u3057\u3087\u3046\uff01<\/p>\n<h3>\u524d\u63d0\u6761\u4ef6<\/h3>\n<ul>\n<li>AWS CLI\u304c\u8a2d\u5b9a\u6e08\u307f<\/li>\n<li>\u9069\u5207\u306aIAM\u6a29\u9650\u3092\u6301\u3064\u30e6\u30fc\u30b6\u30fc<\/li>\n<li>\u30e1\u30fc\u30eb\u901a\u77e5\u3092\u53d7\u4fe1\u3059\u308b\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9<\/li>\n<\/ul>\n<h3>Step 1: SNS\u30c8\u30d4\u30c3\u30af\u306e\u4f5c\u6210<\/h3>\n<p>\u307e\u305a\u3001\u30e1\u30fc\u30eb\u901a\u77e5\u7528\u306eSNS\u30c8\u30d4\u30c3\u30af\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-bash\"># SNS\u30c8\u30d4\u30c3\u30af\u4f5c\u6210\naws sns create-topic --name log-notification-topic\n\n# \u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u3092\u30b5\u30d6\u30b9\u30af\u30e9\u30a4\u30d6\naws sns subscribe \\\n  --topic-arn arn:aws:sns:ap-northeast-1:YOUR_ACCOUNT_ID:log-notification-topic \\\n  --protocol email \\\n  --notification-endpoint your-email@example.com<\/code><\/pre>\n<p><strong>\u6ce8\u610f<\/strong>: \u30b5\u30d6\u30b9\u30af\u30e9\u30a4\u30d6\u5f8c\u3001\u30e1\u30fc\u30eb\u3067\u78ba\u8a8d\u30ea\u30f3\u30af\u304c\u9001\u4fe1\u3055\u308c\u308b\u306e\u3067\u3001\u5fc5\u305a\u30af\u30ea\u30c3\u30af\u3057\u3066\u78ba\u8a8d\u3057\u307e\u3057\u3087\u3046\u3002<br \/>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2025\/11\/confirm-mail.png\"><img decoding=\"async\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2025\/11\/confirm-mail.png\" alt=\"\" \/><\/a><\/p>\n<p>SNS\u30c8\u30d4\u30c3\u30af\u78ba\u8a8d<br \/>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2025\/11\/sns-topic.png\"><img decoding=\"async\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2025\/11\/sns-topic-1024x328.png\" alt=\"\" \/><\/a><\/p>\n<h3>Step 2: IAM\u30ed\u30fc\u30eb\u306e\u4f5c\u6210<\/h3>\n<p>Lambda\u95a2\u6570\u7528\u306eIAM\u30ed\u30fc\u30eb:log-notification-role \u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<br \/>\n\u3053\u306e\u30ed\u30fc\u30eb\u306b\u306f\u3001\u4e0b\u8a18\u30dd\u30ea\u30b7\u30fc\u3092\u30a2\u30bf\u30c3\u30c1\u3057\u307e\u3059\u3002<\/p>\n<h4>\u6a29\u9650\u30dd\u30ea\u30b7\u30fc (log-notification-policy.json)<\/h4>\n<ul>\n<li>logs:CreateLogGroup\uff1aCloudWatch\u306b\u30ed\u30b0\u30b0\u30eb\u30fc\u30d7\u3092\u4f5c\u6210\u3059\u308b\u6a29\u9650<\/li>\n<li>logs:CreateLogStream\uff1a\u30ed\u30b0\u30b0\u30eb\u30fc\u30d7\u5185\u306b\u30ed\u30b0\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u4f5c\u6210\u3059\u308b\u6a29\u9650<\/li>\n<li>logs:PutLogEvents\uff1a\u30ed\u30b0\u30b9\u30c8\u30ea\u30fc\u30e0\u306b\u30ed\u30b0\u30a4\u30d9\u30f3\u30c8\uff08\u5b9f\u969b\u306e\u30ed\u30b0\u30e1\u30c3\u30bb\u30fc\u30b8\uff09\u3092\u66f8\u304d\u8fbc\u3080\u6a29\u9650<\/li>\n<li>sns:Publish\uff1a\u6307\u5b9a\u3055\u308c\u305fSNS\u30c8\u30d4\u30c3\u30af\u306b\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u767a\u884c\u3059\u308b\u6a29\u9650<\/li>\n<\/ul>\n<pre class=\"lang:default decode:true\" title=\"log-notification-policy.json\">\n{\n  \"Version\": \"2012-10-17\",\n  \"Statement\": [\n    {\n      \"Effect\": \"Allow\",\n      \"Action\": [\n        \"logs:CreateLogGroup\",\n        \"logs:CreateLogStream\",\n        \"logs:PutLogEvents\"\n      ],\n      \"Resource\": \"arn:aws:logs:*:*:*\"\n    },\n    {\n      \"Effect\": \"Allow\",\n      \"Action\": [\n        \"sns:Publish\"\n      ],\n      \"Resource\": \"arn:aws:sns:ap-northeast-1:YOUR_ACCOUNT_ID:log-notification-topic\"\n    }\n  ]\n}\n<\/pre>\n<p>\u74b0\u5883\u5909\u6570\u304b\u3089\u3001\u901a\u77e5\u30e1\u30fc\u30eb\u306eSUBJECT\u3001SNS\u30c8\u30d4\u30c3\u30af\u3092\u53d6\u5f97\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2025\/12\/env.png\"><img decoding=\"async\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2025\/12\/env-1024x190.png\" alt=\"\" \/><\/a><\/p>\n<h3>Step 3: \u901a\u77e5\u6a5f\u80fdLambda\u95a2\u6570\u306e\u4f5c\u6210<\/h3>\n<p>\u30ed\u30b0\u3092\u89e3\u6790\u3057\u3066SNS\u3092\u901a\u3058\u3066\u30e1\u30fc\u30eb\u901a\u77e5\u3092\u9001\u4fe1\u3059\u308bLambda\u95a2\u6570\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<h4>Lambda\u95a2\u6570\u30b3\u30fc\u30c9 (Python)<\/h4>\n<pre class=\"lang:default decode:true\" title=\"log-notification-processor.py\">\nimport base64\nimport json\nimport gzip\nimport os\nimport boto3\nimport re\n\ndef lambda_handler(event, context):\n    # \u30c6\u30b9\u30c8\u5b9f\u884c\u6642\u306e\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\n    if 'awslogs' not in event:\n        return {'statusCode': 200, 'body': 'Test execution - no awslogs data'}\n\n    try:\n        # CloudWatch Logs\u304b\u3089\u306e\u5727\u7e2e\u30c7\u30fc\u30bf\u3092\u30c7\u30b3\u30fc\u30c9\n        compressed_payload = base64.b64decode(event['awslogs']['data'])\n        uncompressed_payload = gzip.decompress(compressed_payload)\n        data_json = json.loads(uncompressed_payload)\n    except Exception as e:\n        print(f\"\u30c7\u30fc\u30bf\u30c7\u30b3\u30fc\u30c9\u30a8\u30e9\u30fc: {e}\")\n        return {'statusCode': 400, 'body': f'Decode error: {str(e)}'}\n\n    # \u30ed\u30b0\u30a4\u30d9\u30f3\u30c8\u5168\u4f53\u3092\u53d6\u5f97\n    log_events = data_json[\"logEvents\"]\n\n    # \u5404\u30ed\u30b0\u30a4\u30d9\u30f3\u30c8\u306b\u5bfe\u3057\u3066\u51e6\u7406\u3092\u5b9f\u884c\n    for log_event in log_events:\n        try:\n            sns = boto3.client('sns')\n\n            # \u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u53d6\u5f97\n            message_content = log_event['message']\n\n            # JSON\u30d1\u30bf\u30fc\u30f3\u3092\u62bd\u51fa\u3059\u308b\u305f\u3081\u306e\u6b63\u898f\u8868\u73fe\n            json_pattern = r'\\{.*\\}'\n            match = re.search(json_pattern, message_content)\n\n            if match:\n                # JSON\u90e8\u5206\u3092\u62bd\u51fa\n                json_str = match.group(0)\n                try:\n                    # JSON\u3092\u30d1\u30fc\u30b9\n                    json_obj = json.loads(json_str)\n                    # \u65e5\u672c\u8a9e\u3092\u6b63\u3057\u304f\u8868\u793a\u3059\u308b\u305f\u3081\u306b\u518d\u5ea6JSON\u306b\u5909\u63db\n                    formatted_json = json.dumps(json_obj, ensure_ascii=False, indent=2)\n\n                    # \u5143\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u304b\u3089JSON\u90e8\u5206\u3092\u7f6e\u63db\n                    message_content = message_content.replace(json_str, formatted_json)\n                except json.JSONDecodeError:\n                    # JSON\u306e\u30d1\u30fc\u30b9\u306b\u5931\u6557\u3057\u305f\u5834\u5408\u306f\u5143\u306e\u307e\u307e\n                    pass\n\n            message = \"\u62c5\u5f53\u8005\u69d8\" + \"\\n\" + \"\\n\"\n            message = message + message_content + \"\\n\" + \"\\n\"\n\n            print(message)\n\n            # SNS\u30c8\u30d4\u30c3\u30af\u306b\u901a\u77e5\u3092\u767a\u884c\n            publishResponse = sns.publish(\n                TopicArn = os.environ['SNS_TOPIC_ARN'],\n                Message = message,\n                Subject = os.environ['ALARM_SUBJECT']\n            )\n            print(publishResponse)\n\n        except Exception as e:\n            # \u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u305f\u5834\u5408\u306f\u30ed\u30b0\u306b\u51fa\u529b\n            print(e)\n\n    return {'statusCode': 200, 'body': 'Processing completed'}\n<\/pre>\n<h3>Step 4: CloudWatch\u30ed\u30b0\u306e\u6e96\u5099<\/h3>\n<p>\u30c6\u30b9\u30c8\u7528\u306e\u30ed\u30b0\u3092\u51fa\u529b\u3059\u308b\u30b5\u30f3\u30d7\u30eb\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\" title=\"log-sample-app.py\">\nimport json\nimport logging\nimport time\nfrom datetime import datetime\n\n# Lambda\u74b0\u5883\u7528\u306e\u30ed\u30ac\u30fc\u8a2d\u5b9a\nlogger = logging.getLogger()\nlogger.setLevel(logging.INFO)\n\ndef output_log(message, notification_flag=False, log_level=\"INFO\"):\n    log_data = {\n        \"logLevel\": log_level,\n        \"timestamp\": datetime.now().isoformat(),\n        \"message\": {\n            \"message\": message\n        },\n        \"notification_flag\": \"true\" if notification_flag else \"false\"\n    }\n    log_json = json.dumps(log_data, ensure_ascii=False, indent=4)\n\n    if log_level == \"ERROR\":\n        logger.error(log_json)\n    else:\n        logger.info(log_json)\n\ndef lambda_handler(event, context):\n    print(\"Lambda\u95a2\u6570\u304c\u958b\u59cb\u3055\u308c\u307e\u3057\u305f\")\n\n    # \u901a\u5e38\u30ed\u30b0\uff08\u691c\u77e5\u306a\u3057\uff09\n    output_log(\"\u30b7\u30b9\u30c6\u30e0\u6b63\u5e38\u7a3c\u50cd\u4e2d\", False, \"INFO\")\n\n    # \u30a8\u30e9\u30fc\u30ed\u30b0\uff08\u691c\u77e5\u3042\u308a\uff09\n    output_log(\"\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u63a5\u7d9a\u306b\u5931\u6557\u3057\u307e\u3057\u305f\", True, \"ERROR\")\n\n    # \u901a\u5e38\u30ed\u30b0\uff08\u691c\u77e5\u306a\u3057\uff09\n    output_log(\"\u30d0\u30c3\u30c1\u51e6\u7406\u5b8c\u4e86\", False, \"INFO\")\n\n    print(\"Lambda\u95a2\u6570\u304c\u5b8c\u4e86\u3057\u307e\u3057\u305f\")\n    return {'statusCode': 200}\n<\/pre>\n<h3>Step 5: \u30b5\u30d6\u30b9\u30af\u30ea\u30d7\u30b7\u30e7\u30f3\u30d5\u30a3\u30eb\u30bf\u30fc\u306e\u8a2d\u5b9a<\/h3>\n<h4>Lambda\u95a2\u6570\u306bCloudWatch Logs\u304b\u3089\u306e\u5b9f\u884c\u6a29\u9650\u3092\u4ed8\u4e0e<\/h4>\n<pre class=\"lang:default decode:true\">\naws lambda add-permission \\\n  --function-name log-notification-processor \\\n  --statement-id allow-cloudwatch-logs \\\n  --action lambda:InvokeFunction \\\n  --principal logs.amazonaws.com \\\n  --source-arn \"arn:aws:logs:ap-northeast-1:YOUR_ACCOUNT_ID:log-group:\/aws\/lambda\/log-sample-app:*\"\n<\/pre>\n<p>Lambda\u95a2\u6570\u306elog-notification-processor\u306bCloudWatch Logs\u306e\u30c8\u30ea\u30ac\u30fc\u304c\u8a2d\u5b9a\u3055\u308c\u307e\u3059\u3002<br \/>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2025\/11\/lambda-trg.png\"><img decoding=\"async\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2025\/11\/lambda-trg-1024x472.png\" alt=\"\" \/><\/a><\/p>\n<h4>\u30b5\u30d6\u30b9\u30af\u30ea\u30d7\u30b7\u30e7\u30f3\u30d5\u30a3\u30eb\u30bf\u30fc\u4f5c\u6210<\/h4>\n<pre class=\"lang:default decode:true\">\naws logs put-subscription-filter \\\n  --log-group-name \"\/aws\/lambda\/log-sample-app\" \\\n  --filter-name \"notification-filter\" \\\n  --filter-pattern '{ $.notification_flag = true }' \\\n  --destination-arn \"arn:aws:lambda:ap-northeast-1:YOUR_ACCOUNT_ID:function:log-notification-processor\"\n<\/pre>\n<p>\u30ed\u30b0\u30b0\u30eb\u30fc\u30d7\uff1a\/aws\/lambda\/log-sample-app \u306b\u6761\u4ef6\u300cnotification_flag = true\u300d\u306b\u4e00\u81f4\u3059\u308b\u30ed\u30b0\u306e\u307f\u3092Lambda\u95a2\u6570\u306b\u9001\u4fe1\u3059\u308b\u30d5\u30a3\u30eb\u30bf\u30fc\u304c\u8a2d\u5b9a\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">\n{ $.notification_flag = true } \u306f\u3001\u30ed\u30b0\u30e1\u30c3\u30bb\u30fc\u30b8\u3092JSON\u3068\u3057\u3066\u89e3\u6790\u3057\u3001notification_flag\u30d5\u30a3\u30fc\u30eb\u30c9\u304ctrue\u306e\u5834\u5408\u306b\u30de\u30c3\u30c1\u3057\u307e\u3059\u3002\n\n\/\/ \u2705 \u30de\u30c3\u30c1\u3059\u308b\uff08Lambda\u95a2\u6570\u304c\u5b9f\u884c\u3055\u308c\u308b\uff09\n{\"message\": \"\u30a8\u30e9\u30fc\u767a\u751f\", \"notification_flag\": true}\n\n\/\/ \u274c \u30de\u30c3\u30c1\u3057\u306a\u3044\uff08Lambda\u95a2\u6570\u306f\u5b9f\u884c\u3055\u308c\u306a\u3044\uff09\n{\"message\": \"\u6b63\u5e38\u51e6\u7406\", \"notification_flag\": false}\n{\"message\": \"\u901a\u5e38\u30ed\u30b0\"}\n<\/pre>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2025\/11\/subscription-filter.png\"><img decoding=\"async\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2025\/11\/subscription-filter-1024x198.png\" alt=\"\" \/><\/a>\n<h3>Step 6: \u52d5\u4f5c\u30c6\u30b9\u30c8<\/h3>\n<p>\u30b5\u30f3\u30d7\u30eb\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u884c\u3057\u3066\u52d5\u4f5c\u78ba\u8a8d\uff01<\/p>\n<ol>\n<li>AWS\u30b3\u30f3\u30bd\u30fc\u30eb\u3067CloudWatch Logs\u3092\u958b\u304f<\/li>\n<li>\u30ed\u30b0\u30b0\u30eb\u30fc\u30d7 <code>\/aws\/lambda\/sample-app<\/code> \u3092\u78ba\u8a8d<\/li>\n<li>\u30ed\u30b0\u304c\u51fa\u529b\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u3092\u78ba\u8a8d\n<pre class=\"lang:default decode:true\">\n2025-11-28T23:41:10.032Z Lambda\u95a2\u6570\u304c\u958b\u59cb\u3055\u308c\u307e\u3057\u305f\n2025-11-28T23:41:10.032Z [INFO] 2025-11-28T23:41:10.032Z 7985da0d-2f59-46ac-8e58-e2f3b5f6b4b1 { \"logLevel\": \"INFO\", \"timestamp\": \"2025-11-28T23:41:10.032627\", \"message\": { \"message\": \"\u30b7\u30b9\u30c6\u30e0\u6b63\u5e38\u7a3c\u50cd\u4e2d\" }, \"notification_flag\": \"false\" }\n2025-11-28T23:41:10.032Z [ERROR] 2025-11-28T23:41:10.032Z 7985da0d-2f59-46ac-8e58-e2f3b5f6b4b1 { \"logLevel\": \"ERROR\", \"timestamp\": \"2025-11-28T23:41:10.032771\", \"message\": { \"message\": \"\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u63a5\u7d9a\u306b\u5931\u6557\u3057\u307e\u3057\u305f\" }, \"notification_flag\": \"true\" }\n2025-11-28T23:41:10.032Z [INFO] 2025-11-28T23:41:10.032Z 7985da0d-2f59-46ac-8e58-e2f3b5f6b4b1 { \"logLevel\": \"INFO\", \"timestamp\": \"2025-11-28T23:41:10.032828\", \"message\": { \"message\": \"\u30d0\u30c3\u30c1\u51e6\u7406\u5b8c\u4e86\" }, \"notification_flag\": \"false\" }\n2025-11-28T23:41:10.032Z Lambda\u95a2\u6570\u304c\u5b8c\u4e86\u3057\u307e\u3057\u305f\n<\/pre>\n<\/li>\n<\/ol>\n<h4>\u30e1\u30fc\u30eb\u901a\u77e5\u306e\u78ba\u8a8d<\/h4>\n<p>notification_flag \u304c true \u306e\u30ed\u30b0\u306e\u307f\u30e1\u30fc\u30eb\u306b\u8a18\u8f09\u3055\u308c\u3066\u901a\u77e5\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2025\/11\/error-mail.png\"><img decoding=\"async\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2025\/11\/error-mail.png\" alt=\"\" \/><\/a>\n<p><a id=\"vs\"><\/a><\/p>\n<h2>\u30b5\u30d6\u30b9\u30af\u30ea\u30d7\u30b7\u30e7\u30f3\u30d5\u30a3\u30eb\u30bf\u30fc vs CloudWatch\u30a2\u30e9\u30fc\u30e0<\/h2>\n<p>\u30ed\u30b0\u76e3\u8996\u306b\u306f2\u3064\u306e\u30a2\u30d7\u30ed\u30fc\u30c1\u304c\u3042\u308a\u307e\u3059\u3002\u8981\u4ef6\u306b\u5fdc\u3058\u3066\u9069\u5207\u306a\u65b9\u5f0f\u3092\u9078\u629e\u3059\u308b\u3053\u3068\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<h3>\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u6bd4\u8f03<\/h3>\n<p><strong>\u30b5\u30d6\u30b9\u30af\u30ea\u30d7\u30b7\u30e7\u30f3\u30d5\u30a3\u30eb\u30bf\u30fc\u65b9\u5f0f:<\/strong><\/p>\n<pre><code>CloudWatch Logs \u2192 Subscription Filter \u2192 Lambda \u2192 SNS \u2192 Email<\/code><\/pre>\n<p><strong>CloudWatch\u30a2\u30e9\u30fc\u30e0\u65b9\u5f0f:<\/strong><\/p>\n<pre><code>CloudWatch Logs \u2192 Metric Filter \u2192 CloudWatch Alarm \u2192 SNS \u2192 Email<\/code><\/pre>\n<h3>\u6a5f\u80fd\u6bd4\u8f03\u8868<\/h3>\n<table>\n<thead>\n<tr>\n<th>\u9805\u76ee<\/th>\n<th>\u30b5\u30d6\u30b9\u30af\u30ea\u30d7\u30b7\u30e7\u30f3\u30d5\u30a3\u30eb\u30bf\u30fc<\/th>\n<th>CloudWatch\u30a2\u30e9\u30fc\u30e0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u6027<\/strong><\/td>\n<td>\u5373\u5ea7\uff08\u79d2\u5358\u4f4d\uff09<\/td>\n<td>\u9045\u5ef6\u3042\u308a\uff08\u5206\u5358\u4f4d\uff09<\/td>\n<\/tr>\n<tr>\n<td><strong>\u901a\u77e5\u5185\u5bb9<\/strong><\/td>\n<td>\u500b\u5225\u30ed\u30b0\u306e\u8a73\u7d30\u60c5\u5831<\/td>\n<td>\u96c6\u8a08\u60c5\u5831\u306e\u307f<\/td>\n<\/tr>\n<tr>\n<td><strong>\u30e1\u30fc\u30eb\u672c\u6587<\/strong><\/td>\n<td>\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u53ef\u80fd<\/td>\n<td>\u5b9a\u578b\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u307f<\/td>\n<\/tr>\n<tr>\n<td><strong>\u30ed\u30b0\u8a73\u7d30\u53d6\u5f97<\/strong><\/td>\n<td>\u25cb\uff08\u30ed\u30b0\u30b0\u30eb\u30fc\u30d7\u3001\u30b9\u30c8\u30ea\u30fc\u30e0\u3001\u30e1\u30c3\u30bb\u30fc\u30b8\u7b49\uff09<\/td>\n<td>\u00d7\uff08\u30a2\u30e9\u30fc\u30e0\u60c5\u5831\u306e\u307f\uff09<\/td>\n<\/tr>\n<tr>\n<td><strong>\u8a2d\u5b9a\u306e\u8907\u96d1\u3055<\/strong><\/td>\n<td>\u9ad8\uff08Lambda\u95a2\u6570\u304c\u5fc5\u8981\uff09<\/td>\n<td>\u4f4e\uff08\u8a2d\u5b9a\u306e\u307f\uff09<\/td>\n<\/tr>\n<tr>\n<td><strong>\u30b3\u30b9\u30c8<\/strong><\/td>\n<td>Lambda\u5b9f\u884c\u6599\u91d1 + SNS<\/td>\n<td>\u30e1\u30c8\u30ea\u30af\u30b9\u30d5\u30a3\u30eb\u30bf\u30fc + \u30a2\u30e9\u30fc\u30e0 + SNS<\/td>\n<\/tr>\n<tr>\n<td><strong>\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u6027<\/strong><\/td>\n<td>\u9ad8\uff08\u4efb\u610f\u306e\u51e6\u7406\u53ef\u80fd\uff09<\/td>\n<td>\u4f4e\uff08\u95be\u5024\u30d9\u30fc\u30b9\u306e\u307f\uff09<\/td>\n<\/tr>\n<tr>\n<td><strong>\u901a\u77e5\u983b\u5ea6\u5236\u5fa1<\/strong><\/td>\n<td>Lambda\u5185\u3067\u5b9f\u88c5\u53ef\u80fd<\/td>\n<td>\u30a2\u30e9\u30fc\u30e0\u8a2d\u5b9a\u3067\u5236\u5fa1<\/td>\n<\/tr>\n<tr>\n<td><strong>\u8907\u6570\u6761\u4ef6\u5224\u5b9a<\/strong><\/td>\n<td>Lambda\u5185\u3067\u67d4\u8edf\u306b\u5b9f\u88c5<\/td>\n<td>\u8907\u6570\u30a2\u30e9\u30fc\u30e0\u304c\u5fc5\u8981<\/td>\n<\/tr>\n<tr>\n<td><strong>\u969c\u5bb3\u6642\u306e\u5f71\u97ff<\/strong><\/td>\n<td>Lambda\u969c\u5bb3\u3067\u901a\u77e5\u505c\u6b62<\/td>\n<td>CloudWatch\u30b5\u30fc\u30d3\u30b9\u4f9d\u5b58<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><a id=\"matome\"><\/a><\/p>\n<h2>\u307e\u3068\u3081<\/h2>\n<p>CloudWatch\u30b5\u30d6\u30b9\u30af\u30ea\u30d7\u30b7\u30e7\u30f3\u30d5\u30a3\u30eb\u30bf\u30fc\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u4ee5\u4e0b\u304c\u51fa\u6765\u307e\u3057\u305f\u3002<\/p>\n<ul>\n<li>\u30ed\u30b0\u306e\u6761\u4ef6\u4ed8\u304d\u76e3\u8996\uff08notification_flag=true\u306e\u307f\uff09<\/li>\n<li>\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u3067\u306e\u30e1\u30fc\u30eb\u901a\u77e5<\/li>\n<li>\u65e5\u672c\u6642\u9593\u3067\u306e\u901a\u77e5<\/li>\n<li>\u69cb\u9020\u5316\u3055\u308c\u305f\u30e1\u30fc\u30eb\u672c\u6587<\/li>\n<\/ul>\n<p>\u3053\u306e\u4ed5\u7d44\u307f\u306b\u3088\u308a\u3001\u91cd\u8981\u306a\u30ed\u30b0\u306e\u307f\u3092\u52b9\u7387\u7684\u306b\u76e3\u8996\u3057\u3001\u8fc5\u901f\u306a\u5bfe\u5fdc\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>\u5fdc\u7528\u4f8b<\/h2>\n<ul>\n<li>\u30a8\u30e9\u30fc\u30ec\u30d9\u30eb\u5225\u306e\u901a\u77e5\u5148\u5909\u66f4<\/li>\n<li>Slack\u306a\u3069\u4ed6\u306e\u901a\u77e5\u30c1\u30e3\u30cd\u30eb\u3068\u306e\u9023\u643a<\/li>\n<li>\u30ed\u30b0\u306e\u96c6\u8a08\u30fb\u5206\u6790\u6a5f\u80fd\u306e\u8ffd\u52a0<\/li>\n<li>\u901a\u77e5\u983b\u5ea6\u306e\u5236\u5fa1\uff08\u540c\u3058\u30a8\u30e9\u30fc\u306e\u91cd\u8907\u901a\u77e5\u9632\u6b62\uff09<\/li>\n<\/ul>\n<h2>\u6ce8\u610f\u70b9<\/h2>\n<ul>\n<li>Lambda\u95a2\u6570\u306e\u5b9f\u884c\u6642\u9593\u3068\u30b3\u30b9\u30c8\u3092\u8003\u616e<\/li>\n<li>SNS\u306e\u9001\u4fe1\u5236\u9650\u306b\u6ce8\u610f<\/li>\n<li>\u30ed\u30b0\u306e\u91cf\u304c\u591a\u3044\u5834\u5408\u306f\u30d5\u30a3\u30eb\u30bf\u30fc\u30d1\u30bf\u30fc\u30f3\u306e\u6700\u9069\u5316\u304c\u91cd\u8981<\/li>\n<li>\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u4e0a\u3001\u6a5f\u5bc6\u60c5\u5831\u3092\u30ed\u30b0\u306b\u542b\u3081\u306a\u3044\u3088\u3046\u6ce8\u610f<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u306f\u3058\u3081\u306b CloudWatch\u30ed\u30b0\u306b\u51fa\u529b\u3055\u308c\u308b\u30ed\u30b0\u306e\u4e2d\u3067\u3001\u7279\u5b9a\u306e\u6761\u4ef6\uff08\u4f8b\u3048\u3070\u3001\u901a\u77e5\u3059\u308b\u30d5\u30e9\u30b0=true\uff09\u3092\u6e80\u305f\u3057\u305f\u5834\u5408\u306e\u307f\u3001SNS\u3092\u901a\u3058\u3066\u62c5\u5f53\u8005\u306b\u30e1\u30fc\u30eb\u901a\u77e5\u3092\u9001\u308b\u4ed5\u7d44\u307f\u3092\u3084\u3063\u3066\u307f\u307e\u3057\u305f\u3002 \u76ee\u6b21 \u4eca\u56de\u306e\u69cb\u6210 \u3084\u3063\u3066\u307f\u3088\u3046\uff01&#8230;<\/p>\n","protected":false},"author":212,"featured_media":29767,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"ja","_original_post":"https:\/\/www.skyarch.net\/blog\/?p=29743","footnotes":""},"categories":[1022,20],"tags":[],"class_list":{"0":"post-29743","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-amazon-cloudwatch","8":"category-aws","9":"ja"},"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/29743","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/users\/212"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/comments?post=29743"}],"version-history":[{"count":19,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/29743\/revisions"}],"predecessor-version":[{"id":30041,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/29743\/revisions\/30041"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/media\/29767"}],"wp:attachment":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/media?parent=29743"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/categories?post=29743"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/tags?post=29743"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}