从API网关SAM配置返回401响应代码

时间:2020-05-27 16:13:39

标签: amazon-web-services aws-api-gateway aws-sam

我有一个通过API网关调用的.NET Core Lambda函数,该函数调用此方法:

select CustomerId, CampaignID  from Table12 where (CustomerId, CampaignID) in (CustomerToCampaign_1, CustomerToCampaign_2)

函数[Microsoft.AspNetCore.Mvc.HttpGet("{key}", Name = "Get")] public async Task<IEnumerable<TestData>> Get(string key) { var exceptionMessage = new HttpResponseMessage(HttpStatusCode.Unauthorized) { ReasonPhrase = "UNAUTHORIZED" }; throw new HttpResponseException(exceptionMessage); } 的事件部分:

AWS::Serverless::Function

我希望API将401响应代码返回给客户端,但实际上却是500:

错误类型→HttpResponseException

(我正在使用Events: Root: Type: Api Properties: RestApiId: !Ref TestApi Path: / Method: ANY ProxyResource: Type: Api Properties: RestApiId: !Ref TestApi Path: /{proxy+} Method: ANY 在本地测试)

我正在努力处理文档,但是我认为我需要set the GatewayResponses

我尝试将其添加到GatewayResponses:

sam local start-api

在SAM框架中,如何确保将所需的响应代码返回给客户端?

0 个答案:

没有答案