From 0b15645e30b847e80e53be15e6f6ac15dda7e5ee Mon Sep 17 00:00:00 2001 From: nathanpage Date: Wed, 7 May 2025 11:46:44 +1000 Subject: [PATCH] [Lock] Add DynamoDbStore --- components/lock.rst | 28 ++++++++++++++++++++++++++++ lock.rst | 4 ++++ 2 files changed, 32 insertions(+) diff --git a/components/lock.rst b/components/lock.rst index b8ba38c8fc7..a4ecafc314f 100644 --- a/components/lock.rst +++ b/components/lock.rst @@ -399,6 +399,7 @@ Store Scope Blocking Ex :ref:`RedisStore ` remote no yes yes yes :ref:`SemaphoreStore ` local yes no no no :ref:`ZookeeperStore ` remote no no no no +:ref:`DynamoDbStore ` remote no yes no yes ========================================================== ====== ======== ======== ======= ============= .. tip:: @@ -698,6 +699,32 @@ PHP process is terminated:: Zookeeper does not require a TTL as the nodes used for locking are ephemeral and die when the PHP process is terminated. +.. _lock-store-dynamodb: + +DynamoDbStore +~~~~~~~~~~~~~ + +The DynamoDbStore saves locks on a Amazon DynamoDB table. Install it by running: + +.. code-block:: terminal + + $ composer require symfony/amazon-dynamodb-lock + +It requires a `DynamoDbClient`_ instance or a `Data Source Name (DSN)`_. +This store does not support blocking, and expects a TTL to avoid stalled locks:: + + use Symfony\Component\Lock\Bridge\DynamoDb\Store\DynamoDbStore; + + // a DynamoDbClient instance or DSN + $dynamoDbClientOrDSN = 'dynamodb://default/lock'; + $store = new DynamoDbStore($dynamoDbClientOrDSN); + +The table where values are stored is created automatically on the first call to +the :method:`Symfony\\Component\\Lock\\Bridge\\DynamoDb\\DynamoDbStore::save` method. +You can also create this table explicitly by calling the +:method:`Symfony\\Component\\Lock\\Bridge\\DynamoDb\\DynamoDbStore::createTable` method in +your code. + Reliability ----------- @@ -1049,3 +1076,4 @@ are still running. .. _`readers-writer lock`: https://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock .. _`priority policy`: https://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock#Priority_policies .. _`PCNTL`: https://www.php.net/manual/book.pcntl.php +.. _`DynamoDbClient`: https://async-aws.com/clients/dynamodb.html diff --git a/lock.rst b/lock.rst index d9d57481f3d..6eb45ca1290 100644 --- a/lock.rst +++ b/lock.rst @@ -61,6 +61,7 @@ this behavior by using the ``lock`` key like: lock: 'sqlsrv:server=127.0.0.1;Database=app' lock: 'oci:host=127.0.0.1;dbname=app' lock: 'mongodb://127.0.0.1/app?collection=lock' + lock: 'dynamodb://127.0.0.1/lock' lock: '%env(LOCK_DSN)%' # using an existing service lock: 'snc_redis.default' @@ -119,6 +120,8 @@ this behavior by using the ``lock`` key like: mongodb://127.0.0.1/app?collection=lock + dynamodb://127.0.0.1/lock + %env(LOCK_DSN)% @@ -157,6 +160,7 @@ this behavior by using the ``lock`` key like: ->resource('default', ['sqlsrv:server=127.0.0.1;Database=app']) ->resource('default', ['oci:host=127.0.0.1;dbname=app']) ->resource('default', ['mongodb://127.0.0.1/app?collection=lock']) + ->resource('default', ['dynamodb://127.0.0.1/lock']) ->resource('default', [env('LOCK_DSN')]) // using an existing service ->resource('default', ['snc_redis.default'])