简体   繁体   中英

Trigger lambda function in a certain time range from s3 upload

Currently, We are triggering our lambda function from S3 Upload. S3 upload is not time-specific, it can happen at any time.

Now we got a new requirement that we can run lambda within a certain time range only eg between 13 UTC to 20 UTC. That means if the s3 upload happened at 5 UTC, lambda will be triggered at 13 UTC.

What is the best approach to implement this change?

Any suggestions would be appreciated. Thanks in advance.

If the condition is that the upload must be done between the time range specified, then nothing special needs to be done.

If you want the upload to trigger the lambda which will only be executed once the time range is met, then you could use AWS Step Functions. Using a Wait state, a task time can delay the invocation of the lambda function. The delay can be dynamic (eg 13 UTC - current time).

The workflow can look like this:

  1. File is uploaded to S3
  2. Notification gets sent to EventBridge
  3. EventBridge starts state machine
  4. Wait state for a certain time period
  5. Lambda gets triggered once wait state is done

See:

Since the timing to trigger your Lambda function is now fixed, you can setup CloudWatch Trigger at the desired time and set the Lambda function as the source for that event rule.

Steps -

  1. Open the Functions page of the Lambda console.

  2. Choose a function

  3. Under Function overview, choose Add trigger.

  4. Set the trigger type to EventBridge (CloudWatch Events).

  5. For Rule, choose Create a new rule.

  6. Configure the remaining options and choose Add.

Rule is nothing but a cron pattern which you need to set for the desired time. Once the rule is implemented, the trigger will start according to the cron, and run the lambda function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM