Reputation: 2382
I always get a 500 Internal Server Error
when I try to call my GET endpoint that I defined using SAM.
I am able to define a POST request that works.
For the GET request it's showing me:
Lambda invocation failed with status: 403
Execution failed due to configuration error:
I think something is wrong where I define my DefinitionBody of my API Gateway.
Globals:
Api:
Cors:
AllowMethods: "'GET,POST,OPTIONS'"
AllowHeaders: "'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'"
AllowOrigin: "'*'"
Resources:
getFunction:
Type: 'AWS::Serverless::Function'
Properties:
...
Events:
GetApi:
Type: Api
Properties:
Path: /tips
Method: GET
RestApiId: !Ref MyApi
MyApi:
Type: AWS::Serverless::Api
Properties:
StageName: dev
EndpointConfiguration: REGIONAL
DefinitionBody:
swagger: "2.0"
info:
title: "API"
paths:
/tips:
get:
x-amazon-apigateway-integration:
uri:
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${getFunction.Arn}/invocations
responses: {}
httpMethod: "POST"
type: "aws_proxy"
I already tried changing httpMethod on the x-amazon-apigateway-integration to "GET" but that is not solving my problem.
In the AWS Lambda console I see that the Lambda and Api Gateway are linked, yet I am unable to invoke the Lambda through the API Gateway. I can execute my Lambda successfully with a Test Event in the Console. It's definitely something on the API Gateway side.
Can someone verify what I am doing wrong?
Upvotes: 0
Views: 1336
Reputation: 2382
After further digging around I found that I had to implement the GET
method of the /tips
path like this:
get:
responses:
'200':
description: 200 response
headers:
Content-Type:
type: string
produces:
- application/json
x-amazon-apigateway-integration:
uri:
Fn::Sub: "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${getTipsFunction.Arn}/invocations"
passthroughBehavior: when_no_match
responses:
default:
statusCode: 200
responseParameters:
method.response.header.Content-Type: integration.response.header.content-type
httpMethod: POST
type: aws
This solves the problem.
Upvotes: 0