Last active
November 26, 2016 14:26
-
-
Save 328/0a518845e918ecc31c544b0a542cc94b to your computer and use it in GitHub Desktop.
Serverless Frameworkのプラクティス。Lambda上で環境変数を読み込んで、SlackにPostするやつを作る
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
function slack_post(message) { | |
var Slack = require('slack-node'); | |
var slack = new Slack(); | |
slack.setWebhook(process.env.WEBHOOK_URL); | |
slack.webhook({ | |
channel: process.env.CHANNEL, | |
username: process.env.USERNAME, | |
text: message, | |
}, function(err, response) { | |
console.log(response); | |
}); | |
}; | |
module.exports.hello = (event, context, callback) => { | |
slack_post("てすとめっせーじですよん"); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
name: sample, | |
"version": "0.0.0", | |
description: "", | |
devDependencies: { | |
slack-node: "" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service: slack-post | |
provider: | |
name: aws | |
runtime: nodejs4.3 | |
stage: dev | |
region: ap-northeast-1 | |
package: | |
include: | |
- node_modules/** | |
functions: | |
cron: | |
handler: handler.hello | |
environment: | |
WEBHOOK_URL: 'https://hooks.slack.com/services/12341234/12341234/1234123412341234' | |
CHANNEL: '#general' | |
USERNAME: 'LambdaNotification' | |
events: | |
- schedule: rate(1 minute) | |
plugins: | |
- serverless-run-function-plugin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment