LoginSignup
2
4

More than 5 years have passed since last update.

AWS Lambdaからマストドンに投稿する

Posted at

準備

アクセストークンはこちらから発行しました。

コード

var request = require('request');

exports.handler = (event, context, callback) => {
    var headers = {
        "Authorization": "Bearer " + process.env.MASTODON_ACCESS
    }

    var url = "http://pawoo.net/api/v1/statuses";
    var body = 'テスト';
    var options = {
        url: url,
        method: 'POST',
        headers: headers,
        body: body
    }
    console.log('options:' + JSON.stringify(options));
    //リクエスト送信
    request(options, function (error, response, body) {
        console.log('res:' + body);
    });
    callback(null);
};

エラーハンドリングはちゃんとやりましょう。
環境変数にアクセストークンを入れてくださいね。
インスタンスのドメインも適宜変えてくださいね。

2
4
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
2
4