Skip to content

Instantly share code, notes, and snippets.

@328
Last active November 26, 2016 14:26
Show Gist options
  • Save 328/0a518845e918ecc31c544b0a542cc94b to your computer and use it in GitHub Desktop.
Save 328/0a518845e918ecc31c544b0a542cc94b to your computer and use it in GitHub Desktop.
Serverless Frameworkのプラクティス。Lambda上で環境変数を読み込んで、SlackにPostするやつを作る
'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("てすとめっせーじですよん");
};
{
name: sample,
"version": "0.0.0",
description: "",
devDependencies: {
slack-node: ""
}
}
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