Skip to content

Commit 1ccd329

Browse files
authored
Merge pull request #186 from awsrahulrsr/main
Added code snippet - docdb-lambda integration using PHP
2 parents 01f093a + d3e4108 commit 1ccd329

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
require __DIR__.'/vendor/autoload.php';
4+
5+
use Bref\Context\Context;
6+
use Bref\Event\Handler;
7+
8+
class DocumentDBEventHandler implements Handler
9+
{
10+
public function handle($event, Context $context): string
11+
{
12+
13+
$events = $event['events'] ?? [];
14+
foreach ($events as $record) {
15+
$this->logDocumentDBEvent($record['event']);
16+
}
17+
return 'OK';
18+
}
19+
20+
private function logDocumentDBEvent($event): void
21+
{
22+
// Extract information from the event record
23+
24+
$operationType = $event['operationType'] ?? 'Unknown';
25+
$db = $event['ns']['db'] ?? 'Unknown';
26+
$collection = $event['ns']['coll'] ?? 'Unknown';
27+
$fullDocument = $event['fullDocument'] ?? [];
28+
29+
// Log the event details
30+
31+
echo "Operation type: $operationType\n";
32+
echo "Database: $db\n";
33+
echo "Collection: $collection\n";
34+
echo "Full document: " . json_encode($fullDocument, JSON_PRETTY_PRINT) . "\n";
35+
}
36+
}
37+
return new DocumentDBEventHandler();

0 commit comments

Comments
 (0)