diff --git a/moto/dynamodb2/models/__init__.py b/moto/dynamodb2/models/__init__.py index eafa2743a..428ccb01e 100644 --- a/moto/dynamodb2/models/__init__.py +++ b/moto/dynamodb2/models/__init__.py @@ -413,6 +413,10 @@ class Table(BaseModel): raise UnformattedGetAttTemplateException() + @property + def physical_resource_id(self): + return self.name + @classmethod def create_from_cloudformation_json( cls, resource_name, cloudformation_json, region_name diff --git a/tests/test_cloudformation/test_cloudformation_stack_integration.py b/tests/test_cloudformation/test_cloudformation_stack_integration.py index 9d639ed42..5a8e9cd68 100644 --- a/tests/test_cloudformation/test_cloudformation_stack_integration.py +++ b/tests/test_cloudformation/test_cloudformation_stack_integration.py @@ -2767,3 +2767,39 @@ def test_stack_events_get_attribute_integration(): output_arn["OutputValue"].should.equal(event_bus["Arn"]) output_name["OutputValue"].should.equal(event_bus["Name"]) + + +@mock_cloudformation +@mock_dynamodb2 +def test_dynamodb_table_creation(): + CFN_TEMPLATE = { + "Outputs": {"MyTableName": {"Value": {"Ref": "MyTable"}},}, + "Resources": { + "MyTable": { + "Type": "AWS::DynamoDB::Table", + "Properties": { + "KeySchema": [{"AttributeName": "id", "KeyType": "HASH"}], + "AttributeDefinitions": [ + {"AttributeName": "id", "AttributeType": "S"} + ], + "BillingMode": "PAY_PER_REQUEST", + }, + }, + }, + } + stack_name = "foobar" + cfn = boto3.client("cloudformation", "us-west-2") + cfn.create_stack(StackName=stack_name, TemplateBody=json.dumps(CFN_TEMPLATE)) + # Wait until moto creates the stack + waiter = cfn.get_waiter("stack_create_complete") + waiter.wait(StackName=stack_name) + # Verify the TableName is part of the outputs + stack = cfn.describe_stacks(StackName=stack_name)["Stacks"][0] + outputs = stack["Outputs"] + outputs.should.have.length_of(1) + outputs[0]["OutputKey"].should.equal("MyTableName") + outputs[0]["OutputValue"].should.contain("foobar") + # Assert the table is created + ddb = boto3.client("dynamodb", "us-west-2") + table_names = ddb.list_tables()["TableNames"] + table_names.should.equal([outputs[0]["OutputValue"]])