AWS Certified Developer - Associate (DVA-C03) free question 5 / 10 · Domain 2: Security
A REST API in Amazon API Gateway uses a Lambda authorizer and a Lambda proxy integration. After the authorizer validates a token, the backend function needs the caller's tenant ID, which the authorizer has already looked up. How should the authorizer hand the tenant ID to the backend?
- Return the tenant ID as an extra field inside a policy statement of the policyDocument that the authorizer returns to API Gateway
- Return the tenant ID in a JSON object as the value of a key in the context map, so that the backend can read its fields
- Return the tenant ID as a string value in the context map of the authorizer output and read it from the backend's request context
- Return the tenant ID in place of the Resource ARN in the policy statement, so that the backend can recover it from the ARN
Show the answer and explanation
Answer: C
Why this is correct
The output of a Lambda authorizer must include a principal identifier and a policy document, and it can also include a context map of key-value pairs. With a Lambda proxy integration, API Gateway passes the context object directly to the backend function as part of the input event, so the function can read each key from the authorizer entry of the request context. The values of the map are stringified, and a value cannot be a JSON object or an array, so the tenant ID goes in as a string.
Why the other options are wrong
"Return the tenant ID as an extra field inside a policy statement of the policyDocument that the authorizer returns to API Gateway" … A policy statement specifies whether to allow or deny an action on a resource. It is not a place for custom values, and the backend is not given the policy document.
"Return the tenant ID in a JSON object as the value of a key in the context map, so that the backend can read its fields" … A context map value cannot be a JSON object or an array. The values must be strings, numbers or booleans, which are stringified when they are returned to the backend.
"Return the tenant ID in place of the Resource ARN in the policy statement, so that the backend can recover it from the ARN" … The Resource element names the API method that the policy allows or denies. Changing it breaks the authorization decision and is not the mechanism for passing values to the backend.
Key points
Pass data from a Lambda authorizer to the backend through the context map (string, number or boolean values), not through the policy document.