Sample questions with answers and explanations
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.