protected function getItemKeyByEventId(Identifier $eventId, array $context = []): ?array
    {
        $tableName = $this->getTableNameForRead($context);
        $params = [
            'TableName'                 => $tableName,
            'IndexName'                 => EventStoreTable::GSI_EVENT_ID_NAME,
            'Limit'                     => 1,
            'ExpressionAttributeNames'  => [
                '#hash' => EventStoreTable::GSI_EVENT_ID_HASH_KEY_NAME,
            ],
            'ExpressionAttributeValues' => [
                ':v_hash' => ['S' => (string)$eventId],
            ],
            'KeyConditionExpression'    => '#hash = :v_hash',
        ];

        try {
            $response = $this->client->query($params);
        } catch (\Throwable $e) {
            if ($e instanceof AwsException) {
                $errorName = $e->getAwsErrorCode() ?: ClassUtils::getShortName($e);
                if ('ProvisionedThroughputExceededException' === $errorName) {
                    $code = Code::RESOURCE_EXHAUSTED;
                } else {
                    $code = Code::UNAVAILABLE;
                }
            } else {
                $errorName = ClassUtils::getShortName($e);
                $code = Code::INTERNAL;
            }

            throw new EventStoreOperationFailed(
                sprintf(
                    '%s on IndexQuery [%s] on DynamoDb table [%s].',
                    $errorName,
                    EventStoreTable::GSI_EVENT_ID_NAME,
                    $tableName
                ),
                $code,
                $e
            );
        }

        if (!isset($response['Items']) || empty($response['Items'])) {
            return null;
        }

        $item = array_pop($response['Items']);
        return [
            EventStoreTable::HASH_KEY_NAME  => ['S' => $item[EventStoreTable::HASH_KEY_NAME]['S']],
            EventStoreTable::RANGE_KEY_NAME => ['N' => (string)$item[EventStoreTable::RANGE_KEY_NAME]['N']],
        ];
    }
protected function getItemKeyByEventId(Identifier $eventId, array $context = []): ?array
    {
        $tableName = $this->getTableNameForRead($context);
        $params = [
            'TableName'                 => $tableName,
            'IndexName'                 => EventStoreTable::GSI_EVENT_ID_NAME,
            'Limit'                     => 1,
            'ExpressionAttributeNames'  => [
                '#hash' => EventStoreTable::GSI_EVENT_ID_HASH_KEY_NAME,
            ],
            'ExpressionAttributeValues' => [
                ':v_hash' => ['S' => (string)$eventId],
            ],
            'KeyConditionExpression'    => '#hash = :v_hash',
        ];

        try {
            $response = $this->client->query($params);
        } catch (\Throwable $e) {
            if ($e instanceof AwsException) {
                $errorName = $e->getAwsErrorCode() ?: ClassUtils::getShortName($e);
                if ('ProvisionedThroughputExceededException' === $errorName) {
                    $code = Code::RESOURCE_EXHAUSTED;
                } else {
                    $code = Code::UNAVAILABLE;
                }
            } else {
                $errorName = ClassUtils::getShortName($e);
                $code = Code::INTERNAL;
            }

            throw new EventStoreOperationFailed(
                sprintf(
                    '%s on IndexQuery [%s] on DynamoDb table [%s].',
                    $errorName,
                    EventStoreTable::GSI_EVENT_ID_NAME,
                    $tableName
                ),
                $code,
                $e
            );
        }

        if (!isset($response['Items']) || empty($response['Items'])) {
            return null;
        }

        $item = array_pop($response['Items']);
        return [
            EventStoreTable::HASH_KEY_NAME  => ['S' => $item[EventStoreTable::HASH_KEY_NAME]['S']],
            EventStoreTable::RANGE_KEY_NAME => ['N' => (string)$item[EventStoreTable::RANGE_KEY_NAME]['N']],
        ];
    }
protected function getItemKeyByEventId ( Identifier $ eventId , array $ context = [ ] ) : ? array { $ tableName = $ this -> getTableNameForRead ( $ context ) ; $ params = [ 'TableName' => $ tableName , 'IndexName' => EventStoreTable :: GSI_EVENT_ID_NAME , 'Limit' => 1 , 'ExpressionAttributeNames' => [ '#hash' => EventStoreTable :: GSI_EVENT_ID_HASH_KEY_NAME , ] , 'ExpressionAttributeValues' => [ ':v_hash' => [ 'S' => ( string ) $ eventId ] , ] , 'KeyConditionExpression' => '#hash = :v_hash' , ] ; try { $ response = $ this -> client -> query ( $ params ) ; } catch ( \ Throwable $ e ) { if ( $ e instanceof AwsException ) { $ errorName = $ e -> getAwsErrorCode ( ) ? : ClassUtils :: getShortName ( $ e ) ; if ( 'ProvisionedThroughputExceededException' === $ errorName ) { $ code = Code :: RESOURCE_EXHAUSTED ; } else { $ code = Code :: UNAVAILABLE ; } } else { $ errorName = ClassUtils :: getShortName ( $ e ) ; $ code = Code :: INTERNAL ; } throw new EventStoreOperationFailed ( sprintf ( '%s on IndexQuery [%s] on DynamoDb table [%s].' , $ errorName , EventStoreTable :: GSI_EVENT_ID_NAME , $ tableName ) , $ code , $ e ) ; } if ( ! isset ( $ response [ 'Items' ] ) || empty ( $ response [ 'Items' ] ) ) { return null ; } $ item = array_pop ( $ response [ 'Items' ] ) ; return [ EventStoreTable :: HASH_KEY_NAME => [ 'S' => $ item [ EventStoreTable :: HASH_KEY_NAME ] [ 'S' ] ] , EventStoreTable :: RANGE_KEY_NAME => [ 'N' => ( string ) $ item [ EventStoreTable :: RANGE_KEY_NAME ] [ 'N' ] ] , ] ; }
When needing to get or delete an event by its id we must first
get the DynamoDb item key from the GSI.  At this time DynamoDb
does not support a batch get from a GSI so this can only handle
one event id at a time.

@param Identifier $eventId
@param array      $context

@return array|null
When needing to get or delete an event by its id we must first get the DynamoDb item key from the GSI . At this time DynamoDb does not support a batch get from a GSI so this can only handle one event id at a time .