A developer is using AWS Serverless Application Model (SAM) to deploy a serverless API. The application uses a Lambda function triggered by an API Gateway API (defined as an `Api` event source) to retrieve records from a database. During testing, the API Gateway endpoint returns a 502 Bad Gateway error. The Lambda function logs indicate that it executed successfully and returned the database records, but the integration failed. Additionally, the developer needs to store the database credentials securely and ensure they are rotated automatically.
Which of the following actions should the developer take to resolve the integration error and meet the security requirements? (Select TWO.)
- Format the Lambda function's return payload to include the statusCode, headers, and body fields.Cevap
- Store the database credentials in AWS Secrets Manager and configure automatic rotation for the secret.Cevap
- CModify the API Gateway integration in the template to use a custom integration, and configure the Lambda function handler to parse the request mapping templates.
- DStore the database credentials in AWS Systems Manager Parameter Store as a SecureString, and enable the built-in Parameter Store automatic rotation feature.
- EUpdate the trust policy of the Lambda execution role to allow the API Gateway service principal (apigateway.amazonaws.com) to assume the role.
Cevap
Format the Lambda function's return payload to include the statusCode, headers, and body fields, and store the database credentials in AWS Secrets Manager and configure automatic rotation for the secret.
The correct options are to format the Lambda function's return payload with status code, headers, and body fields, and to store the credentials in AWS Secrets Manager with automatic rotation. Because the default SAM Api event source deploys API Gateway with Lambda proxy integration, the Lambda response must adhere to a specific structure. Additionally, Secrets Manager is the correct service to use because it supports native automated credential rotation, whereas Systems Manager Parameter Store does not.
Adım Adım Çözüm
Anahtar Kavram
AWS SAM templates default to API Gateway Lambda proxy integrations, requiring structured JSON responses from the backend Lambda function, and security credentials requiring rotation should be managed by AWS Secrets Manager.