├── README.md ├── batch.course.data1.json └── batch.course.data2.json /README.md: -------------------------------------------------------------------------------- 1 | # DynamoDB Global Tables Demostration 2 | 3 | ## Step 1 4 | 5 | Create a new DynamoDB table named ```cloudacademy-courses```. 6 | 7 | ``` 8 | aws dynamodb create-table \ 9 | --region us-west-2 \ 10 | --table-name cloudacademy-courses \ 11 | --key-schema AttributeName=courseid,KeyType=HASH \ 12 | --attribute-definitions AttributeName=courseid,AttributeType=S \ 13 | --billing-mode PAY_PER_REQUEST 14 | ``` 15 | 16 | ## Step 2 17 | 18 | Load course data into the ```cloudacademy-courses``` table. 19 | 20 | ``` 21 | aws dynamodb batch-write-item --region us-west-2 --request-items file://./batch.course.data1.json 22 | ``` 23 | 24 | ## Step 3 25 | 26 | Update the ```cloudacademy-courses``` table and make it a global table with a new replica in the ```ap-southeast-2``` (Sydney) region. 27 | 28 | ``` 29 | aws dynamodb update-table \ 30 | --region us-west-2 \ 31 | --table-name cloudacademy-courses --cli-input-json \ 32 | '{ 33 | "ReplicaUpdates": 34 | [ 35 | { 36 | "Create": { 37 | "RegionName": "ap-southeast-2" 38 | } 39 | } 40 | ] 41 | }' 42 | ``` 43 | 44 | ## Step 4 45 | 46 | Check to see if the ```cloudacademy-courses``` global table is ready in the ```ap-southeast-2``` region. 47 | 48 | **Note**: Wait 1-2 minutes before running this command to give the previous command enough time to propagate the table updates across to the new region. 49 | 50 | ``` 51 | aws dynamodb describe-table \ 52 | --region ap-southeast-2 \ 53 | --table-name cloudacademy-courses 54 | ``` 55 | 56 | ## Step 5 57 | 58 | Setup 30 second watch on the ```cloudacademy-courses``` global table deployed in the ```ap-southeast-2``` region - and query the ```TableStatus``` attribute. Wait for it to reach ```Active``` status. 59 | 60 | **Note**: This command leverages the [jq utility](https://stedolan.github.io/jq/) to query the json data response for the ```TableStatus``` attribute 61 | 62 | ``` 63 | watch -n 30 "aws dynamodb describe-table \ 64 | --region ap-southeast-2 \ 65 | --table-name cloudacademy-courses \ 66 | | jq -r .Table.TableStatus" 67 | ``` 68 | 69 | ## Step 6 70 | 71 | Start up ```tmux``` and split the terminal. 72 | 73 | **Pane 1**: Run the following command to query for a new record which we will load in the second tmux pane. 74 | 75 | ``` 76 | watch -n1 "aws dynamodb get-item --region ap-southeast-2 --table-name cloudacademy-courses --key '{\"courseid\" : {\"S\" : \"6666666\"}}'" 77 | ``` 78 | 79 | **Pane 2**: Load the new data set into the ```cloudacademy-courses```. Observe how long it takes before the results show up in the other tmux pane. 80 | 81 | ``` 82 | aws dynamodb batch-write-item --region us-west-2 --request-items file://./batch.course.data2.json 83 | ``` -------------------------------------------------------------------------------- /batch.course.data1.json: -------------------------------------------------------------------------------- 1 | { 2 | "cloudacademy-courses": [ 3 | { 4 | "PutRequest": { 5 | "Item": { 6 | "courseid": {"S": "1111111"}, 7 | "company": {"S": "CloudAcademy"}, 8 | "title": {"S": "Working with Amazon DynamoDB"}, 9 | "url": {"S": "https://cloudacademy.com/course/working-with-amazon-dynamodb/"}, 10 | "duration": {"N": "92"}, 11 | "instructor": {"S": "Ryan Park"} 12 | } 13 | } 14 | }, 15 | { 16 | "PutRequest": { 17 | "Item": { 18 | "courseid": {"S": "2222222"}, 19 | "company": {"S": "CloudAcademy"}, 20 | "title": {"S": "Database Fundamentals for AWS"}, 21 | "url": {"S": "https://cloudacademy.com/course/aws-database-fundamentals-aws-180"}, 22 | "duration": {"N": "69"}, 23 | "instructor": {"S": "Andrew Larkin"} 24 | } 25 | } 26 | }, 27 | { 28 | "PutRequest": { 29 | "Item": { 30 | "courseid": {"S": "3333333"}, 31 | "company": {"S": "CloudAcademy"}, 32 | "title": {"S": "Working with Amazon DynamoDB"}, 33 | "url": {"S": "https://cloudacademy.com/course/amazon-web-services-big-data-specialty-storage"}, 34 | "duration": {"N": "107"}, 35 | "instructor": {"S": "Shane Gibson"} 36 | } 37 | } 38 | } 39 | ] 40 | } 41 | -------------------------------------------------------------------------------- /batch.course.data2.json: -------------------------------------------------------------------------------- 1 | { 2 | "cloudacademy-courses": [ 3 | { 4 | "PutRequest": { 5 | "Item": { 6 | "courseid": {"S": "4444444"}, 7 | "company": {"S": "CloudAcademy"}, 8 | "title": {"S": "Build AWS Serverless Web Applications With Python"}, 9 | "url": {"S": "https://cloudacademy.com/course/build-aws-serverless-web-applications-with-python"}, 10 | "duration": {"N": "119"}, 11 | "instructor": {"S": "Ben Lambert"} 12 | } 13 | } 14 | }, 15 | { 16 | "PutRequest": { 17 | "Item": { 18 | "courseid": {"S": "5555555"}, 19 | "company": {"S": "CloudAcademy"}, 20 | "title": {"S": "How to Use the AWS Command-Line Interface"}, 21 | "url": {"S": "https://cloudacademy.com/course/how-to-use-the-aws-command-line-interface"}, 22 | "duration": {"N": "50"}, 23 | "instructor": {"S": "David Clinton"} 24 | } 25 | } 26 | }, 27 | { 28 | "PutRequest": { 29 | "Item": { 30 | "courseid": {"S": "6666666"}, 31 | "company": {"S": "CloudAcademy"}, 32 | "title": {"S": "Advanced Use of Amazon API Gateway"}, 33 | "url": {"S": "https://cloudacademy.com/course/advanced-use-of-amazon-api-gateway"}, 34 | "duration": {"N": "22"}, 35 | "instructor": {"S": "Tehreem Siddiqui"} 36 | } 37 | } 38 | } 39 | ] 40 | } --------------------------------------------------------------------------------