Ravindra BagaleCourses & study guides English

AWS CLI DynamoDB Commands: Tables, Put, Get, Query आणि Scan

Terminal मधून DynamoDB वापरू: table बनवा, put, get, update, delete items, key ने query, scan, batch writes, TTL आणि backups.

या chapter मध्ये तुम्ही काय शिकाल

  • On-demand table बनवा
  • Items put, get, update, delete
  • Query vs scan
  • Batch writes आणि TTL
  • Backups आणि delete

1. मोठं चित्र: key-value register

हे का लागतं?

School register: roll number (partition key) ने student पटकन सापडतो, मग तारीख (sort key). प्रत्येक पान शोधणं (scan) slow.

हे काय आहे?

Commands aws dynamodb मध्ये. Values type letters: S string, N number, BOOL, L, M.

कसं करायचं (step by step)

Table workflowcreate-table PK+SKput-itemपूर्ण key ने get-itemPK ने queryगरज असेल तरच scan
App चे प्रश्न लक्षात ठेवून keys design करा.

2. Table बनवा

हे का लागतं?

Servers शिवाय scale होणारा fast database हवा.

हे काय आहे?

Table ला partition key आणि optional sort key. PAY_PER_REQUEST = request नुसार पैसे, capacity planning नाही.

कसं करायचं (step by step)

  1. customer आणि date keys सह Orders.
aws dynamodb create-table --table-name Orders --attribute-definitions AttributeName=cust,AttributeType=S AttributeName=odate,AttributeType=S --key-schema AttributeName=cust,KeyType=HASH AttributeName=odate,KeyType=RANGE --billing-mode PAY_PER_REQUEST --query TableDescription.TableStatus --output text

अपेक्षित output:

CREATING
  1. Wait आणि verify.
aws dynamodb wait table-exists --table-name Orders
aws dynamodb describe-table --table-name Orders --query "Table.[TableStatus,BillingModeSummary.BillingMode]" --output text

अपेक्षित output:

ACTIVE  PAY_PER_REQUEST

3. Put, get, update, delete

हे का लागतं?

प्रत्येक app दिवसभर हेच चार करतं.

हे काय आहे?

put-item पूर्ण item लिहितो. get-item पूर्ण key ने वाचतो. update-item काही attributes बदलतो. delete-item एक item काढतो.

कसं करायचं (step by step)

  1. Item put.
aws dynamodb put-item --table-name Orders --item '{"cust":{"S":"ravi"},"odate":{"S":"2026-10-24"},"total":{"N":"499"},"status":{"S":"NEW"}}'

अपेक्षित output:

(no output means success)
  1. Get.
aws dynamodb get-item --table-name Orders --key '{"cust":{"S":"ravi"},"odate":{"S":"2026-10-24"}}' --query "Item.total.N" --output text

अपेक्षित output:

499
  1. Condition सह update.
aws dynamodb update-item --table-name Orders --key '{"cust":{"S":"ravi"},"odate":{"S":"2026-10-24"}}' --update-expression "SET #s = :p" --condition-expression "#s = :n" --expression-attribute-names '{"#s":"status"}' --expression-attribute-values '{":p":{"S":"PAID"},":n":{"S":"NEW"}}' --return-values UPDATED_NEW

अपेक्षित output:

{ "Attributes": { "status": { "S": "PAID" } } }
  1. Delete.
aws dynamodb delete-item --table-name Orders --key '{"cust":{"S":"ravi"},"odate":{"S":"2026-10-24"}}'

अपेक्षित output:

(no output means success)

4. Query vs scan

हे का लागतं?

चुकीच्या पद्धतीने वाचणं slow आणि महाग.

हे काय आहे?

Query एक partition key वाचतो, sort key range सह. Scan पूर्ण table वाचून मग filter.

कसं करायचं (step by step)

  1. ravi च्या October orders.
aws dynamodb query --table-name Orders --key-condition-expression "cust = :c AND begins_with(odate, :m)" --expression-attribute-values '{":c":{"S":"ravi"},":m":{"S":"2026-10"}}' --query "Count"

अपेक्षित output:

3
  1. Filter सह scan (सगळं वाचतो).
aws dynamodb scan --table-name Orders --filter-expression "total > :t" --expression-attribute-values '{":t":{"N":"1000"}}' --query "[Count,ScannedCount]" --output text

अपेक्षित output:

2  250

5. Batch writes आणि TTL

हे का लागतं?

एक एक items load करणं slow. जुना data आपोआप जावा.

हे काय आहे?

batch-write-item एका call मध्ये 25 items. TTL attribute मधल्या epoch time नंतर items delete करतो.

कसं करायचं (step by step)

  1. File मधून batch load.
aws dynamodb batch-write-item --request-items file://orders.json --query "length(UnprocessedItems)"

अपेक्षित output:

0
  1. expires वर TTL.
aws dynamodb update-time-to-live --table-name Orders --time-to-live-specification Enabled=true,AttributeName=expires --query "TimeToLiveSpecification.Enabled"

अपेक्षित output:

true
  1. On-demand backup.
aws dynamodb create-backup --table-name Orders --backup-name orders-1 --query "BackupDetails.BackupStatus" --output text

अपेक्षित output:

CREATING

6. हीच action Python, Node.js, Java, Go, .NET आणि PHP मध्ये

हे का लागतं?

Scripts CLI मध्ये सुरू होतात. Apps तोच API SDK मधून call करतात. दोन्ही माहीत असले की test केलेली command थेट code मध्ये नेता येते.

हे काय आहे?

प्रत्येक CLI command म्हणजे एक API call. उदा. aws dynamodb put-item --table-name Orders --item ... म्हणजे PutItem API.

कसं करायचं (step by step)

हीच action (PutItem) code मधून. प्रत्येक SDK CLI सारखेच profile, region आणि credentials वाचतो.

StackCode
Python (boto3)boto3.resource("dynamodb").Table("Orders").put_item(Item={"cust":"ravi","odate":"2026-10-24"})
Node.js (v3)await doc.send(new PutCommand({TableName:"Orders",Item:{cust:"ravi",odate:"2026-10-24"}}));
Java (v2)ddb.putItem(r -> r.tableName("Orders").item(Map.of("cust",AttributeValue.fromS("ravi"),"odate",AttributeValue.fromS("2026-10-24"))));
Go (v2)c.PutItem(ctx, &dynamodb.PutItemInput{TableName: aws.String("Orders"), Item: item})
.NETawait ddb.PutItemAsync("Orders", new(){{"cust",new AttributeValue("ravi")},{"odate",new AttributeValue("2026-10-24")}});
PHP$ddb->putItem(["TableName"=>"Orders","Item"=>["cust"=>["S"=>"ravi"],"odate"=>["S"=>"2026-10-24"]]]);

7. काहीही खर्च चालू राहू नये म्हणून cleanup

हे का लागतं?

चालू ठेवलेले lab resources पैसे खातात आणि security risk बनतात.

हे काय आहे?

उलट्या क्रमाने delete करा: आधी children, मग parents.

कसं करायचं (step by step)

  1. Backup delete.
ARN=$(aws dynamodb list-backups --table-name Orders --query "BackupSummaries[0].BackupArn" --output text)
aws dynamodb delete-backup --backup-arn $ARN

अपेक्षित output:

(no output means success)
  1. Table delete.
aws dynamodb delete-table --table-name Orders
aws dynamodb wait table-not-exists --table-name Orders && echo gone

अपेक्षित output:

gone

Ravindra Bagale's Tip

App code मध्ये scan असेल तर बहुतेक key किंवा GSI कमी आहे. त्या access pattern साठी Global Secondary Index जोडून query करा.

8. मुलाखत प्रश्न आणि उत्तरं

प्र. Partition key vs sort key?

PK partition; SK order आणि range.

प्र. Query vs scan?

Query keys ने; scan पूर्ण table.

प्र. Condition expression काय?

Condition खरी असेल तरच write.

प्र. On-demand vs provisioned?

Request नुसार vs capacity units.

प्र. TTL कसं चालतं?

Epoch time गेलेले items background मध्ये delete.

घरी करून बघा

  1. user आणि created keys सह Notes table, 5 notes add करून एका user ची query.
  2. Filter scan मध्ये Count आणि ScannedCount compare करा.

थोडक्यात सांगायचं तर

  1. Queries साठी keys.
  2. S, N, BOOL.
  3. Query, scan नाही.
  4. 25 एका वेळी.
  5. TTL आपोआप delete.

सराव Tasks

या scenario बद्दल

Lisboa Tiles हा लिस्बन मधला सिरॅमिक टाइल्स व्यवसाय आहे. João Silva त्यांचं IT व cloud काम पाहतात. त्यांचे पैसे EUR मध्ये मोजले जातात आणि AWS resources eu-west-1 Region मध्ये चालतात. खालच्या tasks मध्ये तुम्ही या lesson मध्ये शिकलेलं वापरून त्यांची खरी कामं करता. सगळी नावं, account IDs, IP addresses व numbers सरावासाठी काल्पनिक आहेत.

0 / 11

सोपं Table describe करा

का: Table चे keys, indexes, item count व status पाहा.

काय करायचं: lisboatiles-orders table describe करा.

कसं करायचं:
  1. Task वाचा आणि ते कोणत्या AWS service बद्दल आहे ते ठरवा.
  2. aws लिहा, मग service चं नाव, मग operation (action शब्द).
  3. प्रत्येक आवश्यक flag (--name) व त्यापुढे task मधली value लिहा.
  4. Flags कोणत्याही क्रमाने चालतात. Check answer दाबा.

सोपं लहान table scan करा

का: Scan लहान tables साठी ठीक; मोठ्यांवर टाळा.

काय करायचं: lisboatiles-settings table scan करा.

कसं करायचं:
  1. Task वाचा आणि ते कोणत्या AWS service बद्दल आहे ते ठरवा.
  2. aws लिहा, मग service चं नाव, मग operation (action शब्द).
  3. प्रत्येक आवश्यक flag (--name) व त्यापुढे task मधली value लिहा.
  4. Flags कोणत्याही क्रमाने चालतात. Check answer दाबा.

मध्यम Key ने एक item घ्या

का: GetItem सर्वात जलद read: पूर्ण key ने एक item.

काय करायचं: lisboatiles-orders मधून orderId "o-101" असलेला item घ्या.

कसं करायचं:
  1. Task वाचा आणि ते कोणत्या AWS service बद्दल आहे ते ठरवा.
  2. aws लिहा, मग service चं नाव, मग operation (action शब्द).
  3. प्रत्येक आवश्यक flag (--name) व त्यापुढे task मधली value लिहा.
  4. Flags कोणत्याही क्रमाने चालतात. Check answer दाबा.

मध्यम Item टाका

का: DynamoDB JSON प्रत्येक value चा type दाखवतो: S string, N number.

काय करायचं: lisboatiles-orders मध्ये orderId "o-101" (string) व amount 2500 (number) असलेला item टाका.

कसं करायचं:
  1. Task वाचा आणि ते कोणत्या AWS service बद्दल आहे ते ठरवा.
  2. aws लिहा, मग service चं नाव, मग operation (action शब्द).
  3. प्रत्येक आवश्यक flag (--name) व त्यापुढे task मधली value लिहा.
  4. Flags कोणत्याही क्रमाने चालतात. Check answer दाबा.

मध्यम CloudFormation: on-demand table

का: On-demand tables ला capacity planning नको.

काय करायचं: DynamoDB table lisboatiles-orders, partition key orderId (String), PAY_PER_REQUEST.

कसं करायचं:
  1. Task मधल्या top-level keys पासून सुरू करा.
  2. Child keys 2 spaces ने indent करा (tabs नकोत).
  3. प्रत्येक property मध्ये task मधली value भरा.
  4. Check answer दाबा. Keys चा क्रम महत्त्वाचा नाही.

मध्यम एका table ला Lambda access

का: Function ला फक्त स्वतःच्या table मध्ये वाचणं/लिहिणं लागतं.

काय करायचं: फक्त arn:aws:dynamodb:eu-west-1:101273714098:table/lisboatiles-orders वर dynamodb:GetItem, dynamodb:PutItem, dynamodb:Query allow करा.

कसं करायचं:
  1. { "Version": "2012-10-17", "Statement": [ ... ] } ने सुरू करा.
  2. प्रत्येक statement मध्ये Effect, Action व Resource लिहा.
  3. Task ला लागेल तेवढंच द्या (least privilege).
  4. Double quotes व commas नीट वापरा. Check answer दाबा.

मध्यम एक item delete करा

का: पूर्ण primary key ने delete करा.

काय करायचं: lisboatiles-orders मधून orderId "o-099" item delete करा.

कसं करायचं:
  1. Task वाचा आणि ते कोणत्या AWS service बद्दल आहे ते ठरवा.
  2. aws लिहा, मग service चं नाव, मग operation (action शब्द).
  3. प्रत्येक आवश्यक flag (--name) व त्यापुढे task मधली value लिहा.
  4. Flags कोणत्याही क्रमाने चालतात. Check answer दाबा.

अवघड Read capacity units

का: Provisioned tables ला योग्य RCU लागतो.

काय करायचं: 6 KB items चे strongly consistent reads, 10/sec. किती RCU?

कसं करायचं:
  1. Task मधले numbers लिहून घ्या.
  2. कागदावर step by step काढा.
  3. Box मध्ये फक्त final उत्तर लिहा.
  4. Check answer दाबा.

अवघड DynamoDB table बनवा

का: On-demand billing म्हणजे per request पैसे, capacity planning नाही.

काय करायचं: lisboatiles-orders table बनवा, partition key orderId (string), on-demand billing.

कसं करायचं:
  1. Task वाचा आणि ते कोणत्या AWS service बद्दल आहे ते ठरवा.
  2. aws लिहा, मग service चं नाव, मग operation (action शब्द).
  3. प्रत्येक आवश्यक flag (--name) व त्यापुढे task मधली value लिहा.
  4. Flags कोणत्याही क्रमाने चालतात. Check answer दाबा.

अवघड Partition key ने query करा

का: Query फक्त जुळणारे items वाचतो, Scan पूर्ण table वाचतो.

काय करायचं: lisboatiles-payments table मध्ये customerId = "c-77" ची query, expression customerId = :c वापरून.

कसं करायचं:
  1. Task वाचा आणि ते कोणत्या AWS service बद्दल आहे ते ठरवा.
  2. aws लिहा, मग service चं नाव, मग operation (action शब्द).
  3. प्रत्येक आवश्यक flag (--name) व त्यापुढे task मधली value लिहा.
  4. Flags कोणत्याही क्रमाने चालतात. Check answer दाबा.

अवघड TTL सुरू करा

का: TTL expired items free मध्ये delete करतो, उदा. OTPs किंवा sessions.

काय करायचं: lisboatiles-otp table वर expiresAt attribute वापरून TTL enable करा.

कसं करायचं:
  1. Task वाचा आणि ते कोणत्या AWS service बद्दल आहे ते ठरवा.
  2. aws लिहा, मग service चं नाव, मग operation (action शब्द).
  3. प्रत्येक आवश्यक flag (--name) व त्यापुढे task मधली value लिहा.
  4. Flags कोणत्याही क्रमाने चालतात. Check answer दाबा.

उजळणी, तुलना आणि मुलाखत cards

हा lesson काही मिनिटांत revise करा. Cards phone वर save करा किंवा PNG download करा. प्रत्येक card वरचा QR हा lesson उघडतो.

DynamoDB put / get. Apps दिवसभर single items वाचतात, लिहितात. Items type letters: S, N. put-item, get-item, update-item, delete-item. Overwrite टाळायला --condition-expression.
उजळणी card: DynamoDB put / get · PNG download करा · Card page उघडा
Query, scan नाही. पूर्ण table वाचणं slow, महाग. Query PK आणि SK range वापरतो. Scan सगळं वाचून filter. नवीन pattern? GSI जोडून query.
उजळणी card: Query, scan नाही · PNG download करा · Card page उघडा
Query vs Scan. एक partition key. / पूर्ण table.
तुलना: Query vs Scan · PNG download करा · Card page उघडा
Partition vs sort key?. Partition key data कुठे ते ठरवतो. Sort key order आणि ranges. Access patterns वरून keys design.
मुलाखत card: Partition vs sort key? · PNG download करा · Card page उघडा

अजून cards: Ravi Sir's Cards.