AWS code-library documentation change
Summary
Updated existing global tables documentation to clarify multi-Region replication with eventual consistency (MREC) vs strong consistency, added detailed replica management steps, and improved cleanup instructions
Security assessment
The changes primarily clarify consistency models (MREC vs MRSC) and improve operational procedures without introducing new security features or addressing vulnerabilities. The update differentiates between consistency levels but doesn't directly relate to security controls.
Diff
diff --git a/code-library/latest/ug/bash_2_dynamodb_code_examples.md b/code-library/latest/ug/bash_2_dynamodb_code_examples.md index d5ec44ee1..c22ab9762 100644 --- a//code-library/latest/ug/bash_2_dynamodb_code_examples.md +++ b//code-library/latest/ug/bash_2_dynamodb_code_examples.md @@ -3238,0 +3239,135 @@ Query items from a table with multiple GSIs. +The following code example shows how to create and manage DynamoDB global tables with Multi-Region Strong Consistency (MRSC). + + * Create a table with Multi-Region Strong Consistency. + + * Verify MRSC configuration and replica status. + + * Test strong consistency across Regions with immediate reads. + + * Perform conditional writes with MRSC guarantees. + + * Clean up MRSC global table resources. + + + + +**AWS CLI with Bash script** + + +Create a table with Multi-Region Strong Consistency. + + + # Step 1: Create a new table in us-east-2 (primary region for MRSC) + # Note: Table must be empty when enabling MRSC + aws dynamodb create-table \ + --table-name MusicTable \ + --attribute-definitions \ + AttributeName=Artist,AttributeType=S \ + AttributeName=SongTitle,AttributeType=S \ + --key-schema \ + AttributeName=Artist,KeyType=HASH \ + AttributeName=SongTitle,KeyType=RANGE \ + --billing-mode PAY_PER_REQUEST \ + --region us-east-2 + + # Wait for table to become active + aws dynamodb wait table-exists --table-name MusicTable --region us-east-2 + + # Step 2: Add replica and witness with Multi-Region Strong Consistency + # MRSC requires exactly three replicas in supported regions + aws dynamodb update-table \ + --table-name MusicTable \ + --replica-updates '[{"Create": {"RegionName": "us-east-1"}}]' \ + --global-table-witness-updates '[{"Create": {"RegionName": "us-west-2"}}]' \ + --multi-region-consistency STRONG \ + --region us-east-2 + + + +Verify MRSC configuration and replica status. + + + # Verify the global table configuration and MRSC setting + aws dynamodb describe-table \ + --table-name MusicTable \ + --region us-east-2 \ + --query 'Table.{TableName:TableName,TableStatus:TableStatus,MultiRegionConsistency:MultiRegionConsistency,Replicas:Replicas[*],GlobalTableWitnesses:GlobalTableWitnesses[*].{Region:RegionName,Status:ReplicaStatus}}' + + + +Test strong consistency with immediate reads across Regions. + + + # Write an item to the primary region + aws dynamodb put-item \ + --table-name MusicTable \ + --item '{"Artist": {"S":"The Beatles"},"SongTitle": {"S":"Hey Jude"},"Album": {"S":"The Beatles 1967-1970"},"Year": {"N":"1968"}}' \ + --region us-east-2 + + # Read the item from replica region to verify strong consistency (cannot read or write to witness) + # No wait time needed - MRSC provides immediate consistency + echo "Reading from us-east-1 (immediate consistency):" + aws dynamodb get-item \ + --table-name MusicTable \ + --key '{"Artist": {"S":"The Beatles"},"SongTitle": {"S":"Hey Jude"}}' \ + --consistent-read \ + --region us-east-1 + + + +Perform conditional writes with MRSC guarantees. + + + # Perform a conditional update from a different region + # This demonstrates that conditions work consistently across all regions + aws dynamodb update-item \ + --table-name MusicTable \ + --key '{"Artist": {"S":"The Beatles"},"SongTitle": {"S":"Hey Jude"}}' \ + --update-expression "SET #rating = :rating" \ + --condition-expression "attribute_exists(Artist)" \ + --expression-attribute-names '{"#rating": "Rating"}' \ + --expression-attribute-values '{":rating": {"N":"5"}}' \ + --region us-east-1 + + + +Clean up MRSC global table resources. + + + # Remove replica tables (must be done before deleting the primary table) + aws dynamodb update-table \ + --table-name MusicTable \ + --replica-updates '[{"Delete": {"RegionName": "us-east-1"}}]' \ + --global-table-witness-updates '[{"Delete": {"RegionName": "us-west-2"}}]' \ + --region us-east-2 + + # Wait for replicas to be deleted + echo "Waiting for replicas to be deleted..." + sleep 30 + + # Delete the primary table + aws dynamodb delete-table \ + --table-name MusicTable \ + --region us-east-2 + + + + * For API details, see the following topics in _AWS CLI Command Reference_. + + * [CreateTable](https://docs.aws.amazon.com/goto/aws-cli/dynamodb-2012-08-10/CreateTable) + + * [DeleteTable](https://docs.aws.amazon.com/goto/aws-cli/dynamodb-2012-08-10/DeleteTable) + + * [DescribeTable](https://docs.aws.amazon.com/goto/aws-cli/dynamodb-2012-08-10/DescribeTable) + + * [GetItem](https://docs.aws.amazon.com/goto/aws-cli/dynamodb-2012-08-10/GetItem) + + * [PutItem](https://docs.aws.amazon.com/goto/aws-cli/dynamodb-2012-08-10/PutItem) + + * [UpdateItem](https://docs.aws.amazon.com/goto/aws-cli/dynamodb-2012-08-10/UpdateItem) + + * [UpdateTable](https://docs.aws.amazon.com/goto/aws-cli/dynamodb-2012-08-10/UpdateTable) + + + + @@ -3891 +4026 @@ Describe TTL settings. -The following code example shows how to manage DynamoDB global tables with multi-region replication. +The following code example shows how to manage DynamoDB global tables with multi-Region replication with eventual consistency (MREC). @@ -3893 +4028 @@ The following code example shows how to manage DynamoDB global tables with multi - * Create a table with multi-region replication. + * Create a table with multi-Region replication (MREC). @@ -3897 +4032,3 @@ The following code example shows how to manage DynamoDB global tables with multi - * Remove replicas. + * Remove replicas one-by-one. + + * Clean up by deleting the table. @@ -3905 +4042 @@ The following code example shows how to manage DynamoDB global tables with multi -Create a table with multi-region replication. +Create a table with multi-Region replication. @@ -3908 +4045 @@ Create a table with multi-region replication. - # Step 1: Create a new table in us-west-2 + # Step 1: Create a new table (MusicTable) in US East (Ohio), with DynamoDB Streams enabled (NEW_AND_OLD_IMAGES) @@ -3918 +4055,2 @@ Create a table with multi-region replication. - --region us-west-2 + --stream-specification StreamEnabled=true,StreamViewType=NEW_AND_OLD_IMAGES \ + --region us-east-2 @@ -3920,6 +4058,13 @@ Create a table with multi-region replication. - # Step 2: Create replicas in us-east-1 and us-east-2 - aws dynamodb update-table \ - --table-name MusicTable \ - --replica-updates '[{"Create": {"RegionName": "us-east-1"}}, {"Create": {"RegionName": "us-east-2"}}]' \ - --multi-region-consistency STRONG \ - --region us-west-2 + # Step 2: Create an identical MusicTable table in US East (N. Virginia) + aws dynamodb update-table --table-name MusicTable --cli-input-json \ + '{ + "ReplicaUpdates": + [ + { + "Create": { + "RegionName": "us-east-1" + } + } + ] + }' \ + --region us-east-2 @@ -3926,0 +4072,13 @@ Create a table with multi-region replication. + # Step 3: Create a table in Europe (Ireland) + aws dynamodb update-table --table-name MusicTable --cli-input-json \ + '{ + "ReplicaUpdates": + [ + { + "Create": { + "RegionName": "eu-west-1" + } + } + ] + }' \ + --region us-east-2 @@ -3929 +4086,0 @@ Create a table with multi-region replication. -Describe the multi-region table. @@ -3930,0 +4088 @@ Describe the multi-region table. +Describe the multi-Region table. @@ -3932,2 +4090,6 @@ Describe the multi-region table.