{"id":584,"date":"2019-10-25T06:44:10","date_gmt":"2019-10-24T21:44:10","guid":{"rendered":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2019\/10\/25\/integrate_datadog_lambda_ssm"},"modified":"2022-10-28T22:36:12","modified_gmt":"2022-10-28T13:36:12","slug":"integrate_datadog_lambda_ssm","status":"publish","type":"post","link":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2019\/10\/25\/integrate_datadog_lambda_ssm\/","title":{"rendered":"Datadog \u00d7 API Gateway \u00d7 Lambda \u00d7 AWS Systems Manager \u3067\u30d7\u30ed\u30bb\u30b9\u306e\u518d\u8d77\u52d5\u3092\u81ea\u52d5\u5316\u3059\u308b"},"content":{"rendered":"
\u76e3\u8996\u3057\u3066\u3044\u305f\u30b5\u30fc\u30d0\u30fc\u3067\u4f55\u3089\u304b\u306e\u969c\u5bb3\u304c\u767a\u751f\u3057\u305f\u969b\u306a\u3069\u306b\u3001\u53d6\u308a\u6025\u304eWeb\u30b5\u30fc\u30d0\u30fc\u3092\u81ea\u52d5\u7684\u306b\u518d\u8d77\u52d5\u3057\u305f\u3044\u3068\u3044\u3046\u30b1\u30fc\u30b9\u306f\u3088\u304f\u3042\u308b\u3053\u3068\u304b\u3068\u601d\u3046\u3002 \u4ee5\u524d\u3001\u4e0b\u8a18\u306e\u30d6\u30ed\u30b0\u30a8\u30f3\u30c8\u30ea\u30fc\u306b\u3066\u3001 Datadog \u00d7 API Gateway \u00d7 Lambda\u3067\u30d7\u30ed\u30bb\u30b9\u306e\u518d\u8d77\u52d5\u3092\u81ea\u52d5\u5316\u3059\u308b | MMM\u30d6\u30ed\u30b0<\/a> <\/p>\n \u305d\u306e\u969b\u306b\u306f\u3001 \u3068\u3044\u3046\u6d41\u308c\u3067\u3084\u3063\u3066\u307f\u308b\u3002<\/p>\n \u307e\u305a\u306f\u3001EC2\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u4f5c\u6210\u3092\u3059\u308b\u3002 <\/p>\n \u4f5c\u6210\u3057\u305f\u30ed\u30fc\u30eb\u3092EC2\u306b\u4ed8\u4e0e\u3002<\/p>\n <\/p>\n \u3010\u53c2\u8003\u3011 \u4e0b\u8a18\u306e\u3088\u3046\u306b\u8a2d\u5b9a\u3059\u308b\u3002<\/p>\n \u8a2d\u5b9a\u5f8c\u306b\u3001<\/p>\n \u3067\u30a8\u30fc\u30b8\u30a7\u30f3\u30c8\u306e\u518d\u8d77\u52d5\u3092\u884c\u3046\u3002<\/p>\n <\/p>\n <\/p>\n \u4eca\u56de\u306f\u6700\u4f4e\u9650\u306e\u5b9f\u88c5\u306b\u3057\u3066\u3044\u308b\u304c\u3001\u6210\u529f\u6642\u3084\u5931\u6557\u6642\u306b <\/p>\n <\/p>\n \u30a2\u30e9\u30fc\u30c8\u901a\u77e5\u5148\u306b\u4f5c\u6210\u3057\u305f <\/p>\n <\/p>\n \u3068\u3044\u3046\u30e1\u30ea\u30c3\u30c8\u304c\u3042\u308b\u3002 \u76e3\u8996\u3057\u3066\u3044\u305f\u30b5\u30fc\u30d0\u30fc\u3067\u4f55\u3089\u304b\u306e\u969c\u5bb3\u304c\u767a\u751f\u3057\u305f\u969b\u306a\u3069\u306b\u3001\u53d6\u308a\u6025\u304eWeb\u30b5\u30fc\u30d0\u30fc\u3092\u81ea\u52d5\u7684\u306b\u518d\u8d77\u52d5\u3057\u305f\u3044\u3068\u3044\u3046\u30b1\u30fc\u30b9\u306f\u3088\u304f\u3042\u308b\u3053\u3068\u304b\u3068\u601d\u3046\u3002\u3064\u3044\u5148\u65e5\u3082\u3001 Application Load Balancer \u304b\u3089\u306e\u30d8\u30eb\u30b9\u30c1\u30a7\u30c3\u30af\u304c\u3001 healthy \u3068 unhealthy \u3092\u7e70\u308a\u8fd4\u3059\u72b6\u6cc1\u304c\u767a\u751f\u3057\u3001 apache \u306e\u518d\u8d77\u52d5\u3067\u6b63\u5e38\u5fa9\u65e7\u3057\u305f\u3053\u3068\u304c\u3042\u3063\u305f\u3002 \u4ee5\u524d\u3001\u4e0b\u8a18\u306e\u30d6\u30ed\u30b0\u30a8\u30f3\u30c8\u30ea\u30fc\u306b\u3066\u3001 EC2\u30ce\u30fc\u30c9\u4e0a\u3067\u8d70\u3063 […]<\/p>\n","protected":false},"author":3,"featured_media":684,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[21],"tags":[277,273,399],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/584"}],"collection":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/comments?post=584"}],"version-history":[{"count":1,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/584\/revisions"}],"predecessor-version":[{"id":3288,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/584\/revisions\/3288"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/media?parent=584"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/categories?post=584"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/tags?post=584"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}
\u3064\u3044\u5148\u65e5\u3082\u3001 Application Load Balancer<\/code> \u304b\u3089\u306e\u30d8\u30eb\u30b9\u30c1\u30a7\u30c3\u30af\u304c\u3001
healthy<\/code> \u3068
unhealthy<\/code> \u3092\u7e70\u308a\u8fd4\u3059\u72b6\u6cc1\u304c\u767a\u751f\u3057\u3001
apache<\/code> \u306e\u518d\u8d77\u52d5\u3067\u6b63\u5e38\u5fa9\u65e7\u3057\u305f\u3053\u3068\u304c\u3042\u3063\u305f\u3002 <\/p>\n
EC2\u30ce\u30fc\u30c9\u4e0a\u3067\u8d70\u3063\u3066\u3044\u308b\u306f\u305a\u306enginx\u30d7\u30ed\u30bb\u30b9\u304c\u6b62\u307e\u3063\u3066\u3044\u305f\u5834\u5408\u3001\u81ea\u52d5\u3067\u518d\u8d77\u52d5\u3059\u308b<\/code> \u3068\u3044\u3046\u3053\u3068\u3092\u3084\u3063\u305f\u3002 <\/p>\n
AWS Lambda<\/code> \u304b\u3089SSH\u3067\u518d\u8d77\u52d5\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u305f\u3002
\u4eca\u56de\u306f\u3001\u305d\u306eSSH\u3067\u5b9f\u884c\u3057\u305f\u90e8\u5206\u3092\u3001 AWS Systems Manager<\/a> \u3092\u4f7f\u7528\u3057\u3066\u884c\u3063\u3066\u307f\u305f\u3044\u3068\u601d\u3046\u3002
\u4eca\u56de\u306f\u3001 <\/p>\n\n
apache<\/code> \u306e\u30d7\u30ed\u30bb\u30b9\u30c0\u30a6\u30f3\u3092
Datadog<\/code> \u3067\u691c\u77e5<\/li>\n
Datadog<\/code> \u2192
API Gateway<\/code> \u3078
Webhook<\/code> \u5b9f\u884c<\/li>\n
API Gateway<\/code> \u2192
Lambda<\/code> \u5b9f\u884c<\/li>\n
Lambda<\/code> \u304b\u3089
AWS Systems Manager<\/code> \u7d4c\u7531\u3067\u3001
apache<\/code> \u518d\u8d77\u52d5\u30b3\u30de\u30f3\u30c9\u5b9f\u884c<\/li>\n<\/ul>\n
EC2\u306e\u6e96\u5099<\/h2>\n
\u3053\u306e\u969b\u306b\u3001\u6ce8\u610f\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u306e\u306f\u3001 AWS Systems Manager<\/code> \u3092\u5b9f\u884c\u3067\u304d\u308b
IAM<\/code> \u30ed\u30fc\u30eb\u3092\u4ed8\u4e0e\u3057\u3066\u3084\u308b\u3053\u3068\u3002
\u4eca\u56de\u306f\u3001AWS \u7ba1\u7406\u30dd\u30ea\u30b7\u30fc AmazonSSMManagedInstanceCore<\/code> \u3092\u4f7f\u3063\u3066\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b\u30ed\u30fc\u30eb\u3092\u4f5c\u6210\u3001EC2\u306b\u4ed8\u4e0e\u3057\u3066\u3044\u308b\u3002<\/p>\n
\n\u30b9\u30c6\u30c3\u30d7 4: Systems Manager \u306e IAM \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u30d7\u30ed\u30d5\u30a1\u30a4\u30eb\u306e\u4f5c\u6210 - AWS Systems Manager<\/a><\/p>\napache<\/code> \u3068
Datadog<\/code> \u306e\u30a8\u30fc\u30b8\u30a7\u30f3\u30c8\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u304a\u304f\u3002<\/p>\n
apache<\/code> \u306e\u30d7\u30ed\u30bb\u30b9\u76e3\u8996\u306f\u3001\u8a2d\u5b9a\u304c\u5fc5\u8981\u306a\u305f\u3081\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3092\u30b3\u30d4\u30fc\u3001\u7de8\u96c6\u3059\u308b\u3002<\/p>\n
cp \/etc\/datadog-agent\/conf.d\/process.d\/conf.yaml.example \/etc\/datadog-agent\/conf.d\/process.d\/conf.yaml\nvi \/etc\/datadog-agent\/conf.d\/process.d\/conf.yaml<\/code><\/pre>\n
- name: httpd\n search_string: ['httpd']<\/code><\/pre>\n
systemctl restart datadog-agent<\/code><\/pre>\n
API Gateway\u3092\u4f5c\u6210<\/h2>\n
API Gateway<\/code> \u3092\u4f5c\u6210\u3059\u308b\u3002
\u624b\u9806\u7b49\u306f\u3001 \u3053\u3061\u3089<\/a> \u3068\u540c\u3058\u306a\u306e\u3067\u3001\u5272\u611b\u3002<\/p>\nLambda\u30d5\u30a1\u30f3\u30af\u30b7\u30e7\u30f3\u3092\u4f5c\u6210<\/h2>\n
Lambda<\/code> \u30d5\u30a1\u30f3\u30af\u30b7\u30e7\u30f3\u3092\u4f5c\u6210\u3059\u308b\u3002
Python 3.6<\/code> \u3067\u306e\u5b9f\u88c5\u3002<\/p>\n
import boto3\nimport logging\nimport os\n\n\nlogger = logging.getLogger()\nlogger.setLevel(logging.INFO)\n\nINSTANCE_ID = os.environ['INSTANCE_ID']\n\n\ndef lambda_handler(event, context):\n\n ssm = boto3.client('ssm')\n res = ssm.send_command(\n InstanceIds=[INSTANCE_ID],\n DocumentName="AWS-RunShellScript",\n Parameters={\n "commands": [\n "systemctl restart httpd"\n ],\n "executionTimeout": ["60"]\n },\n )\n\n if res['ResponseMetadata']['HTTPStatusCode'] != 200:\n print('FAILED to execute ssm.send_command().')\n\n return\n {\n 'message': "script completed."\n }\n<\/code><\/pre>\n
commands<\/code> \u306e\u3068\u3053\u308d\u3067\u3001
apache<\/code> \u518d\u8d77\u52d5\u30b3\u30de\u30f3\u30c9\u306e
"systemctl restart httpd"<\/code> \u3092\u6307\u5b9a\u3057\u3066\u3044\u308b\u3002
\n\u74b0\u5883\u5909\u6570\u306b\u3001\u4f5c\u6210\u3057\u305fEC2\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9ID\u3092\u8a2d\u5b9a\u3059\u308b\u3002<\/p>\nSlack<\/code> \u901a\u77e5\u306a\u3069\u3082\u8ffd\u52a0\u3057\u305f\u65b9\u304c\u3001\u904b\u7528\u3059\u308b\u969b\u306b\u306f\u4fbf\u5229\u304b\u3068\u601d\u3046\u3002<\/p>\n
Datadog\u8a2d\u5b9a<\/h2>\n
Datadog<\/code> \u30b3\u30f3\u30bd\u30fc\u30eb\u304b\u3089
Webhooks Integration<\/code> \u3092\u4f5c\u6210\u3059\u308b\u3002
\nURL\u306b\u3001\u5148\u307b\u3069\u4f5c\u6210\u3057\u305f\u3001 API Gateway<\/code> \u306eURL\u3092\u5165\u529b\u3059\u308b\u3002<\/p>\n
Datadog<\/code> \u306e\u30d7\u30ed\u30bb\u30b9\u76e3\u8996\u306e\u30a2\u30e9\u30fc\u30c8\u8a2d\u5b9a\u3059\u308b\u3002 <\/p>\n
Pick a Process<\/code> \u306b
Httpd<\/code> \u3092\u9078\u629e\u3002<\/p>\n
Webhook<\/code> \u3092\u9078\u629e\u3002<\/p>\n
\u52d5\u4f5c\u78ba\u8a8d<\/h2>\n
apache<\/code> \u3092\u505c\u6b62\u3059\u308b\u3002
\u3057\u3070\u3089\u304f\u3059\u308b\u3068\u3001 Datadog<\/code> \u3067\u30a2\u30e9\u30fc\u30c8\u304c\u3042\u304c\u308a\u3001\u305d\u306e\u5f8c\u671f\u5f85\u901a\u308a
AWS Systems Manager<\/code> \u7d4c\u7531\u3067\u3001
apache<\/code> \u518d\u8d77\u52d5\u30b3\u30de\u30f3\u30c9\u5b9f\u884c\u3055\u308c\u3066\u3001\u81ea\u52d5\u7684\u306b\u30a2\u30e9\u30fc\u30c8\u5fa9\u65e7\u307e\u3067\u52d5\u4f5c\u3057\u305f\u3002<\/p>\n
\u307e\u3068\u3081<\/h2>\n
Datadog \u00d7 API Gateway \u00d7 Lambda \u00d7 AWS Systems Manager<\/code> \u3067\u30d7\u30ed\u30bb\u30b9\u306e\u518d\u8d77\u52d5\u3092\u81ea\u52d5\u5316\u3092\u3084\u3063\u3066\u307f\u305f\u3002
Lambda<\/code> \u304b\u3089SSH\u3067\u30d7\u30ed\u30bb\u30b9\u518d\u8d77\u52d5\u3059\u308b\u65b9\u6cd5\u3068\u6bd4\u3079\u308b\u3068\u3001<\/p>\n
\n
\u624b\u9806\u3082SSH\u63a5\u7d9a\u3059\u308b\u5834\u5408\u3088\u308a\u7c21\u5358\u3060\u3063\u305f\u3002
\u969c\u5bb3\u767a\u751f\u6642\u306e\u5b9a\u578b\u7684\u306a\u30aa\u30da\u30ec\u30fc\u30b7\u30e7\u30f3\u306f\u3001\u81ea\u52d5\u5316\u3059\u308b\u3053\u3068\u3067\u3001\u30aa\u30da\u30ec\u30fc\u30b7\u30e7\u30f3\u30df\u30b9\u3082\u306a\u304f\u305b\u308b\u3068\u3044\u3046\u30e1\u30ea\u30c3\u30c8\u3082\u3042\u308b\u306e\u3067\u3001\u4eca\u5f8c\u3082\u7a4d\u6975\u7684\u306b\u884c\u3063\u3066\u3044\u304d\u305f\u3044\u3002<\/p>\n\u53c2\u8003<\/h2>\n
\n