A developer is deploying a serverless application using the AWS Serverless Application Model (SAM). The template defines an AWS::Serverless::Api resource with an OpenAPI specification in the DefinitionBody property. The template also defines an AWS::Serverless::Function resource.
Within the OpenAPI specification, the developer configures the integration for a POST route as follows:
yaml
paths:
/orders:
post:
x-amazon-apigateway-integration:
type: "aws"
httpMethod: "POST"
uri:
Fn::Sub: "arn:aws:apigateway:{OrderFunction.Arn}/invocations"
The Lambda function handler is implemented to return the following structure:
{
"statusCode": 201,
"body": "{\"message\": \"Order created successfully\"}",
"headers": {
"Content-Type": "application/json"
}
}
When the client sends a POST request to /orders, it receives an HTTP status code of 200 OK with the following response body:
{
"statusCode": 201,
"body": "{\"message\": \"Order created successfully\"}",
"headers": {
"Content-Type": "application/json"
}
}
Which configuration change should the developer make to ensure the client receives an HTTP status code of 201 Created with the message body '{"message": "Order created successfully"}'?
- AModify the Lambda function handler to return only the JSON string '{"message": "Order created successfully"}' directly as the payload.
- Change the integration type to 'aws_proxy' in the x-amazon-apigateway-integration extension inside the OpenAPI specification.Answer
- CUpdate the Lambda function's execution role to define the 'apigateway.amazonaws.com' service principal as a trusted entity in the trust policy.
- DRemove the 'Transform: AWS::Serverless-2016-10-31' line from the top of the template and deploy the stack.