likeuntomurphy / serverless-ogm-bundle
Symfony bundle for the Serverless OGM
Package info
github.com/likeuntomurphy/serverless-ogm-bundle
Type:symfony-bundle
pkg:composer/likeuntomurphy/serverless-ogm-bundle
Requires
- php: >=8.5
- likeuntomurphy/serverless-ogm: ^0.1 || @dev
- symfony/config: ^8.0
- symfony/dependency-injection: ^8.0
- symfony/finder: ^8.0
- symfony/framework-bundle: ^8.0
- symfony/http-kernel: ^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.94
- matthiasnoback/symfony-dependency-injection-test: ^6.2
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^13.0
This package is auto-updated.
Last update: 2026-04-08 12:46:24 UTC
README
Symfony integration for the Serverless OGM. Registers the DocumentManager, discovers document classes automatically, and provides a DynamoDB profiler panel for the Symfony toolbar.
Installation
composer require likeuntomurphy/serverless-ogm-bundle
Configuration
# config/packages/serverless_ogm.yaml serverless_ogm: ~
The defaults connect to DynamoDB using the standard AWS credential chain (IAM role on Lambda, environment variables locally). Override for local development:
# config/packages/serverless_ogm.yaml when@dev: serverless_ogm: dynamodb: endpoint: '%env(DYNAMODB_ENDPOINT)%' credentials: key: 'local' secret: 'local'
Full configuration reference
serverless_ogm: dynamodb: region: 'us-east-1' # AWS region (default: us-east-1) endpoint: ~ # Override for DynamoDB Local credentials: key: ~ # Explicit access key (default: null, uses credential chain) secret: ~ # Explicit secret key table_suffix: '' # Appended to all table names (e.g. '_test') default_billing_mode: 'PAY_PER_REQUEST' # PAY_PER_REQUEST or PROVISIONED tables: # Per-table overrides (keyed by table name from #[Document]) sessions: billing_mode: 'PROVISIONED' rcu: 10 # ReadCapacityUnits (default: 5) wcu: 5 # WriteCapacityUnits (default: 5)
Document discovery
The bundle uses Symfony 7.3+ resource tags to discover document classes. Any class with the #[Document] attribute is automatically registered with the MetadataFactory and excluded from the service container — no directory scanning, no explicit class lists.
use Likeuntomurphy\Serverless\OGM\Mapping\Document; use Likeuntomurphy\Serverless\OGM\Mapping\Field; use Likeuntomurphy\Serverless\OGM\Mapping\PartitionKey; #[Document(table: 'users', pk: 'PK')] class User { #[PartitionKey] public string $email; #[Field] public string $name; }
No further configuration needed. The class is discovered, mapped, and excluded from the container automatically.
Services
The bundle registers the following services, all autowirable:
| Service | Description |
|---|---|
DocumentManager |
The main persistence interface. Tagged with kernel.reset to clear the identity map between requests. |
MetadataFactory |
Holds metadata for all registered document classes. |
DynamoDbClient |
The AWS SDK client, configured from the bundle config. |
Table creation
Create DynamoDB tables for all mapped documents:
php bin/console table:create
The command reads partition and sort key types from PHP property types (string maps to S, int/float to N). Billing mode defaults to PAY_PER_REQUEST (on-demand) and can be overridden globally via default_billing_mode or per table via the tables config. See ProvisionedThroughput for details on provisioned capacity.
Profiler
When the Symfony profiler is installed (symfony/web-profiler-bundle), the bundle adds a DynamoDB panel to the toolbar showing:
- Operations — every DynamoDB API call with operation name, table, and execution time
- Identity map — hit/miss counts showing how many
find()calls were served from cache - Hydrations — how many entities were hydrated from DynamoDB responses
The profiler hooks into the AWS SDK middleware stack and the OGM's ProfilingLogger interface. It is registered only when the profiler service is available — zero overhead in production.
Requirements
- PHP >= 8.5
likeuntomurphy/serverless-ogm^0.1symfony/framework-bundle^8.0
License
MIT