LoginSignup
0
0

More than 1 year has passed since last update.

Serverless Framework スケジュール実行で Lambda に引数を渡す方法

Posted at

serverless.ymlinput を定義することで、スケジュール実行に任意の引数を渡すことができます

# serverless.yml
events:
  - schedule:
      rate: rate(10 minutes)
      enabled: false
      input:
        sampleKey: sampleValue # Lambda に渡したい値

JavaScript の場合、handler からは以下のように値を取得することができます

// handler.ts
module.exports.hello = async event => {
  const { sampleKey } = event; // serverless.yml に定義した値を取得
};

:bulb: input 指定の詳細は Serverless Framework | Schedule を参照してください

:warning: sls invoke local では↑で定義した値は渡されない

  • sls invoke local で実行する場合 serverless.yml で定義した input は渡されないようです
  • 実装をテストしたい場合は下記コマンドを実行すると event に指定の値を渡すことができます
npx sls invoke local -f functionName --data '{"sampleKey": "sampleValue"}'

:bulb: invoke local のパラメータ詳細は Serverless Framework | AWS - Invoke Local を参照してください。

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