Bird
Raised Fist0
DynamoDBquery~20 mins

AWS SDK for JavaScript/Node.js in DynamoDB - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
AWS SDK for JavaScript DynamoDB Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ service_behavior
intermediate
2:00remaining
What is the output of this DynamoDB query code?

Consider this AWS SDK for JavaScript code querying a DynamoDB table named Users for items where age is greater than 25.

const { DynamoDBClient, QueryCommand } = require("@aws-sdk/client-dynamodb");
const client = new DynamoDBClient({ region: "us-east-1" });

const params = {
  TableName: "Users",
  KeyConditionExpression: "#age > :ageVal",
  ExpressionAttributeNames: { "#age": "age" },
  ExpressionAttributeValues: { ":ageVal": { N: "25" } }
};

async function run() {
  try {
    const data = await client.send(new QueryCommand(params));
    console.log(data.Items.length);
  } catch (err) {
    console.error(err);
  }
}

run();

What will happen when this code runs?

DynamoDB
const { DynamoDBClient, QueryCommand } = require("@aws-sdk/client-dynamodb");
const client = new DynamoDBClient({ region: "us-east-1" });

const params = {
  TableName: "Users",
  KeyConditionExpression: "#age > :ageVal",
  ExpressionAttributeNames: { "#age": "age" },
  ExpressionAttributeValues: { ":ageVal": { N: "25" } }
};

async function run() {
  try {
    const data = await client.send(new QueryCommand(params));
    console.log(data.Items.length);
  } catch (err) {
    console.error(err);
  }
}

run();
AThe code throws a ValidationException because KeyConditionExpression must use the partition key, not a non-key attribute.
BThe code returns all items where age > 25 and prints the count of those items.
CThe code throws a SyntaxError due to invalid ExpressionAttributeNames syntax.
DThe code returns zero items because the filter condition is incorrect.
Attempts:
2 left
💡 Hint

Remember that Query requires the partition key in the KeyConditionExpression.

❓ Configuration
intermediate
2:00remaining
Which option correctly configures AWS SDK client with credentials from environment variables?

You want to create a DynamoDB client in Node.js using AWS SDK v3 that automatically uses credentials set in environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. Which code snippet correctly achieves this?

Aconst client = new DynamoDBClient({ region: "us-east-1" });
Bconst client = new DynamoDBClient({ region: "us-east-1", credentials: { accessKeyId: process.env.AWS_ACCESS_KEY_ID, secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY } });
Cconst client = new DynamoDBClient({ region: "us-east-1", credentials: fromEnv() });
Dconst client = new DynamoDBClient({ region: "us-east-1", accessKeyId: process.env.AWS_ACCESS_KEY_ID, secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY });
Attempts:
2 left
💡 Hint

The AWS SDK v3 automatically loads credentials from environment variables if no explicit credentials are provided.

❓ Architecture
advanced
2:30remaining
Which architecture best supports high availability for a DynamoDB-based web app using AWS SDK for JavaScript?

You are designing a web application that uses DynamoDB as its database. You want to ensure high availability and low latency globally. Which architecture choice below best supports this goal?

ADeploy the web app in a single region and use DynamoDB Streams to replicate data manually to other regions.
BDeploy the web app in a single AWS region and use DynamoDB Global Tables to replicate data to other regions.
CDeploy the web app in multiple regions but use a single DynamoDB table in one region accessed remotely.
DDeploy the web app in multiple AWS regions with separate DynamoDB tables in each region without replication.
Attempts:
2 left
💡 Hint

Think about automatic multi-region replication and data consistency.

❓ security
advanced
2:30remaining
Which IAM policy least privileges DynamoDB access for a Lambda function to only read items from a specific table?

You want to create an IAM policy for a Lambda function that only allows reading items from the DynamoDB table Orders. Which policy below follows the principle of least privilege?

A{ "Effect": "Allow", "Action": ["dynamodb:GetItem", "dynamodb:Query", "dynamodb:Scan"], "Resource": "arn:aws:dynamodb:us-east-1:123456789012:table/*" }
B{ "Effect": "Allow", "Action": "dynamodb:*", "Resource": "*" }
C{ "Effect": "Allow", "Action": ["dynamodb:GetItem", "dynamodb:Query"], "Resource": "arn:aws:dynamodb:us-east-1:123456789012:table/Orders" }
D{ "Effect": "Allow", "Action": ["dynamodb:GetItem", "dynamodb:Query", "dynamodb:Scan"], "Resource": "arn:aws:dynamodb:us-east-1:123456789012:table/Orders" }
Attempts:
2 left
💡 Hint

Consider which actions are needed to read items and the resource scope.

✅ Best Practice
expert
3:00remaining
What is the best practice to handle DynamoDB throttling errors in AWS SDK for JavaScript?

Your Node.js app using AWS SDK for JavaScript calls DynamoDB frequently and sometimes receives ProvisionedThroughputExceededException errors. What is the best practice to handle these errors?

AImmediately retry the request in a tight loop until it succeeds.
BCatch the error and log it without retrying to avoid extra load.
CImplement exponential backoff with jitter before retrying the request.
DIncrease the provisioned throughput manually each time the error occurs.
Attempts:
2 left
💡 Hint

Think about how to reduce retry collisions and avoid overwhelming the service.

Practice

(1/5)
1. What is the first step to interact with DynamoDB using the AWS SDK for JavaScript/Node.js?
easy
A. Create a DynamoDB client instance
B. Write a SQL query
C. Install a database driver
D. Open a database connection manually

Solution

  1. Step 1: Understand AWS SDK usage

    To work with DynamoDB, you first create a client object that represents the service.
  2. Step 2: Recognize the role of the client

    The client handles requests and responses to DynamoDB; no manual connection or SQL is needed.
  3. Final Answer:

    Create a DynamoDB client instance -> Option A
  4. Quick Check:

    Client creation = First step [OK]
Hint: Always start by creating the service client [OK]
Common Mistakes:
  • Trying to write SQL queries for DynamoDB
  • Assuming manual connection is needed
  • Skipping client creation
2. Which of the following is the correct way to import the DynamoDB client from AWS SDK v3 in Node.js?
easy
A. const DynamoDBClient = require('@aws-sdk/client-dynamodb');
B. const { DynamoDBClient } = require('aws-sdk');
C. import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
D. import DynamoDBClient from 'aws-sdk';

Solution

  1. Step 1: Identify AWS SDK v3 import style

    AWS SDK v3 uses ES modules and named imports from '@aws-sdk/client-dynamodb'.
  2. Step 2: Match correct syntax

    import { DynamoDBClient } from '@aws-sdk/client-dynamodb'; uses ES module import with correct package and named import syntax.
  3. Final Answer:

    import { DynamoDBClient } from '@aws-sdk/client-dynamodb'; -> Option C
  4. Quick Check:

    ES module named import = import { DynamoDBClient } from '@aws-sdk/client-dynamodb'; [OK]
Hint: Use ES module imports from '@aws-sdk/client-dynamodb' [OK]
Common Mistakes:
  • Using old AWS SDK v2 import style
  • Using default import instead of named import
  • Mixing require and import syntax
3. Given the following code snippet, what will be logged if the item exists in the DynamoDB table?
import { DynamoDBClient, GetItemCommand } from '@aws-sdk/client-dynamodb';
const client = new DynamoDBClient({ region: 'us-east-1' });

async function getItem() {
  const command = new GetItemCommand({
    TableName: 'Users',
    Key: { 'UserId': { S: '123' } }
  });
  const response = await client.send(command);
  console.log(response.Item);
}
getItem();
medium
A. Undefined because no item exists
B. An empty object {}
C. An error is thrown due to missing parameters
D. The item object with attributes if found

Solution

  1. Step 1: Understand GetItemCommand behavior

    GetItemCommand returns an object with an Item property if the item exists.
  2. Step 2: Analyze console.log output

    Logging response.Item will show the item's attributes as an object if found.
  3. Final Answer:

    The item object with attributes if found -> Option D
  4. Quick Check:

    response.Item = item object [OK]
Hint: GetItemCommand returns Item if found, else undefined [OK]
Common Mistakes:
  • Expecting an error when item is missing
  • Assuming response itself is the item
  • Confusing empty object with undefined
4. What is wrong with the following code snippet that tries to put an item into DynamoDB?
import { DynamoDBClient, PutItemCommand } from '@aws-sdk/client-dynamodb';
const client = new DynamoDBClient({ region: 'us-east-1' });

async function putItem() {
  const command = new PutItemCommand({
    TableName: 'Users',
    Item: { UserId: '123', Name: 'Alice' }
  });
  await client.send(command);
}
putItem();
medium
A. TableName should be lowercase
B. Item attributes must be wrapped with DynamoDB data types like { S: 'value' }
C. PutItemCommand does not exist in AWS SDK
D. Missing await before client.send

Solution

  1. Step 1: Check Item attribute format

    DynamoDB expects attribute values wrapped in type descriptors like { S: 'string' }.
  2. Step 2: Identify the error cause

    Passing plain strings without type wrappers causes validation errors.
  3. Final Answer:

    Item attributes must be wrapped with DynamoDB data types like { S: 'value' } -> Option B
  4. Quick Check:

    Attribute values need type wrappers [OK]
Hint: Always wrap attribute values with DynamoDB types (S, N, etc.) [OK]
Common Mistakes:
  • Passing plain strings instead of typed attributes
  • Assuming table names are case-insensitive
  • Forgetting to await async calls
5. You want to update a user's email in DynamoDB using AWS SDK for JavaScript/Node.js. Which approach correctly updates only the email attribute without overwriting the entire item?
const command = new UpdateItemCommand({
  TableName: 'Users',
  Key: { UserId: { S: '123' } },
  UpdateExpression: 'SET Email = :email',
  ExpressionAttributeValues: { ':email': { S: 'newemail@example.com' } }
});
await client.send(command);
hard
A. This code correctly updates only the Email attribute
B. UpdateExpression should be 'ADD Email :email' to update
C. You must use PutItemCommand to update attributes
D. ExpressionAttributeValues keys should not start with ':'

Solution

  1. Step 1: Understand UpdateItemCommand usage

    UpdateExpression with 'SET' updates specified attributes without replacing the whole item.
  2. Step 2: Verify ExpressionAttributeValues syntax

    Keys start with ':' and values use DynamoDB types, matching the expression.
  3. Step 3: Confirm no overwrite occurs

    Using UpdateItemCommand with SET updates only Email, preserving other attributes.
  4. Final Answer:

    This code correctly updates only the Email attribute -> Option A
  5. Quick Check:

    UpdateExpression SET = partial update [OK]
Hint: Use UpdateItemCommand with SET to update attributes safely [OK]
Common Mistakes:
  • Using PutItemCommand which overwrites entire item
  • Using ADD instead of SET for attribute update
  • Removing ':' prefix in ExpressionAttributeValues keys
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard