AWS-API,CODECOMMIT

こんばんは、
最近加齢臭と口臭がキツイなと思うこの頃です。

いつか書かなきゃ忘れてしまうので、
AWSでうんたらかんたらやってた時に難儀した事を書きます。

aws-api

AWSのCODECOMMITからイベントの時に送られるJSONに
commentIDってのがあったんですが、commentの中身をどう取り出そうってなりました。
Lambda(node.js)でプログラム書いていたのでとりあえず、
APIリファレンスを読みます。
0729素材
英語しかない。。。英語苦手なのに、
まあ頑張って探すと、
スクリーンショット 2018-07-29 22.40.28.png
こんな感じのAWS SDK for JavaScriptにたどり着きました。
(他にもJava、Python、C++などのもあります。)
ここで、getcommentっていうそれらしきものがありました。
スクリーンショット 2018-07-29 22.44.07
あとは、書いてくだけで、いいはず。。。
んで出来たのがこれ、

const https = require('https');
const querystring = require('querystring');
//AWS-SDK、CodeCommitAPIの呼び出し方
const codecommit = new AWS.CodeCommit();
exports.handler = function(event, context) {
console.log('Received event:', JSON.stringify(event, null, 2));
 〜〜〜〜〜
//getCommentに渡すidの設定
params_comment.commentId=event.detail.commentId;
//getComment実行して中で処理を行う
//※外だと出来ないから注意
codecommit.getComment(params_comment, function(err, data) {
if (err){
console.log(err, err.stack); // an error occurred
}else{
console.log(data);
var content = data.comment.content;
chatwork_info = "[info]"+content+"[/info]";
post_message = user_name+"が"+user_action+"しました。\n"+chatwork_info;
post_chatwork(post_message);
}// successful response
});
}
 〜〜〜〜〜
 
};
//CodeCommitAPIに渡すパラメータ宣言
var params_comment = {
commentId: null,
};
var params_pullreq = {
pullRequestId: null
};
view raw gistfile1.txt hosted with ❤ by GitHub

あれ、動かない。。。。
そうかaws-sdkを呼び出してないのか、
ここが案外時間食いました、、
基本的な事だからどこにも書いてない、、、、
最終的に出来たのがこれ、
const https = require('https');
const querystring = require('querystring');
//AWS-SDK、CodeCommitAPIの呼び出し方
const AWS = require('aws-sdk');
const codecommit = new AWS.CodeCommit();
exports.handler = function(event, context) {
console.log('Received event:', JSON.stringify(event, null, 2));
 〜〜〜〜〜
//getCommentに渡すidの設定
params_comment.commentId=event.detail.commentId;
//getComment実行して中で処理を行う
//※外だと出来ないから注意
codecommit.getComment(params_comment, function(err, data) {
if (err){
console.log(err, err.stack); // an error occurred
}else{
console.log(data);
var content = data.comment.content;
chatwork_info = "[info]"+content+"[/info]";
post_message = user_name+"が"+user_action+"しました。\n"+chatwork_info;
post_chatwork(post_message);
}// successful response
});
}
 〜〜〜〜〜
 
};
//CodeCommitAPIに渡すパラメータ宣言
var params_comment = {
commentId: null,
};
var params_pullreq = {
pullRequestId: null
};
view raw gistfile1.txt hosted with ❤ by GitHub

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

この1行を探すのにも時間食ったのは萎えました。
調べ方悪いのかな。。。

以上です。
ちゃんと読んでくれた方ありがとうござます。

Leave a comment

Design a site like this with WordPress.com
Get started
search previous next tag category expand menu location phone mail time cart zoom edit close