Lambda Functions Invocations
There are other AWS services that can trigger the lambda function as follows.Services used to invoke lambda function Synchronously,
- Application Load balancer - ALB
- Alexa
- API Gateway
- CloudFront Distribution
- Kinesis Data firehose
- Cognito
- Amazon Lex
Immediate invocation of lambda function can be performed using the Synchronous method
Below services are used for Asynchronous invocation of the Lambda function.
- Simple Storage Service (S3)
- Simple Notification Service (SNS)
- Simple Email Service (SES)
- CloudFormation
- Cloudwatch Logs
- Cloudwatch Events
- AWS Config
- AWS Code Commit
Any execution failures or errors during Asynchronous invocation, there are two retry will be performed
Poll based invocation of lambda functions can be done using the below listed AWS services.
- Amazon Kinesis
- DynamoDB Streams
- Simple Queue Service (SQS)
Creating Cloudwatch Event Rule
We will create and configure Cloudwatch event rule in order to trigger / invoke the lambda functions.
Login to Cloudwatch Console,
On the left side, Below Events, Choose Rules
Choose Create rule, Under the Event Source, Select Schedule.
Let’s us configure the cloudwatch event rule to trigger the lambda function based on the Cron expression
The Lambda function can be triggered for the fixed rate of ‘n’ minutes or
Based on the Cron expressions. For example, Trigger every day at 1 AM (0 1 * * *)
Also read: How are Cloud Services transforming the Business World?
Next is to add the Lambda function as a Target.
Under Targets, Choose Add target, On the dropdown menu, select the preferred Lambda function,
For Function, Select the function name.
You can add multiple lambda functions under Targets, if you want to trigger all at once using the CloudWatch event rule
For Configure details, Under the Rule definition, enter a name for the rule and then provide a short description.
State should be Checked (Enabled).
Necessary permissions for the cloudwatch event rule will be automatically added to execute the Target lambda functions.
Verify The Cloud Watch Event Rule
Go to Cloudwatch Console.
Under Events, Select Rules, and then select the Event rule,
In Monitoring, Select Show metric for the rule. Based on the cron expression you can find the metrics for the event rule
And also, For every execution the lambda function logs information such as INFO or ERROR to Cloudwatch Log groups.
Hence To verify the execution of the lambda function,
In the Cloudwatch Console, Select Logs, Choose Log group
Search for the Log group of that lambda function as mentioned below,
/aws/lambda/functionname
All the executions will create a log stream and log the execution details there.
From the latest log stream we can find whether the lambda is executed successfully as per the event rule and we can find the logs for the same.
Conclusion:
You May Also Like: AWS vs Azure vs Google Cloud