Skip to content

bug: Global tables fail deployment when using cloudformation #12811

@Mohsens22

Description

@Mohsens22

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

The cloudformation stack failes deploying when multiple regions are specified. It seems that the it tries to create a table in the default region, then if there's a replica specified in that default region it will just fail because it already exists.
Here is the error:

{
            "StackId": "arn:aws:cloudformation:eu-west-1:000000000000:stack/TEST-Table-Stack/64963906",
            "EventId": "ab614b18-81cc-4470-b288-613a2bfcf0c8",
            "StackName": "TEST-Table-Stack",
            "LogicalResourceId": "TEST-Table-Stack",
            "PhysicalResourceId": "arn:aws:cloudformation:eu-west-1:000000000000:stack/TEST-Table-Stack/64963906",
            "ResourceType": "AWS::CloudFormation::Stack",
            "Timestamp": "2025-06-27T15:33:39.308000+00:00",
            "ResourceStatus": "CREATE_FAILED",
            "ResourceStatusReason": "An error occurred (ValidationException) when calling the UpdateTable operation: Failed to create a the new replica of table with name: 'Mohsen.Dev1.Table.NotificationsSubscriptions' because one or more replicas already existed as tables."
        },
        {
            "StackId": "arn:aws:cloudformation:eu-west-1:000000000000:stack/TEST-Table-Stack/64963906",
            "EventId": "474644dd-e0ba-4bfb-9119-e634d9e424d5",
            "StackName": "TEST-Table-Stack",
            "LogicalResourceId": "NotificationsSubscriptionsTable",
            "PhysicalResourceId": "arn:aws:cloudformation:eu-west-1:000000000000:stack/TEST-Table-Stack/64963906",
            "ResourceType": "AWS::DynamoDB::GlobalTable",
            "Timestamp": "2025-06-27T15:33:39.306000+00:00",
            "ResourceStatus": "CREATE_FAILED",
            "ResourceStatusReason": "An error occurred (ValidationException) when calling the UpdateTable operation: Failed to create a the new replica of table with name: 'Mohsen.Dev1.Table.NotificationsSubscriptions' because one or more replicas already existed as tables."
        },

In order to make it work in locastack you need to remove the replica in the main region which will make it fail in the real AWS.

Expected Behavior

In the real AWS you should both specify all the replicas regardless of the region where it is being deployed from. If you don't specify the active region, the deployment will fail.

How are you starting LocalStack?

With a docker-compose file

Steps To Reproduce

docker-compose -f .\docker-compose.testing.yml up -d
name: "test"

services:
  localstack:
    image: localstack/localstack:4.5
    container_name: localstack
    ports:
      - "4566:4566"
    environment:
      - SERVICES=dynamodb,sns,sqs,lambda,cloudformation,kms,cloudwatch,s3,iam,logs,ssm
      - DEBUG=1
      - ENFORCE_IAM=1
      - DEFAULT_REGION=eu-west-1
      - LAMBDA_EXECUTOR=docker
      - LAMBDA_REMOTE_DOCKER=true
      - LAMBDA_REMOVE_CONTAINERS=true
      - DATA_DIR=/tmp/localstack/data
      - DOCKER_HOST=unix:///var/run/docker.sock
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"

  dynamodb-admin:
    image: aaronshaf/dynamodb-admin
    depends_on:
      - localstack
    environment:
      - DYNAMO_ENDPOINT=http://localstack:4566
      - AWS_REGION=eu-west-1
    ports:
      - "8001:8001"

Cloudformation stack for the one that doesn't work in localstack but works in the real AWS

AWSTemplateFormatVersion: 2010-09-09

Description: This stack deploys does work on AWS but doesn't in localstack

Resources:
  NotificationsSubscriptionsTable:
    Type: AWS::DynamoDB::GlobalTable
    Properties:
      AttributeDefinitions:
        - AttributeName: EndpointUrl
          AttributeType: S
      BillingMode: PAY_PER_REQUEST
      KeySchema:
        - AttributeName: EndpointUrl
          KeyType: HASH
      SSESpecification:
        SSEEnabled: true
      StreamSpecification:
        StreamViewType: NEW_AND_OLD_IMAGES
      Replicas:
      - 
          Region: !Sub ${AWS::Region}
          Tags:
          - Key: Name
            Value: !Sub Mohsen-Dev1-Table-NotificationsSubscriptions
          - Key: ConfigurationContext
            Value: !Sub Dev1
      - 
          Region: eu-central-1
          Tags:
          - Key: Name
            Value: !Sub Mohsen-Dev1-Table-NotificationsSubscriptions
          - Key: ConfigurationContext
            Value: !Sub Dev1
      TableName:
        Fn::Sub: Mohsen.Dev1.Table.NotificationsSubscriptions
      

To deploy it

set AWS_REGION=eu-west-1

set CFN_TABLE_TEMPLATE=./not-work-localstack.yaml
set CFN_TABLE_TEMPLATE_PROCESSED=./not-work-localstack-output.yaml

set TABLE_STACK_NAME=TEST-Table-Stack

echo Creating s3 bucket for stuff
aws s3api create-bucket --bucket test-bucket --endpoint-url http://localhost:4566 --create-bucket-configuration LocationConstraint=%AWS_REGION% --region %AWS_REGION%

echo removing existing table stack
aws cloudformation delete-stack --endpoint-url http://localhost:4566 --region %AWS_REGION% --stack-name %TABLE_STACK_NAME% --deletion-mode FORCE_DELETE_STACK

echo Deploying the table

aws cloudformation package --endpoint-url http://localhost:4566 --region %AWS_REGION% --template-file %CFN_TABLE_TEMPLATE% --output-template-file %CFN_TABLE_TEMPLATE_PROCESSED% --s3-bucket test-bucket
aws cloudformation deploy --endpoint-url http://localhost:4566 --region %AWS_REGION% --template-file %CFN_TABLE_TEMPLATE_PROCESSED% --stack-name %TABLE_STACK_NAME% --capabilities CAPABILITY_NAMED_IAM

Cloudformation stack for the one that doesn't work in AWS but works in localstack

AWSTemplateFormatVersion: 2010-09-09

Description: This stack deploy does not work on AWS but does in localstack

Resources:
  NotificationsSubscriptionsTable:
    Type: AWS::DynamoDB::GlobalTable
    Properties:
      AttributeDefinitions:
        - AttributeName: EndpointUrl
          AttributeType: S
      BillingMode: PAY_PER_REQUEST
      KeySchema:
        - AttributeName: EndpointUrl
          KeyType: HASH
      SSESpecification:
        SSEEnabled: true
      StreamSpecification:
        StreamViewType: NEW_AND_OLD_IMAGES
      Replicas:
      - 
          Region: eu-central-1
          Tags:
          - Key: Name
            Value: !Sub Mohsen-Dev1-Table-NotificationsSubscriptions
          - Key: ConfigurationContext
            Value: !Sub Dev1
      TableName:
        Fn::Sub: Mohsen.Dev1.Table.NotificationsSubscriptions
      

To deploy it

set AWS_REGION=eu-west-1

set CFN_TABLE_TEMPLATE=./working-localstack.yaml
set CFN_TABLE_TEMPLATE_PROCESSED=./working-localstack-output.yaml

set TABLE_STACK_NAME=TEST-Table-Stack

echo Creating s3 bucket for stuff
aws s3api create-bucket --bucket test-bucket --endpoint-url http://localhost:4566 --create-bucket-configuration LocationConstraint=%AWS_REGION% --region %AWS_REGION%

echo removing existing table stack
aws cloudformation delete-stack --endpoint-url http://localhost:4566 --region %AWS_REGION% --stack-name %TABLE_STACK_NAME% --deletion-mode FORCE_DELETE_STACK

echo Deploying the table

aws cloudformation package --endpoint-url http://localhost:4566 --region %AWS_REGION% --template-file %CFN_TABLE_TEMPLATE% --output-template-file %CFN_TABLE_TEMPLATE_PROCESSED% --s3-bucket test-bucket
aws cloudformation deploy --endpoint-url http://localhost:4566 --region %AWS_REGION% --template-file %CFN_TABLE_TEMPLATE_PROCESSED% --stack-name %TABLE_STACK_NAME% --capabilities CAPABILITY_NAMED_IAM

Environment

- OS: Windows / Docker (WSL2)
- LocalStack: 4.5

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions