Add a Global Secondary Index (GSI)

Add a Global Secondary Index (GSI)

  1. Go to AWS DynamoDB Console.
  • Click Tables
  • Click TravelBuddyTripSectors Add a Global Secondary Index (GSI)
  1. Select tab Indexes
  • Click Create Index Add a Global Secondary Index (GSI)
  1. In the Partition Key section, type originCity Add a Global Secondary Index (GSI)
  • Drag the screen down, click Create index
  1. Check created index. Add a Global Secondary Index (GSI)
  2. Click Actions
  • Click Create item Add a Global Secondary Index (GSI)
  1. In the date section, enter a timestamp in milliseconds, representing a date in the future. For example: 1655686284000 which is June 20, 2021. You can use https://www.epochconverter.com to quickly convert new timestamps.
  • In the originCity section, type Melbourne
  • Click Add new attribute
  • Click String Add a Global Secondary Index (GSI)
  1. In the Attribute name section of the new attribute, type destinationCity
  1. Download file populate_tripsector.sh into folder Downloads into the Windows virtual machine
  • Open Command Prompt
  • Execute the below command to run file populate_tripsector.sh
cd Downloads
populate_tripsector.sh

Add a Global Secondary Index (GSI)

  • The content of the script :
#!/bin/bash
echo Adding record to DynamoDB
aws dynamodb put-item --profile aws-lab-env --table-name TravelBuddyTripSectors --item '{"date": {"N": "1610175636000"},"originCity": {"S": "Melbourne"},"destinationCity": {"S": "Sydney"}}';
echo Adding record to DynamoDB
aws dynamodb put-item --profile aws-lab-env --table-name TravelBuddyTripSectors --item '{"date": {"N": "1610175633000"},"originCity": {"S": "Melbourne"},"destinationCity": {"S": "Perth"}}';
echo Adding record to DynamoDB
aws dynamodb put-item --profile aws-lab-env --table-name TravelBuddyTripSectors --item '{"date": {"N": "1610190033000"},"originCity": {"S": "Melbourne"},"destinationCity": {"S": "Canberra"}}';
echo Adding record to DynamoDB
aws dynamodb put-item --profile aws-lab-env --table-name TravelBuddyTripSectors --item '{"date": {"N": "1610294800000"},"originCity": {"S": "Sydney"},"destinationCity": {"S": "Perth"}}';
echo Adding record to DynamoDB
aws dynamodb put-item --profile aws-lab-env --table-name TravelBuddyTripSectors --item '{"date": {"N": "1610327200000"},"originCity": {"S": "Sydney"},"destinationCity": {"S": "Melbourne"}}';
echo Adding record to DynamoDB
aws dynamodb put-item --profile aws-lab-env --table-name TravelBuddyTripSectors --item '{"date": {"N": "1610356000000"},"originCity": {"S": "Perth"},"destinationCity": {"S": "Darwin"}}';
echo Adding record to DynamoDB
aws dynamodb put-item --profile aws-lab-env --table-name TravelBuddyTripSectors --item '{"date": {"N": "1610374000000"},"originCity": {"S": "Perth"},"destinationCity": {"S": "Singapore"}}';
echo Adding record to DynamoDB
aws dynamodb put-item --profile aws-lab-env --table-name TravelBuddyTripSectors --item '{"date": {"N": "1610402800000"},"originCity": {"S": "Perth"},"destinationCity": {"S": "Sydney"}}';
echo Adding record to DynamoDB
aws dynamodb put-item --profile aws-lab-env --table-name TravelBuddyTripSectors --item '{"date": {"N": "1610446000000"},"originCity": {"S": "Melbourne"},"destinationCity": {"S": "Sydney"}}';
echo Adding record to DynamoDB
aws dynamodb put-item --profile aws-lab-env --table-name TravelBuddyTripSectors --item '{"date": {"N": "1610500000000"},"originCity": {"S": "Darwin"},"destinationCity": {"S": "Sydney"}}';
echo Done!
  1. Check the items in the DynamoDB table. Add a Global Secondary Index (GSI)