概要
掲題の通り、invokeAsync ではなく invoke を使う方が推奨されているよ、という話。
内容
invokeAsync のリファレンスを見ると、↓のように書かれている。
This API is deprecated. We recommend you use Invoke API (see Invoke).
なので、invoke を使うべし。
サンプルコード
invokeAsync を使った例
'use strict';
var aws = require('aws-sdk');
module.exports.invoke_hello = (event, context, callback) => {
var lambda = new aws.Lambda();
var params = {
FunctionName: "myServiceTokinaga-dev-hello",
InvokeArgs: JSON.stringify(event),
};
lambda.invokeAsync(params, function(err, data){
if(err) {
console.log("invoke error")
context.done(err, err);
} else {
console.log("invoke done")
context.done(null, '');
}
});
};
invoke を使った例
'use strict';
var aws = require('aws-sdk');
module.exports.invoke_hello = (event, context, callback) => {
var lambda = new aws.Lambda();
var params = {
FunctionName: "myServiceTokinaga-dev-hello",
InvocationType: "Event",
Payload: JSON.stringify(event),
};
lambda.invoke(params, function(err, data){
if(err) {
console.log("invoke error")
context.done(err, err);
} else {
console.log("invoke done")
context.done(null, '');
}
});
};