A developer is securing a REST API in Amazon API Gateway for a social media application. Users authenticate via a web frontend using Amazon Cognito. The developer needs to restrict access to the API Gateway resources to authenticated users only and pass the user's username and email to the backend AWS Lambda function for auditing. The solution must minimize custom code and use built-in API Gateway features. Which two steps must the developer perform to meet these requirements? (Select TWO.)
- Configure an API Gateway Cognito User Pool Authorizer and associate it with the API methods.Cevap
- In the backend Lambda function, extract the user's identity details from the event.requestContext.authorizer.claims context object.Cevap
- CConfigure an API Gateway Cognito Identity Pool Authorizer and associate it with the API methods.
- DCreate an API Gateway Lambda Custom Authorizer to validate the JWT and return an IAM policy allowing the request.
- EConfigure a Lambda Custom Integration (non-proxy) and parse the Authorization header inside the Lambda function using a mapping template.
Cevap
Configure an API Gateway Cognito User Pool Authorizer and associate it with the API methods, and extract the user's identity details from the event.requestContext.authorizer.claims context object in the backend Lambda function.
To secure the API with minimal custom code, the developer should configure an API Gateway Cognito User Pool Authorizer. This built-in authorizer natively validates JSON Web Tokens (JWTs) issued by Cognito User Pools. Once validated, API Gateway automatically propagates the user's token claims (including email and username) to the backend integration, where they can be extracted directly from the requestContext.authorizer.claims context variable inside the Lambda function.
Adım Adım Çözüm
Anahtar Kavram
API Gateway Cognito User Pools Integration