12
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[AWS Lambda] invokeAsync ではなく invoke を使おう

Posted at

概要

掲題の通り、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, '');
    }
  });
};
12
7
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
12
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?