How to use AWS EventBridge with Python Lambda and Boto?

0

I played around with AWS a little bit and ended up at AWS EventBridge. I tried to write a Lambda for testing and understanding, but got an error just at the beginning.

import json, boto3

def lambda_handler(event, context):
    client = boto3.client('events')
    response = client.create_event_bus(
    Name='TestEventBus',
    EventSourceName='SomeSoucreEvent'
)

    return {
        'statusCode': 200,
        'body': json.dumps(response)
    }

I get the following error message:

Response: { "errorMessage": "'CloudWatchEvents' object has no attribute 'create_event_bus'", "errorType": "AttributeError", "stackTrace": [ " File \"/var/task/lambda_function.py\", line 5, in lambda_handler\n response = client.create_event_bus(\n", " File \"/var/runtime/botocore/client.py\", line 563, in getattr\n self.class.name, item)\n" ] }

The version of Boto running in the Lambda is 1.9.42

asked 3 years ago939 views
1 Answer
0

First of all, with your code

client = boto3.client('events')
response = client.create_event_bus(

you are accessing the CloudWatchEvents, not AWS EventBridge (as the error message states - reason why is stated below).

"CloudWatchEvents' object has no attribute 'create_event_bus'"

Moreover, EventBridge isn't available in the Python and JS lambda environment yet (via default packages). I assume AWS has not the latest version of their SDK running in lambda, you could upload your own code as a bundle bundle or work with lambda layers and install your custom NPM dependencies (assuming you will run it as JS). That way you could install the latest SDK version of AWS (NPM) and use EventBridge (EventBridge was announced one month ago).

Furthermore if you take a look a the boto3 documentation https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/events.html#eventbridge, it states that it is (as of now) version 1.9.205 (see also the /api/latest/ in the URL).

If you open up the documentation for 1.9.42, the version you added to your report (I assume you got this out of the lambda), via this URL, https://boto3.amazonaws.com/v1/documentation/api/1.9.42/reference/services/events.html#eventbridge , you will see that the version 1.9.42 does not have EventBridge implemented.

It only features CloudWatchEvents and that's why you can only access EventBridge with boto3 (as of now). You have to wait until AWS updates the boto3 version on lambda's or you have to manually deploy your bundle and run it.

Edited by: MartinJK on Aug 12, 2019 10:06 AM

answered 3 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions