Event-Based Real-Time Cloud Functions Examples
Google Cloud Function Setup
- Configure the Cloud Run with the
google.cloud.storage.object.v1.finalizedtriggerto process newly added objects. - Python Function Example:
import functions_frameworkimport jsonimport requestsimport os# Triggered by a change in a storage bucket.cloud_eventdef hello_gcs(cloud_event): requests.post(os.getenv('APIENDPOINT', ""), headers={'ApiKey':os.getenv('APIKEY', "")}, json = {'metadata': json.dumps(cloud_event.data), 'storageClientId': os.getenv('STORAGECLIENTID', "") })- Requirements.txt example:
functions-framework==3.*requestsAlibaba Cloud Function Setup
- Follow the official Alibaba Cloud documentation to create a compute function with an OSS trigger: https://www.alibabacloud.com/help/en/function-compute/latest/configure-an-oss-trigger
- Specify the bucket to monitor and subscribe to the
oss:ObjectCreated:*event. - Python Function Example:
import oss2, json, osimport requestsdef handler(event, context): for eventRecord in json.loads(event)['events']: requests.post(os.getenv('APIENDPOINT', ""), headers={'ApiKey':os.getenv('APIKEY', "")}, json = {'metadata': json.dumps(eventRecord), 'storageClientId': os.getenv('STORAGECLIENTID', "") })Wasabi Function Setup
- Follow the official Wasabi documentation to create an event notification: https://docs.wasabi.com/v1/docs/event-notifications-bucket
- Establish a connection with a service capable of sending requests to MetaDefender Storage Security (MDSS).
- The Wasabi documentation example uses AWS SNS, which can be integrated with AWS Lambda (see Amazon S3 Lambda Function Setup: How do I configure Event Notifications on my Wasabi bucket using AWS SNS?
S3 Compatible function setup
- Event-based real-time processing configuration varies for different S3-compatible services.
- Most S3-compatible services offer event notification similar to Wasabi.
- The service must send a request to the MDSS endpoint:
http(s)://{baseurl}/api/webhook/realtimewith the appropriate request body:
{ "storageClientId": [Storage Client Id], "metadata": "{'s3': { 'object': {'key': [Object Path] }}}"}