Ex:Add items to Student Table

Hands on Exercise

In this exercise you will add items to the Student table created in an earlier exercise.

exercise-

Pre-Requisites

  • Student model commited to the Local DynamoDB Table
  • Refer : Earlier exercise for Student table

1. Add a Single student

Documentation

  • Use put-item to add a student to the Student table
  • Requires data specification

Solution

aws dynamodb put-item  --table-name Student \
    --item '{
        "email": {"S": "paul@example.com"},
        "name": {"S": "Paul"},
        "grade": {"S": "3"},
        "classes": {"SS": ["Geography","English"]}
    }'  \
    --endpoint-url  http://localhost:8000
  • With request for consumed capacity
aws dynamodb put-item  --table-name Student \
    --item '{
        "email": {"S": "paul@example.com"},
        "name": {"S": "Paul"},
        "grade": {"S": "3"},
        "classes": {"SS": ["Geography","English"]}
    }'  \
    --return-consumed-capacity TOTAL \
    --return-item-collection-metrics  SIZE \
    --endpoint-url  http://localhost:8000

2. Add a batch of students

  • In this exercise you will use the batch_writer()
  • Review Pythong code python/bulk-upload-json.py
  • Review and add data to modeling/students-bulk-upload.json
  • Run the code

Solution

  • Run it on shell prompt in the root folder of project repository
python  ./python/bulk-upload-json.py   Student    ./modeling/students-bulk-upload.json

3. Use Workbench to scan

  • Open Workbench > Operation builder > Localhost
  • Try the Scan operation to ensure added items are available