CodexBloom - Programming Q&A Platform

OCI Event Service: how to to Trigger Functions with Cloud Events due to Invalid Payload

👀 Views: 77 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-14
oci functions events Python

I'm refactoring my project and I'm working on a personal project and I'm dealing with I'm converting an old project and I'm currently working on integrating OCI Event Service with OCI Functions, but I'm working with an scenario where my function is not triggering as expected when a cloud event is published..... I have set up the event topic and the function correctly, but the function is logging an behavior indicating that the payload is invalid. The behavior message I am receiving is: ``` behavior: Invalid payload format: expected JSON object. ``` I've verified the structure of the event being generated, and it seems to conform to the expected format mentioned in the OCI documentation. Below is the code for my function written in Python using the `oci-functions-sdk`: ```python import json def handler(ctx, event): print("Event received:", json.dumps(event)) return { 'statusCode': 200, 'body': json.dumps({'message': 'Event processed successfully'}) } ``` I am publishing the event using the following snippet, which I believe is correctly formatted: ```python import oci event_service_client = oci.events.EventsClient(config) event_details = { "data": { "key": "value" }, "eventType": "com.oraclecloud.example.event", "dataType": "application/json" } response = event_service_client.publish_event(event_details) print("Response status:", response.status) ``` I also have the correct permissions set up for both the function and the event service. I used the following IAM policy to allow the function to subscribe to the event: ``` Allow service FunctionService to manage events in compartment my_compartment ``` I've tried checking the event format against the OCI documentation, and it looks correct. However, any time I trigger the event, the function fails to process it due to this payload behavior. Has anyone faced a similar scenario, or can someone provide insight into what might be going wrong with the event payload? My setup uses the OCI SDK version 2.42.0. Thanks in advance for your help! My development environment is Ubuntu. I'm working on a microservice that needs to handle this. Could someone point me to the right documentation? What's the correct way to implement this? I'm working with Python in a Docker container on Ubuntu 22.04. Thanks, I really appreciate it! My team is using Python for this REST API. I appreciate any insights!