I am new to AWS lambda.
Will like to seek advice from the experts here.
I understand that Lambda is activated based on a trigger.
If I wanted to send a timed http request (for example, send a http request 4 hours later),
is there any recommendations to do it.
Yes, you can configure scheduled AWS Lambda Triggers using Cloudwatch.
Tutorial: Schedule AWS Lambda Functions Using CloudWatch Events
To create a rule using the console
Open the CloudWatch console at https://console.aws.amazon.com/cloudwatch/
In the navigation pane, choose Events, Create rule.
For Event Source, do the following:
a. Choose Schedule.
b. Choose Fixed rate of and specify the schedule interval (for example, 5 minutes).
For Targets, choose Add target, Lambda function.
For Function, select the Lambda function that you created.
Choose Configure details.
For Rule definition, type a name and description for the rule.
Choose Create rule.
Related
Is it possible to create an EventBrisge rule which can be scheduled to run at a certain time of day and call an API as a custom target?
It seems as though a schedule can be setup for targets if they are AWS or Partner services, but not if they are custom configured endpoints.
All I want to do is setup a daily routine to call an endpoint so it can perform a daily cleanup task. If there is a better way, can someone suggest it, please?
EDIT
Under EventBridge I have created a Connection which points at the OAuth endpoint and then an API Destination which points at the API endpoint I want to invoke on a daily basis.
I have then created an event bus and a rule but when I try to set the Schedule option on the rule it shows a warning which states:
Schedule rule is not supported when custom or partner event bus is
selected
I believe this means that I cannot invoke my own API endpoint with EventBridge without going through a Lambda. Am I wrong?
Create your scheduled rule on the *default bus* using the Create Rule interface. It appears you are right that the brand-new EventBridge Scheduler console interface does not yet (?) support API Destinations.
The "create rule" scheduling supports cron-type use cases like yours. EventBridge Scheduler adds new functionality like ad-hoc scheduling of one-off events, flexible time windows, and TZ-aware scheduling.
I have a workflow where I need to pass in some information that would be stored for a period of time, and then sends off a trigger after a scheduled period of time with the same information.
I considered using a TTL on a dynamo db table, but I was wondering if I could use cloudwatch events for this since it seems ideal as it has cron expressions for cloudwatch rules.
I know I can setup a cloudwatch rule to trigger say every 15 minutes, but how do I setup cloudwatch such that only my custom information gets picked up by this rule and I can pass some information into this event so that when the trigger gets sent to the target, my custom information is sent to the target as well?
DynamoDB TTL is a bad fit as you don’t get a ton of granularity.
You can use the CloudWatch events PutEvent api to put a custom event. That should get you where you want.
https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/AddEventsPutEvents.html
I have written some cronjobs in my django app and I want to schedule these jobs using AWS Lambda service. Can someone please recommend a good approach to get this done?
I will answer this based on the question's topic rather than the body, since I am not sure what the OP means with "I want to schedule these jobs using AWS Lambda".
If all you want is trigger your Lambda function based in a cronjob, you can use CloudWatch Events to achieve this. You can specify regular cron expressions or some built-in expressions that AWS makes available, like rate(1 min) will run your function every minute. You can see how to trigger a Lambda function via CloudWatch Events on the docs. See cron/rate to see all the available options.
CloudWatch Events is only one of the many options to trigger you Lambda function. Your function can react to a whole bunch of AWS Events, including S3, SQS, SNS, API Gateway, etc. You can see the full list of events here. Just pick one that fits your needs and you are good to go.
EDIT AFTER OP'S UPDATE:
Yes, what you're looking for is CloudWatch Events. Once you have the Lambda to poll your database in place, you can just create a rule in CloudWatchEvents and have your Lambda be triggered by it. Please see the following images for guidance.
Go to CloudWatch, click on Events and choose Schedule as the Event Source
(make sure to setup your own Cron expression or select the pre-defined rate values)
On the right-hand side, choose your Lambda function accordingly.
Click on "Configure Details" when you are done, give it a name, leave the "Enabled" box checked and finally click on Create.
Go back to your Lambda function and you should see it's now triggered by CloudWatch Events (column on the left-hand side)
Your lambda is now configured properly and will execute once a day.
I have AWS lambda function written in c#, and I want to invoke that lambda function for the specific interval. This interval value is not fixed, and the user can customize this interval from the app. Any ideas on how to achieve this?
One method is to programmatically update the schedule of a CloudWatch Scheduled Rule. This works well if you have a relatively low number of schedules, but there are limits to how many schedules you can create. The default limit is 50 rules, though this can be increased to meet your needs by requesting an increase from AWS.
This is an example of creating a rule programmatically in C#, you'll need to permission your Lambda Role to update the rules, also in this doc:
https://docs.aws.amazon.com/sdk-for-net/v3/developer-guide/cloudwatch-examples-sending-events.html#create-a-scheduled-rule
try Using AWS Lambda with Amazon SQS
SQS has each URL.
user (or some API) can send request to that url.
The outline of processing is as follows
user (or some API) -> SQS -> Lambda
I have a requirement to launch a number of lambda functions on the ObjectCreated event in a number of s3 buckets. But the architecture of my application requires modularity thus, I have to create two different templates, one for my bucket creation and another for the lambdas. According to me, one way to achieve this is by using the SNS service.
SNS
we create the SNS topic in the buckets creation template and provide the ObjectCreated event to it through NotificationConfiguration property of the s3. In the lambda template we can subscribe the lambda to the above mentioned SNS topic and the lambda function will be called on the s3 ObjectCreated event.
But again the architecture does not allows using SNS.
Possible way
Is it all possible to do this without using SNS and compromising on the modularity like making two separate templates for buckets and lambdas and using their notification configuration in a third template to complete the chain.
Final Question
I can not use SNS and I want modularity, how can I call my lambda functions on the s3 event? is it even ossible with my restrictions?
thank you
You could trigger your functions straight from S3 using events in the bucket properties. http://docs.aws.amazon.com/lambda/latest/dg/with-s3-example.html
You could also use a CloudWatch Event Rule to trigger your functions. To do so:
Go to your AWs Console and select Services > CloudWatch.
Select Rules under Events on the left.
Select Create Rule.
Leave Event Pattern selected.
Select Simple Storage Service (S3) from Service Name drop down.
Select Object Level Operations from Event Type drop down.
Select Specific operation(s).
Select PutObject from drop down.
Select Specific bucket(s) by name.
Enter bucket names.
Select + Add target* on the right.
Select Lambda function to trigger.
Select Configure details at the bottom of the page.
Enter a rule name.
Finish by selecting Create rule.