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

<?php

/**
 * Sample OBS S3 event handler for FunctionGraph.
 */

require_once __DIR__ . '/../vendor/autoload.php';

use OTC\fg_obss3_event\OBSS3Event;

function initializer($context)
{
  $logger = $context->getLogger();
  $output = 'Initializer called for function: ' . $context->getFunctionName();
  $logger->debug($output);
  return $output;
}

/**
 * Main handler function for the OBS S3 event.
 *
 * @param mixed $event   The OBS S3 event data
 * @param mixed $context FunctionGraph execution context
 * @return array Response with event name and bucket name
 */
function handler($event, $context)
{
  $logger = $context->getLogger();

  $logger->info('Function Name: ' . $context->getFunctionName());

  $obsEvent = new OBSS3Event($event);

  $logger->info('OBS Event: ' . $obsEvent->getRecords()[0]->getEventName());
  $logger->info('OBS Event - Bucket: ' . $obsEvent->getRecords()[0]->getS3()->getBucket()->getName());

  $output = [
    'event_name' => $obsEvent->getRecords()[0]->getEventName(),
    'bucketname' => $obsEvent->getRecords()[0]->getS3()->getBucket()->getName(),
  ];

  return $output;
}

Full sample code is available in the samples-doc/scratch-event-obss3.