1
0

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 3 years have passed since last update.

Lambda 関数から Lambda 関数を呼び出す (Node.js)

Last updated at Posted at 2020-06-05

次のページを参考にしました。
AWS lambdaでハマったこと (lambdaからlambdaを呼び出す)

メインプログラム

callSample/index.js
const AWS = require('aws-sdk');
const lambda = new AWS.Lambda();
exports.handler = function(event, context) {
	console.error("*** start callSample PM 18:57 ***")
	
	const event_aa = {
    "key1": 118,
    "key2": 216,
    "key3": 314
}

const payload = JSON.stringify(event_aa)

    const params = {
        FunctionName: 'example01',
        InvocationType: 'RequestResponse',
        Payload: payload
    };
    lambda.invoke(params, function(err, data) {
        if (err) {
            context.fail(err);
        } else {
            console.error("*** check callSample PM 18:51 ***")
            context.succeed(data);
        }
    });
};

callSample.png

呼び出される関数

example01/index.js
exports.handler = async (event) => {
    // TODO implement
    console.error("***** start example01 PM 18:49 ***")
    var rvalue = {}
    rvalue['key1'] = event['key1']
    rvalue['key2'] = event['key2']
    rvalue['key3'] = event['key3']
    rvalue['message'] = 'Hello from example01'

    const response = {
        statusCode: 200,
        body: JSON.stringify(rvalue),
    };
    console.error("***** end example01 ***")
    return response;
};

example01.png

実行時には、デフォールトの roll ではなく、次のような権限を持った、ロールが必要です。

AWSLambdaFullAccess

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?