@peccul is peccu

(love peccu '(emacs lisp cat outdoor bicycle mac linux coffee))

AWS LambdaでLINE Notifyを叩く


トークンを環境変数 bearer に設定してください。

'use strict';
const AWS = require('aws-sdk');

const BEARER = process.env.bearer;
const MESSAGE = '通知だよー';
const API = 'https://notify-api.line.me/api/notify';

exports.handler = (event, context, callback) => {
    console.log('Received event:', event.clickType);
    var exec = require('child_process').exec;
    var command = `curl -X POST -H 'Authorization: Bearer ${BEARER}' -d 'message=${MESSAGE}' ${API}`;
    var child = exec(command, function(error) {
      if (error) {
          return callback(error);
      // Resolve with result of process
      context.done(error, 'Process complete!');

    // Log process stdout and stderr
    child.stdout.on('data', console.log);
    child.stderr.on('data', console.error);