Question 1
An API Gateway REST API stage has caching enabled with a TTL of 300 seconds. A support tool must sometimes fetch fresh data by sending the Cache-Control: max-age=0 header, but the cache continues to return cached responses. Other clients must not be able to bypass the cache. What should the developer do?
- Require authorization for cache invalidation, and grant the support tool's IAM role the execute-api:InvalidateCache permission. — Correct
- Add the Cache-Control header as a cache key parameter on the method so that requests with max-age=0 are cached separately from other requests.
- Flush the entire stage cache from the console each time the support tool needs to read fresh data.
- Set the stage's cache TTL to 0 seconds so that every request from every client goes to the backend integration.
Correct answer
Require authorization for cache invalidation, and grant the support tool's IAM role the execute-api:InvalidateCache permission.
Explanation
Clients can invalidate cache entries with Cache-Control: max-age=0 when authorized, and requiring the InvalidateCache permission limits this to approved callers. A TTL of 0 disables caching for all clients. A cache key parameter does not force a backend call. Flushing the cache by hand affects everyone.
Question 2
A web application at https://app.example.com uploads files from the browser directly to S3 by using presigned PUT URLs. The upload requests fail with a CORS error in the browser. What should the developer do?
- Add a CORS configuration to the bucket that allows PUT from https://app.example.com with the required headers. — Correct
- Generate the presigned URLs with a longer expiration time and the content type included so that the browser's preflight check passes.
- Add a bucket policy that allows s3:PutObject only when the aws:Referer condition key matches https://app.example.com for the request.
- Enable static website hosting on the bucket so that it accepts requests from other domains.
Correct answer
Add a CORS configuration to the bucket that allows PUT from https://app.example.com with the required headers.
Explanation
Browsers need the bucket to return CORS headers for cross-origin PUT requests. A bucket policy controls authorization, not CORS. Website hosting does not support PUT. The expiration time does not affect CORS.
Question 3
Some messages in an SQS queue always cause the consuming Lambda function to fail. These messages are retried until they expire, which wastes compute and delays other messages. What should the developer do?
- Configure a dead-letter queue on the Lambda function in the function's asynchronous invocation settings.
- Reduce the queue's message retention period so that failing messages expire more quickly.
- Increase the queue's visibility timeout so that failing messages are retried less often.
- Configure a redrive policy on the source queue with a dead-letter queue and a maxReceiveCount value. — Correct
Correct answer
Configure a redrive policy on the source queue with a dead-letter queue and a maxReceiveCount value.
Explanation
A redrive policy moves a message to a DLQ after it has been received maxReceiveCount times. The function's DLQ setting applies only to asynchronous invocations, not SQS event sources. Shorter retention loses good messages too. A longer visibility timeout only delays retries.
Question 4
An application stores orders in an existing DynamoDB table with OrderId as the partition key. A new feature must retrieve all orders for a given CustomerId sorted by OrderDate. The table contains several terabytes of data and must not be recreated. Which solution meets these requirements MOST efficiently?
- Create a global secondary index with CustomerId as the partition key and OrderDate as the sort key, and query the index. — Correct
- Enable DynamoDB Streams and copy every order into a second table that uses CustomerId and OrderDate as its keys.
- Run a Scan operation with a FilterExpression on CustomerId and sort the returned items by OrderDate in the application.
- Create a local secondary index with CustomerId as the partition key and OrderDate as the sort key, and query the index.
Correct answer
Create a global secondary index with CustomerId as the partition key and OrderDate as the sort key, and query the index.
Explanation
A GSI can be added to an existing table and supports a different partition key. An LSI must share the table's partition key and can only be created when the table is created. A Scan reads the whole table and is inefficient. A second table maintained from Streams works but adds code and cost compared with a GSI.
Question 5
A payment Lambda function is invoked asynchronously. Lambda retries cause some payments to be charged twice. The developer must make the function safe to retry with the LEAST custom code. What should the developer do?
- Add reserved concurrency of 1 so that only one copy of the function can run at the same time.
- Use the idempotency utility from Powertools for AWS Lambda with a DynamoDB table and the payment ID as the idempotency key. — Correct
- Set the function's maximum retry attempts for asynchronous invocation to 0 so that Lambda never runs a failed payment event a second time.
- Switch the event source to an SQS FIFO queue with content-based deduplication so that each payment message is processed exactly once.
Correct answer
Use the idempotency utility from Powertools for AWS Lambda with a DynamoDB table and the payment ID as the idempotency key.
Explanation
The Powertools idempotency utility stores processed keys and returns the stored result for repeats. Turning off retries loses legitimate retries. FIFO queues still deliver at least once to consumers on failure. Concurrency of 1 does not stop a retry from running again.
Question 6
A developer is building an inventory service that stores items in an Amazon DynamoDB table. Two instances of the service sometimes read the same item, modify the quantity, and write it back at the same time, which causes one update to be lost. The developer must prevent lost updates without serializing all writes through a single process. What should the developer do?
- Set ConsistentRead to true on every GetItem call so that each instance always reads the latest committed quantity before it writes the new value.
- Wrap each read in a TransactGetItems call and each write in a separate TransactWriteItems call so that both operations run as transactions.
- Add a version number attribute to each item and use a ConditionExpression on UpdateItem that requires the version to match the value that was read. — Correct
- Enable DynamoDB Streams and use a Lambda function to detect conflicting writes and reapply the lost changes after they occur.
Correct answer
Add a version number attribute to each item and use a ConditionExpression on UpdateItem that requires the version to match the value that was read.
Explanation
Optimistic locking with a conditional write rejects an update if another writer changed the item after it was read. Strongly consistent reads still allow two writers to read the same value and overwrite each other. Detecting conflicts after the fact does not prevent them. A read transaction followed by a separate write transaction is not atomic across the two calls.
Question 7
A DynamoDB table stores clickstream events with EventDate (for example, 2026-11-22) as the partition key. During business hours, writes are throttled even though total consumed capacity is well below the table's provisioned capacity. What should the developer do?
- Increase the table's provisioned write capacity and enable auto scaling so that capacity rises automatically during business hours each day.
- Create a global secondary index with EventDate as its partition key so that DynamoDB spreads the writes across the index's partitions.
- Put DynamoDB Accelerator (DAX) in front of the table to buffer writes during business hours.
- Add a random suffix to the partition key, such as EventDate#1 to EventDate#10, and query all suffixes when reading a day's events. — Correct
Correct answer
Add a random suffix to the partition key, such as EventDate#1 to EventDate#10, and query all suffixes when reading a day's events.
Explanation
All of the day's writes go to one partition key, which creates a hot partition. Write sharding spreads the writes across partitions. More capacity does not raise the per-partition limit. A GSI on the same key has the same hot spot and adds write cost. DAX caches reads and passes writes through.
Question 8
A company uses an AWS Lambda function to process messages from an Amazon SQS standard queue with a batch size of 10. When one message in a batch fails, the entire batch returns to the queue and successful messages are processed again, which creates duplicate records downstream. The developer must ensure that only the failed messages are retried while keeping the current throughput. Which solution meets these requirements with the LEAST development effort?
- Replace the standard queue with an SQS FIFO queue and enable content-based deduplication on the queue.
- Configure an on-failure destination on the Lambda function that sends failed invocation records, including the message body, to a second SQS queue.
- Enable ReportBatchItemFailures on the event source mapping and return the IDs of the failed messages in the batchItemFailures response. — Correct
- Reduce the batch size of the event source mapping to 1 so that each invocation processes a single message.
Correct answer
Enable ReportBatchItemFailures on the event source mapping and return the IDs of the failed messages in the batchItemFailures response.
Explanation
Partial batch responses let the function report only the failed message IDs, so successful messages are deleted and only failures return to the queue. A batch size of 1 avoids duplicates but sharply reduces throughput. Function destinations apply to asynchronous invocations, not SQS polling. FIFO deduplication only covers duplicate sends within 5 minutes and does not stop batch reprocessing.
Question 9
A company publishes order events to an Amazon SNS topic. Three SQS queues subscribe to the topic, but each consumer needs only orders of a certain type, which is sent in a message attribute. The publisher code must not change. What is the MOST efficient solution?
- Have each consumer read every message from its queue and delete messages that it does not need.
- Add a Lambda function between SNS and each queue that forwards only the matching order types.
- Add an SNS subscription filter policy to each subscription that matches the required order type. — Correct
- Create three separate SNS topics and route each order type to its own topic before publishing.
Correct answer
Add an SNS subscription filter policy to each subscription that matches the required order type.
Explanation
Filter policies deliver only matching messages to each subscriber without publisher changes. Separate topics require the publisher to change. Discarding messages in consumers wastes processing. Intermediate functions add cost and code.
Question 10
A developer created a global secondary index with the KEYS_ONLY projection. A new screen queries the index and must also show the status attribute, but the returned items do not include status. What should the developer do so that the query returns status with the LEAST read cost?
- Set ConsistentRead to true on the Query request so that DynamoDB returns all item attributes.
- Add status to the ProjectionExpression of the Query request so that DynamoDB fetches it from the base table.
- Create a new GSI that uses an INCLUDE projection containing the status attribute, and query the new index. — Correct
- Run a Scan on the base table with a FilterExpression on the key values returned by the index.
Correct answer
Create a new GSI that uses an INCLUDE projection containing the status attribute, and query the new index.
Explanation
A GSI returns only projected attributes, and a projection cannot be changed after creation. A new index with an INCLUDE projection returns status. A ProjectionExpression cannot fetch attributes that are not projected. GSIs do not support strongly consistent reads. A Scan is expensive.