OBS Event Source¶
For details, see Using an OBS Trigger.
Hints¶
Note
Triggers on OBS can only be used for FunctionGraphs in the main Project, not in Sub-Projects!
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 |
eventSource |
String |
Event source |
awsRegion |
String |
AWS region |
eventTime |
String |
Time when an event occurs |
eventName |
String |
See below |
userIdentity |
String |
User identity information |
requestParameters |
String |
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 s3:ObjectRemoved:Delete event type. Alternatively, you can request notification when a delete marker is created for a versioned object using s3:ObjectRemoved:DeleteMarkerCreated. These event notifications don’t alert you for automatic deletes from lifecycle configurations or from failed operations. |
Parameter s3¶
Parameter |
Type |
Description |
|---|---|---|
s3SchemaVersion |
String |
S3 schema version |
configurationId |
String |
Configuration ID |
bucket |
Object |
See below |
Parameter bucket¶
Parameter |
Type |
Description |
|---|---|---|
name |
String |
Name of the bucket |
ownerIdentity |
String |
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 |
versionId |
String |
Version ID |
sequencer |
String |
Sequencer |
Example¶
package main
import (
"encoding/json"
"fmt"
obs "github.com/opentelekomcloud-community/otc-functiongraph-go-runtime/go-runtime/events/obss3"
"github.com/opentelekomcloud-community/otc-functiongraph-go-runtime/go-runtime/go-api/context"
"github.com/opentelekomcloud-community/otc-functiongraph-go-runtime/go-runtime/pkg/runtime"
)
// Example for OBS Service handler
func ObsTest(payload []byte, ctx context.RuntimeContext) (interface{}, error) {
var obsEvent obs.OBSS3TriggerEvent
err := json.Unmarshal(payload, &obsEvent)
if err != nil {
fmt.Println("Unmarshal failed")
return "invalid data", err
}
ctx.GetLogger().Logf("payload:%s", obsEvent.String())
return "ok", nil
}
func main() {
runtime.Register(ObsTest)
}