Call the AWS Lambda function only once, at a given time

I want to be able to set the time to call the AWS Lambda function, then call this function if and only if. For example, I want my lambda function to execute at 21:00 on December 19, 2017. I do not want her to repeat, I do not want her to call now, only at 21:00 on the 19th.

I understand that CloudWatch provides scheduled events, and I thought that when you enter the time to schedule this reminder, a scheduled CloudWatch calendar is created at this time, so if you plan on having it at 8:22 p.m. to run at 9 p.m. it will be 38 minutes), then it calls the lambda function at 9 pm, after which it deletes the event scheduled by CloudWatch. My problem is that when the Scheduled Event CloudWatch event is raised, it runs correctly, then at the specified interval.

Any other ideas would be appreciated, as I cannot come up with another solution. Thanks in advance!

+10
source share
3 answers

You can schedule a lambda event using the following syntax:

cron(Minutes Hours Day-of-month Month Day-of-week Year)

Note : all fields are required, and the time zone is only UTC

See AWS Documentation for more information.

thanks

+12
source

Calling a lambda function through Events is an asynchronous call option. Using CloudWatchEvent to run the lambda function, we can use the cron task, but we still run into problems, because the lambda function runs several times for the same cron.PFB schedule Link: https://cloudonaut.io/your -lambda-function-might-execute exactly double-deals-with-it /

But for this you need Dynamo DB to be embedded in your account, and then make your lambda function idempotent.

0
source

You can use DynamoDB TTL to easily implement this, just do the following:

1- Place the element with TTL , the exact time when you want to execute or call the lambda function.

2- Configure DynamoDB Streams to run the lambda function on the remove event of an element.

As soon as the item / record expires, your lambda will be activated. You do not need to delete or clear anything, since the element in Dynamodb has already disappeared.

NOTE. However, this approach is easy to implement and scales very well, but one precaution should be mentioned; Using DynamoDB TTL as a scheduling mechanism cannot guarantee accurate time accuracy, as there may be a delay. Scheduled tasks are completed a couple of minutes later.

0
source

Source: https://habr.com/ru/post/1274178/