Search code examples
aws-lambdaaws-event-bridge

EventBridge invokes Lambda as a target


We are designing a solution which has a Lambda function as a source and another Lambda function as a target to EventBridge. I read that for the put_rule part, the RoleArn has the ARN for the role which the rule will use needs to have the permission to invoke the target Lambda function. But for Lambda we don't use IAM roles, but use resource bases policies instead.

The question is, where we are specifying the resource based policy in the code. In the RoleArn? And what's the fields in the targets part for the target Lambda function?

eventclient = boto3.client('events')

response = eventclient.put_rule(
    Name='notificationScheduler',
    ScheduleExpression='at(2023-02-01T02:30:00)',
    State='ENABLED',
    Description='schedule notifications reminders '
    **RoleArn**='string', ## The ARN for the role which the rule will use needs to have the permission to invoke the target lambda function
)

response = eventclient.put_targets(
    Rule='notificationScheduler',
    Targets=[{ ??? }]
)

Solution

  • We have resolved this by using the EventBridge scheduler in boto3 newer version..

    Code we have used :

            try:
                client.create_schedule(
                    Description='function for sending the reminderTime for the eventBridge',
                    FlexibleTimeWindow={
                        'Mode': 'OFF'
                    },
                    Name='Name of the schedule',
                    ScheduleExpression='at(specificTime)',
                    State='ENABLED',
                    Target={
                        # The Amazon Resource Name (ARN) of the target.
                        'Arn': 'ARN of the target function',
                        # The Amazon Resource Name (ARN) of the IAM role that EventBridge Scheduler will use for this target when the schedule is invoked.
                        'RoleArn': 'ARN of the role',
                        # The text, or well-formed JSON, passed to the target. If you are configuring a templated Lambda, AWS Step Functions, or Amazon EventBridge target, the input must be a well-formed JSON. For all other target types, a JSON is not required. If you do not specify anything for this field, EventBridge Scheduler delivers a default notification to the target.
                        'Input': Input to be passed to the target function,
                    }
    
                )
    
            except Exception as err:
                print(err)
    

    This is our customized Python code , The below Link has the full library .

    Boto3 EventBridgeScheduler