A developer is implementing a custom Lambda authorizer for Amazon API Gateway. The authorizer must validate incoming JSON Web Tokens (JWT) using a secret client key that is updated manually every six months. The API receives millions of requests daily, and the developer wants to minimize AWS service costs associated with secret retrieval while maintaining security. Which strategy should the developer use?
- Store the secret client key as a SecureString parameter in AWS Systems Manager Parameter Store. Retrieve the parameter outside the Lambda handler function to cache it, and enable caching on the API Gateway authorizer.Answer
- BStore the secret client key in AWS Secrets Manager. Retrieve the secret inside the Lambda handler function on every invocation using the AWS SDK.
- CStore the secret client key as an unencrypted environment variable in the Lambda function's configuration to avoid parameter retrieval overhead.
- DStore the secret client key as a String parameter in AWS Systems Manager Parameter Store. Retrieve the parameter inside the Lambda handler function on every invocation.
Answer
Store the secret client key as a SecureString parameter in AWS Systems Manager Parameter Store, retrieve it outside the Lambda handler for caching, and enable authorizer caching in API Gateway.
Storing the key as a SecureString in Systems Manager Parameter Store satisfies the security requirement by encrypting the secret at rest with AWS KMS. Since the key is rotated manually every six months, the automatic rotation features of Secrets Manager are not needed. Choosing Parameter Store is highly cost-effective because standard parameters do not incur API request fees. Furthermore, caching the secret outside the Lambda handler ensures it is reused across warm container invocations, and enabling authorizer caching in API Gateway prevents invoking the Lambda function for every incoming client request.
Step-by-Step Solution
Key Concept
Parameter Store vs Secrets Manager cost and features trade-offs
Estimated Time:1m 30s