Invoke AWS Lambda function only once, at a single specified future time

前端 未结 6 1498
无人共我
无人共我 2020-12-29 07:12

I want to be able to set a time to invoke an AWS Lambda function, then have that function be invoked then and only then. For example, I want my Lambda function to run at 9:0

6条回答
  •  离开以前
    2020-12-29 07:46

    You can schedule a step function which can wait until a specific point in time before invoking the lambda with an arbitrary payload.

    https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-wait-state.html

    Something like this

    const stepFunctions = new AWS.StepFunctions()
    const payload = {
        stateMachineArn: process.env.SCHEDULED_LAMBDA_SF_ARN,
        name: `${base64.encode(email)}-${base64.encode(timestamp)}`, // Dedupe key
        input: JSON.stringify({
          timestamp,
          lambdaName: 'myLambdaName',
          lambdaPayload: {
            email,
            initiatedBy
          },
        }),
      }
    await stepFunctions.startExecution(payload).promise()
    

提交回复
热议问题