I have a requirement to invoke 2 methods x and y specified in the lambda function at different times which is triggered by AWS Cloudwatch event. Is it possible to invoke the handler for different time units by passing in different values to the event parameter ? Or else should I create another lambda handler and invoke it separately?
def lambda_handler(event , context):
"""Run main logic of the script.
This function is called by AWS to handle the request
or by __main__ when run from the command-line.
Args:
context: Lambda context instance.
Returns:
A string saying "Successful invocation" on success.
Raises:
Exception: If a problem occurs.
"""
# Set up logging
app_config = config.Config(context.aws_request_id)
x.run(app_config)
y.run(app_config)
return "Successful invocation."
Template for AWS Cloudwatch event:
Trigger:
Type: AWS::Events::Rule
Properties:
Description: !Sub "Trigger the exp-${Environment} Lambda every ${FunctionInvocationRateValue} ${FunctionInvocationRateUnit}"
Name: !Sub "exp-${Environment}"
ScheduleExpression: !Sub "rate(${FunctionInvocationRateValue} ${FunctionInvocationRateUnit})"
Targets:
- Id: !Sub "exp-${Environment}"
Arn: !GetAtt exp.Arn
Input: '{}' # No input necessary for the function to run.