{"id":1963,"date":"2016-10-23T14:38:12","date_gmt":"2016-10-23T05:38:12","guid":{"rendered":"https:\/\/ecpplus.net\/weblog\/?p=1963"},"modified":"2020-06-06T19:19:23","modified_gmt":"2020-06-06T10:19:23","slug":"%e5%80%a4%e3%81%ab%e5%a4%89%e6%9b%b4%e3%81%8c%e3%81%82%e3%81%a3%e3%81%9f%e6%99%82%e3%81%a0%e3%81%91slack%e3%81%ab%e9%80%9a%e7%9f%a5%e3%81%99%e3%82%8bapi%e3%82%92%e4%bd%9c%e3%81%a3%e3%81%9f","status":"publish","type":"post","link":"https:\/\/ecpplus.net\/weblog\/%e5%80%a4%e3%81%ab%e5%a4%89%e6%9b%b4%e3%81%8c%e3%81%82%e3%81%a3%e3%81%9f%e6%99%82%e3%81%a0%e3%81%91slack%e3%81%ab%e9%80%9a%e7%9f%a5%e3%81%99%e3%82%8bapi%e3%82%92%e4%bd%9c%e3%81%a3%e3%81%9f\/","title":{"rendered":"\u5024\u306b\u5909\u66f4\u304c\u3042\u3063\u305f\u6642\u3060\u3051Slack\u306b\u901a\u77e5\u3059\u308bAPI\u3092\u4f5c\u3063\u305f"},"content":{"rendered":"<p>\u30e6\u30fc\u30b6\u6570\u306a\u3069\u3092 cron \u306a\u3069\u3067\u5b9a\u671f\u7684\u306b Slack \u306b POST \u3057\u3066\u3044\u305f\u304c\u3001\u5909\u5316\u304c\u7121\u3044\u6642\u306b\u901a\u77e5\u3055\u308c\u3066\u3082\u3042\u307e\u308a\u610f\u5473\u304c\u306a\u3044\u306e\u3067\u3001\u5909\u5316\u3057\u305f\u3068\u304d\u3060\u3051 Slack \u306b\u901a\u77e5\u3059\u308b\u3001\u3068\u3044\u3046\u306e\u3092 Serverless \u3067\u4f5c\u3063\u3066\u307f\u305f\u3002<\/p>\n<h1>\u51fa\u6765\u308b\u3053\u3068<\/h1>\n<p>\u76e3\u8996\u3059\u308b\u4efb\u610f\u306e\u5024\u306b\u5909\u5316\u304c\u3042\u3063\u305f\u6642\u306b Slack \u306b\u901a\u77e5\u3057\u3066\u304f\u308c\u308b\u3002<\/p>\n<h3>\u3082\u3046\u5c11\u3057\u8a73\u7d30\u306b<\/h3>\n<p>\u76e3\u8996\u3059\u308b\u5024\u3092 API \u306b POST \u3057\u7d9a\u3051\u3001\u524d\u56de\u306e\u5024\u304b\u3089\u5909\u5316\u304c\u3042\u3063\u305f\u3089 Slack \u306b\u901a\u77e5\u3059\u308b\u3068\u3044\u3046\u30b7\u30f3\u30d7\u30eb\u306a\u3082\u306e\u3002\u4f8b\u3048\u3070\u3001<\/p>\n<ul>\n<li>\u30d5\u30a1\u30a4\u30eb\u306e <code>md5<\/code> \u30921\u6642\u9593\u304a\u304d\u306b\u53d6\u3063\u3066 API \u306b\u6295\u3052\u308c\u3070\u3001\u30d5\u30a1\u30a4\u30eb\u5185\u5bb9\u306b\u5909\u66f4\u304c\u3042\u3063\u305f\u3089\u5206\u304b\u308b\u3002<\/li>\n<li>\u30b5\u30fc\u30d3\u30b9\u306e\u767b\u9332\u4eba\u6570\u306e count \u30921\u6642\u9593\u304a\u304d\u306b\u53d6\u308c\u3070\u3001\u5909\u5316\u304c\u3042\u3063\u305f\u3068\u304d\u306b\u5206\u304b\u308b\u3002<\/li>\n<li>\u30af\u30ed\u30fc\u30ea\u30f3\u30b0\u3057\u3066\u3044\u308b\u30c7\u30fc\u30bf\u306e\u6700\u7d42\u66f4\u65b0\u65e5\u6642\u306e\u6587\u5b57\u5217\u309215\u5206\u304a\u304d\u306b\u6295\u3052\u308c\u3070\u3001\u5909\u5316\u304c\u3042\u3063\u305f\u6642\u306b\u5206\u304b\u308b\u3002<\/li>\n<\/ul>\n<p>\u306a\u3069\u3001 trivial \u306a\u30c7\u30fc\u30bf\u3092\u6c17\u8efd\u306b\u76e3\u8996\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u3002\u3068\u3044\u3046\u306e\u304c\u3053\u306e\u30b7\u30b9\u30c6\u30e0\u306e\u4e3b\u306a\u76ee\u7684\u3002<\/p>\n<p>\u3061\u3083\u3093\u3068\u4f5c\u3063\u305f\u30b7\u30b9\u30c6\u30e0\u306f\u30c7\u30fc\u30bf\u89e3\u6790\u306e\u305f\u3081\u306e\u4ed5\u7d44\u307f\u304c\u3061\u3083\u3093\u3068\u3042\u308b\u3060\u308d\u3046\u3051\u3069\u3001\u6570\u6642\u9593\u3067\u4f5c\u3063\u305f\u81ea\u5206\u7528\u30a2\u30d7\u30ea\u3068\u304b\u3060\u3068\u305d\u3046\u3044\u3046\u306e\u307e\u3067\u4f5c\u3089\u306a\u3044\u306e\u3067\u3001\u3053\u3046\u3044\u3046\u306e\u304c\u3042\u308b\u3068\u4fbf\u5229\u3060\u306a\u3068\u601d\u3063\u3066\u4f5c\u3063\u305f\u3002<\/p>\n<h1>Getting started<\/h1>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/monit.ecp.plus\/\">https:\/\/monit.ecp.plus\/<\/a><\/p>\n<p>Web \u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9\u3092\u4f5c\u3063\u305f\u306e\u3067\u3001\u3053\u308c\u3092\u4f7f\u3048\u3070\u76e3\u8996\u304c\u59cb\u3081\u3089\u308c\u308b\u3002\u5024\u3092\u5165\u529b\u3057\u3066\u4f5c\u6210\u3057\u305f\u3089\u3001 <code>curl<\/code> \u306e\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u304c\u51fa\u3066\u304f\u308b\u306e\u3067\u3001\u5024\u306e\u3068\u308a\u65b9\u3060\u3051\u81ea\u5206\u304c\u53d6\u308a\u305f\u3044\u3082\u306e\u306b\u5408\u308f\u305b\u3066\u3001 crontab \u3068\u304b\u306b\u767b\u9332\u3057\u3066\u304a\u3051\u3070OK\u3060\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>API Gateway + Lambda + DynamoDB \u3067\u4f5c\u3063\u305f\u306e\u3067\u3001\u30b5\u30fc\u30d3\u30b9\u304c\u843d\u3061\u308b\u5fc3\u914d\u3082\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<h1>GitHub<\/h1>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ecpplus.github.io\/value-changing-monitor\/\">Value changing monitor<\/a><\/p>\n<p>(<a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/github.com\/ecpplus\/value-changing-monitor\">View on GitHub<\/a>)<\/p>\n<h1>API<\/h1>\n<p>\u76e3\u8996\u3059\u308b\u30ea\u30bd\u30fc\u30b9\u306f\u306a\u3093\u3067\u3082\u826f\u3044\u306e\u3067\u3001 Resource \u3068\u3044\u3046\u3042\u307e\u308a\u306b\u62bd\u8c61\u7684\u306a\u540d\u524d\u3057\u304b\u601d\u3044\u3064\u304b\u306a\u304b\u3063\u305f\u304c\u3068\u308a\u3042\u3048\u305a\u3053\u308c\u3067\u3002<\/p>\n<ul>\n<li>POST \/resources<\/li>\n<li>PUT \/resources\/:uuid<\/li>\n<\/ul>\n<p>POST \u3067\u76e3\u8996\u5bfe\u8c61\u306e\u30ea\u30bd\u30fc\u30b9\u3092\u751f\u6210\u3057\u3001\u4ee5\u5f8c\u306f\u305d\u3053\u3067\u767a\u884c\u3055\u308c\u305f uuid \u306b\u5bfe\u3057\u3066 PUT \u3092\u3057\u3066\u3044\u304f\u3088\u3046\u306b\u3059\u308b\u3002 POST \u3059\u308b\u3068\u304d\u306b Slack \u306e Webhook \u306e\u60c5\u5831 (URL, Channel, Template) \u3092\u4ed8\u3051\u3066\u304a\u3044\u3066\u3001\u3082\u3057\u5909\u66f4\u304c\u3042\u3063\u305f\u3089\u307e\u305f POST \u3057\u3066\u4f5c\u308c\u3070\u3044\u3044\u3084\u3068\u3044\u3046\u65b9\u91dd\u306b\u3057\u305f\u3002<\/p>\n<p>\u3053\u308c\u306f <code>serverless.yml<\/code> \u306b\u66f8\u304f\u3060\u3051\u3067\u6e08\u3080\u3002<\/p>\n<p>POST \u306e\u65b9\u3092\u3001<code>createResource<\/code> \u3068\u3044\u3046 function\u540d\u306b\u3057\u3066\u3001PUT \u306e\u65b9\u3092 <code>updateResource<\/code> \u3068\u3044\u3046 function\u540d\u306b\u3057\u3066\u3001 URL \u304b\u3089 uuid \u3068\u3044\u3046\u540d\u524d\u3067\u30d1\u30e9\u30fc\u30e1\u30fc\u30bf\u3068\u3057\u3066\u53d7\u3051\u53d6\u308b\u3088\u3046\u306b\u3057\u305f\u3002<\/p>\n<p>Serverless \u3067\u3001 <code>integration<\/code> \u3092\u6307\u5b9a\u3057\u306a\u3044\u6642\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u304c\u3001\u4ee5\u524d\u306f <code>lambda<\/code> \u3060\u3063\u305f\u306e\u3060\u304c\u3001\u6700\u8fd1\u30c7\u30d5\u30a9\u30eb\u30c8\u304c <code>lambda-proxy<\/code> \u306b\u306a\u3063\u3066\u305f\u3002 API Gateway \u306e\u30de\u30c3\u30d4\u30f3\u30b0\u304c\u5909\u308f\u308b\u306e\u3067\u3001 Lambda \u5074\u3067\u5024\u306e\u53d6\u308a\u65b9\u304c\u5909\u308f\u308b\u3002 <code>lambda-proxy<\/code> \u306b\u3059\u308b\u3068\u3001 path \u304c\u3001 pathParameters \u3068\u3044\u3046\u540d\u524d\u306b\u306a\u3063\u3066\u305f\u3002<\/p>\n<pre><code class=\"language-yml line-numbers\">functions:\n  create:\n    handler: handler.createResource\n    memorySize: 128\n    integration: lambda\n    events:\n      - http:\n          path: resources\n          method: post\n\n  update:\n    handler: handler.updateResource\n    memorySize: 128\n    integration: lambda\n    events:\n      - http:\n          path: resources\/{uuid}\n          method: put\n          request:\n            parameters:\n              paths:\n                uuid: true\n<\/code><\/pre>\n<h2>DB<\/h2>\n<p>\u5024\u306f DynamoDB \u306b\u8caf\u3081\u3066\u304a\u304f\u3002 POST \u6642\u306b\u521d\u671f\u5024\u3092\u8a2d\u5b9a\u51fa\u6765\u3066\u3001\u4ee5\u5f8c\u306f <code>value<\/code> \u306e\u307f\u3092 PUT \u3057\u3066\u3044\u304f\u3002\u5909\u66f4\u304c\u3042\u3063\u305f\u6642\u306f Slack \u306b\u901a\u77e5\u3057\u3066\u3001 DynamoDB \u306e\u5024\u3092\u66f8\u304d\u63db\u3048\u308b\u3001\u3068\u3044\u3046\u30b7\u30f3\u30d7\u30eb\u306a\u3082\u306e\u3002\u3053\u308c\u306a\u3089\u66f8\u304d\u8fbc\u307f&amp;\u8aad\u307f\u8fbc\u307f\u306e\u30ad\u30e3\u30d1\u30b7\u30c6\u30a3\u30fc\u4e21\u65b91\u3067\u826f\u3044\u306e\u3067\u30011\u79d2\u9593\u306b1\u56de!\u4ee5\u5185\u306e\u30da\u30fc\u30b9\u3067\u3042\u308c\u3070\u6708\u984d$0.67\u3067\u6e08\u3080(\u5927\u4e8b)<\/p>\n<p>Key-Value Store \u3068\u3057\u3066\u3057\u304b\u4f7f\u308f\u306a\u3044\u306e\u3067\u3001AWS Console \u304b\u3089\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u3063\u305f\u3002 uuid \u3092\u6587\u5b57\u5217\u3067\u30ad\u30fc\u3068\u3057\u3066\u307f\u305f\u3002<\/p>\n<p>IAM\u306e\u8a2d\u5b9a\u306f <code>serverless.yml<\/code> \u306b\u66f8\u304f\u3060\u3051\u3067OK\u3002\u4eca\u56de\u306f\u3001 PutItem, GetItem, UpdateItem \u306e\u307f\u3092\u8a31\u53ef\u3057\u305f\u3044\u306e\u3067\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306a\u611f\u3058\u306b\u3057\u305f\u3002<\/p>\n<pre><code class=\"language-yml line-numbers\">iamRoleStatements:\n  - Effect: \"Allow\"\n    Action:\n      - \"dynamodb:PutItem\"\n      - \"dynamodb:GetItem\"\n      - \"dynamodb:UpdateItem\"\n    Resource:\n      - \"arn:aws:dynamodb:ap-northeast-1:1234567890:table\/your-awesome-table-name\"\n<\/code><\/pre>\n<h2>Domain<\/h2>\n<p>API Gateway \u306e\u30ab\u30b9\u30bf\u30e0\u30c9\u30e1\u30a4\u30f3\u304c\u672a\u3060\u306b\u3088\u304f\u5206\u304b\u3063\u3066\u304a\u3089\u305a\u3001\u5185\u90e8\u7684\u306b\u306f CloudFront \u306e\u88cf\u306b\u3044\u308b\u306e\u306b\u3001 CloudFront \u306e\u3088\u3046\u306b\u30b7\u30fc\u30e0\u30ec\u30b9\u306b\u8a3c\u660e\u66f8\u3092\u3064\u3051\u3089\u308c\u306a\u304f\u3066\u3081\u3093\u3069\u304f\u3055\u3044\u3002Let&#8217;s Encypt \u3068\u304b\u3067TLS\u8a3c\u660e\u66f8\u3092\u81ea\u5206\u3067\u4f5c\u3063\u3066\u4e0a\u3052\u3066\u307f\u3066\u3082\u3088\u3044\u3051\u308c\u3069\u3001\u697d\u3092\u3059\u308b\u305f\u3081\u306b\u524d\u306b CloudFront \u3092\u7acb\u3066\u308b\u3053\u3068\u306b\u3059\u308b\u3002\u306a\u306e\u3067\u3001\u304a\u305d\u3089\u304f AWS \u5168\u4f53\u3092\u898b\u308b\u3068\u3001 <code>\u81ea\u5206\u3067\u7acb\u3066\u305fCloudFront<\/code> -> <code>APIGateway\u306e\u5185\u90e8\u3067\u4f7f\u308f\u308c\u3066\u3044\u308bCloudFront<\/code> -> <code>APIGateway\u306e\u67d0\u304b\u306e\u7d4c\u8def<\/code> -> <code>AWSLambda<\/code> \u3068\u306a\u3063\u3066\u304a\u308a\u3001\u96fb\u6c17\u304c\u7121\u99c4\u306b\u306a\u3063\u3066\u3044\u3066\u30a8\u30b3\u3067\u306f\u306a\u3055\u305d\u3046\u3002<\/p>\n<p>API Gateway \u306e\u524d\u306b CloudFront \u3092\u7f6e\u304f\u6642\u306e\u6ce8\u610f\u70b9\u3068\u3057\u3066\u306f\u3001\u52d5\u7684\u306a\u30c7\u30fc\u30bf\u3092\u6271\u3044\u305f\u3044\u5834\u5408\u3001<\/p>\n<ul>\n<li>\u30ad\u30e3\u30c3\u30b7\u30e5\u306e TTL \u3092 0 \u306b\u3059\u308b<\/li>\n<li>\u5fc5\u8981\u306a\u30d8\u30c3\u30c0\u30fc\u304c\u3042\u3063\u305f\u3089\u8ee2\u9001\u3059\u308b( <code>Content-Type<\/code> \u3092\u8ee2\u9001\u3057\u3088\u3046\u3068\u601d\u3063\u305f\u304c\u3001JSON\u3057\u304b\u306a\u3044\u306e\u3067 <code>application\/json<\/code> \u3067\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9\u3057\u305f)<\/li>\n<li>\u5fc5\u8981\u306b\u5fdc\u3058\u3066\u3001GET, OPTION \u4ee5\u5916\u306e\u30e1\u30bd\u30c3\u30c9\u3082\u8a31\u53ef(\u8a73\u7d30\u306b\u9078\u3079\u306a\u3044\u306e\u3067\u3001\u4eca\u56de\u306f\u5168\u90e8\u306b\u306a\u3063\u305f)<\/li>\n<li>API Gateway \u5074\u306b stage\u540d\u304c\u30c9\u30e1\u30a4\u30f3\u76f4\u4e0b\u306b\u3064\u304f\u306e\u3067\u3001 CloudFront \u306e Origin Path \u3092\u305d\u3053\u306b\u8a2d\u5b9a\u3059\u308b\u3002\u4f8b\u3048\u3070 <code>\/production<\/code> \u3068\u304b\u3002<\/li>\n<\/ul>\n<p>CloudFront \u304c\u51fa\u6765\u305f\u3089\u3001Route53 \u3067 Alias \u3068\u3057\u3066\u8a2d\u5b9a\u3059\u308c\u3070\u5b8c\u4e86\u3059\u308b\u3002<\/p>\n<h2>Serverless<\/h2>\n<p>\u8a2d\u5b9a\u3092\u3057\u305f\u3089\u5f8c\u306f\u7279\u306b\u5909\u308f\u3063\u305f\u3053\u3068\u306f\u3057\u3066\u3044\u306a\u3044\u3002<br \/>\nGitHub \u306b\u8a2d\u5b9a\u8af8\u3005\u306e\u30b3\u30fc\u30c9\u3092\u4e0a\u3052\u305f\u3002 <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ecpplus.github.io\/value-changing-monitor\/\">value-changing-monitor<\/a><\/p>\n<p>\u6700\u8fd1\u30ed\u30fc\u30ab\u30eb\u3067\u306e\u958b\u767a\u306f\u3001 node-lambda \u3092\u4f7f\u3063\u3066\u3084\u3063\u3066\u3044\u305f\u304c\u3001\u30b7\u30f3\u30d7\u30eb\u306a\u3082\u306e\u306a\u3089 Serverless \u3067\u4f5c\u3063\u3066\u30c7\u30d7\u30ed\u30a4\u3057\u3066\u78ba\u8a8d\u3068\u3044\u3046\u65b9\u6cd5\u3082\u697d\u3067\u826f\u3044\u304b\u3082\u3057\u308c\u306a\u3044\u3002<\/p>\n<h2>Web interface<\/h2>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/monit.ecp.plus\/\">https:\/\/monit.ecp.plus\/<\/a><\/p>\n<p>curl \u3067 POST \u3059\u308b\u306e\u306f\u9762\u5012\u3060\u3063\u305f\u306e\u3067\u3001 mithril \u3092\u4f7f\u3063\u3066 Web interface \u3092\u4f5c\u3063\u3066\u307f\u305f\u3002\u3053\u308c\u3082\u7279\u306b\u5909\u308f\u3063\u305f\u3053\u3068\u306f\u3057\u3066\u304a\u3089\u305a\u7279\u306b\u9762\u767d\u304f\u306f\u306a\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30e6\u30fc\u30b6\u6570\u306a\u3069\u3092 cron \u306a\u3069\u3067\u5b9a\u671f\u7684\u306b Slack \u306b POST \u3057\u3066\u3044\u305f\u304c\u3001\u5909\u5316\u304c\u7121\u3044\u6642\u306b\u901a\u77e5\u3055\u308c\u3066\u3082\u3042\u307e\u308a\u610f\u5473\u304c\u306a\u3044\u306e\u3067\u3001\u5909\u5316\u3057\u305f\u3068\u304d\u3060\u3051 Slack \u306b\u901a\u77e5\u3059\u308b\u3001\u3068\u3044\u3046\u306e\u3092 Serverless \u3067\u4f5c\u3063\u3066\u307f\u305f\u3002  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2296,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[33,39],"class_list":["post-1963","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development","tag-aws","tag-javascript"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts\/1963","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/comments?post=1963"}],"version-history":[{"count":16,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts\/1963\/revisions"}],"predecessor-version":[{"id":2297,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts\/1963\/revisions\/2297"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/media\/2296"}],"wp:attachment":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/media?parent=1963"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/categories?post=1963"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/tags?post=1963"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}