0
0
DynamoDBquery~20 mins

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

Choose your learning style9 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.