Ex: Experiments with API

Hands on Exercise

Documentation

In this exercise you will use AWS CLI to try out the streams API.

1. Setup a table in Local DynamoDB

  • You may use the Employee table

2. Enable DynamoDB Stream on Employee table

  • You may try different StreamViewType
aws dynamodb update-table \
    --table-name Employee \
    --stream-specification StreamEnabled=true,StreamViewType=NEW_AND_OLD_IMAGES \
    --endpoint-url http://localhost:8000

3. Carry out Create/Update/Delete on table

  • You may use Workbench or CLI

4. ListStreams

  • Make sure you have a stream enabled in at least 1 table
  • In a temporary text file copy/paste the ARN for Employee table stream
aws dynamodbstreams list-streams \
    --endpoint-url http://localhost:8000

5. DescibeStream

  • Replace the ARN below with arn for the Employee stream
  • Copy/Paste the ShardId to temporary text file
aws dynamodbstreams describe-stream --stream-arn  REPLACE_WITH_STREAM_ARN \
    --endpoint-url http://localhost:8000

6. GetShardIterator

  • Decide on the iterator type
    • AT_SEQUENCE_NUMBER
    • AFTER_SEQUENCE_NUMBER
    • TRIM_HORIZON
    • LATEST
  • If you are using the AT/AFTER_SEQUNCE_NUMBER, you need to specify the –sequence-number in the command
  • Use the ARN and ShardId that you have copied to the temporary text file
aws dynamodbstreams get-shard-iterator \
    --stream-arn  REPLACE_WITH_STREAM_ARN  \
    --shard-id    REPLACE_WITH_SHARD_ID  \
    --shard-iterator-type    TRIM_HORIZON \
    --endpoint-url http://localhost:8000

7. GetRecords

  • Retrieves the stream records from a given shard
  • Requires shard-id
  • Returned records depend on the shard-iterator-type
aws dynamodbstreams get-records \
    --shard-iterator REPLACE_WITH_ITERATOR \
    --endpoint-url http://localhost:8000

8. Experiment

  • Change the View type, Iterator type
  • Carry out additional operations
  • To change the stream disable/enable stream:

Disable:

aws dynamodb update-table \
    --table-name Employee \
    --stream-specification StreamEnabled=false \
    --endpoint-url http://localhost:8000

Enable:

aws dynamodb update-table \
    --table-name Employee \
    --stream-specification StreamEnabled=true,StreamViewType=NEW_AND_OLD_IMAGES \
    --endpoint-url http://localhost:8000