OBS Event Source¶
For the use of OBS triggers, please refer to Using an OBS Trigger.
Note
For each OBS bucket, only one FunctionGraph can be triggered (no multiple FunctionGraphs listening on same bucket).
OBS example event¶
{
"Records": [
{
"eventVersion": "2.0",
"eventTime": "2018-01-09T07:50:50.028Z",
"requestParameters": {
"sourceIPAddress": "103.218.216.125"
},
"s3": {
"configurationId": "UK1DGFPYUKUZFHNQ00000160CC0B471D101ED30CE24DF4DB",
"object": {
"eTag": "9d377b10ce778c4938b3c7e2c63a229a",
"sequencer": "00000000160D9E681484D6B4C0000000",
"key": "job.png",
"size": 777835
},
"bucket": {
"arn": "arn:fss:s3:::syj-input2",
"name": "functionstorage-template",
"ownerIdentity": {
"PrincipalId": "0ed1b73473f24134a478962e631651eb"
}
}
},
"awsRegion": "region",
"eventName": "ObjectCreated:Post",
"userIdentity": {
"principalId": "9bf43789b1ff4b679040f35cc4f0dc05"
}
}
]
}
Parameter description¶
Parameter |
Type |
Description |
|---|---|---|
eventVersion |
String |
Event version |
awsRegion |
String |
AWS region |
eventTime |
String |
Time when an event occurs |
eventName |
String |
See below |
userIdentity |
Object |
User identity information |
requestParameters |
Object |
Request parameters |
responseElements |
String |
Response elements |
s3 |
Object |
See below |
Possible values for eventName¶
EventName |
Description |
|---|---|
ObjectCreated:Put
ObjectCreated:Post
ObjectCreated:Copy
|
Operations such as PUT, POST, and COPY can create an object. With these event types, you can enable notifications when an object is created using a specific API operation. |
ObjectCreated:CompleteMultipartUpload |
ObjectCreated:CompleteMultipartUpload includes objects that are created using UploadPartCopy for Copy operations. |
ObjectRemoved:Delete
ObjectRemoved:DeleteMarkerCreated
|
By using the ObjectRemoved event types, you can enable notification when an object or a batch of objects is removed from a bucket. You can request notification when an object is deleted or a versioned object is permanently deleted by using the ObjectRemoved:Delete event type. Alternatively, you can request notification when a delete marker is created for a versioned object using ObjectRemoved:DeleteMarkerCreated. These event notifications don’t alert you for automatic deletes from lifecycle configurations or from failed operations. |
Parameter requestParameters¶
Parameter |
Type |
Description |
|---|---|---|
sourceIPAddress |
String |
Source IP address |
Parameter s3¶
Parameter |
Type |
Description |
|---|---|---|
object |
Object |
See below |
configurationId |
String |
Configuration ID |
bucket |
Object |
See below |
Parameter bucket¶
Parameter |
Type |
Description |
|---|---|---|
name |
String |
Name of the bucket |
ownerIdentity |
Object |
Owner identity information |
arn |
String |
Amazon Resource Name |
Parameter object¶
Parameter |
Type |
Description |
|---|---|---|
key |
String |
The name that has been assigned to an object. |
eTag |
String |
The entity tag is a hash of the object. |
size |
Long |
Size in bytes of the object |
sequencer |
String |
Sequencer |
Example¶
# coding: utf-8
"""
Sample obs event handler for FunctionGraph.
"""
from fg_obss3_event import OBSS3Event
def handler(event, context):
"""
Main handler function for the OBS event.
Args:
event (dict): The OBS event data
context: FunctionGraph execution context
Returns:
str: Response message
"""
logger = context.getLogger()
logger.info("Function Name: %s", context.getFunctionName())
obs_event = OBSS3Event(event)
logger.info("OBS Event: %s", obs_event.get_records()[0].get_event_name())
logger.info("OBS Event - Bucket: %s", obs_event.get_records()[0].get_s3().get_bucket().get_name())
output = {
"event_name": obs_event.get_records()[0].get_event_name(),
"bucketname": obs_event.get_records()[0].get_s3().get_bucket().get_name(),
}
return output
Full sample code is available in the samples-doc/scratch-event-obs.
Further reading¶
For working with OBS Buckets, please refer to: Object Storage Service 3rd Party - Python SDK.
FunctionGraph Python Runtime contains a bundled version of OBS SDK, which is available in the runtime environment.
See Bundled Libraries for the specific Python version documentation for more details.
For samples, see:
Package description¶
Public package exports for fg_obss3_event.
- class fg_obss3_event.OBSS3Event(event)¶
Bases:
objectRepresents an Object Storage Service S3 event for FunctionGraph.
- get_records()¶
- to_json()¶
- class fg_obss3_event.OBSS3Record(record)¶
Bases:
objectRepresents a single OBS S3 event record.
- get_event_version()¶
- get_event_time()¶
- get_request_parameters()¶
- get_s3()¶
- get_aws_region()¶
- get_event_name()¶
- get_user_identity()¶
- to_json()¶
- class fg_obss3_event.RequestParameters(params)¶
Bases:
objectRepresents the request parameters in an OBS S3 event record.
- get_source_ip_address()¶
- to_json()¶
- class fg_obss3_event.S3Details(s3)¶
Bases:
objectRepresents the S3 payload in an OBS S3 event record.
- get_configuration_id()¶
- get_object()¶
- get_bucket()¶
- to_json()¶
- class fg_obss3_event.S3Object(obj)¶
Bases:
objectRepresents the object details in an OBS S3 event.
- get_e_tag()¶
- get_sequencer()¶
- get_key()¶
- get_size()¶
- to_json()¶
- class fg_obss3_event.S3Bucket(bucket)¶
Bases:
objectRepresents the bucket details in an OBS S3 event.
- get_arn()¶
- get_name()¶
- get_owner_identity()¶
- to_json()¶