LoginSignup
4
2

More than 5 years have passed since last update.

LineBotをAWS LambdaからAzure Functionsに引っ越してみる

Last updated at Posted at 2018-08-03

今回の目的

Azure Functionsの使い勝手を試してみること。
line boot awards 2018の開催も決まり、良い機会なので(本当は、たまたま時期が重なっただけ)、以前AWS Lambdaで作ったLineBotをAzure Functionsに移行してみることにした。
(特にAWS Lambdaに不便をしていたという訳ではなく、単純な知的好奇心)

検証の前提

隙間時間を利用して技術検証等を行うためマシンに依存せずに作業ができるようにブラウザオンリーで実施可能な内容としている。
(ブラウザオンリーでの開発に固執中)

個人的な結論(感想)

プロトタイピングの基盤として Azure Functions はかなり便利。
単純に動くところまでなら、Lambdaよりも設定するところが少ないのでは(要確認)。。。
個人的に今後、ハッカソン等で活用するシーンが増えそう。

試した手順

Azure Functionsで関数"HTTP trigger"を定義し、下記要領で変更したソースをブラウザ上に貼りつけて終了。

AWS_Lambda
exports.handler = function(event, context) {
    let event_data = JSON.parse(event.body);
    let reply_token = event_data.events[0].replyToken;
    console.log(reply_token);
Azure_Functions
module.exports = function (context, req) {
    let messageData = req.body.events && req.body.events[0];
    let reply_token = messageData.replyToken;
    context.log(reply_token);

参考とさせていただいた記事:Azure Functions × LINE Bot をNode.jsでやってみよう

但し、時代は進んでいるので、参考にしていた記事より簡単にモジュール追加は可能となっていた。

「プラットフォーム機能」→「コンソール」からnpm installが実行可能に!!
console.png

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2