A developer uses the AWS Serverless Application Model (SAM) to deploy a serverless application. The template defines an AWS::Serverless::Function resource with an Api event source, as shown in the following snippet:
yaml
Resources:
ProcessOrderFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs18.x
CodeUri: ./src
Events:
CreateOrder:
Type: Api
Properties:
Path: /orders
Method: post
The application deploys successfully. However, when clients send a POST request to /orders, the API Gateway returns a 502 Bad Gateway status code, and the Lambda function execution logs show that the function ran and completed successfully without errors.
Which of the following describes the cause of this issue and the correct resolution?
- AThe Lambda function execution exceeded its default timeout limit because SAM functions default to a timeout of 3 seconds. To resolve this, increase the Timeout property under the resource Properties in the SAM template.
- BThe SAM template is missing the Transform declaration at the root level, causing API Gateway to fail to map the incoming request to the Lambda function. To resolve this, add 'Transform: AWS::Serverless-2016-10-31' to the template.
- The default integration type for the SAM Api event is a Lambda proxy integration. The Lambda function returned a plain text string instead of a structured JSON response containing the statusCode and body fields, which API Gateway requires. To resolve this, modify the Lambda function return value to match the expected JSON structure.Cevap
- DThe IAM execution role assigned to the Lambda function has an invalid trust policy that does not trust the API Gateway service principal. To resolve this, update the trust policy to allow 'apigateway.amazonaws.com' to assume the role.