最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - return 401 from lambda non-proxy api gateway and return headers - Stack Overflow

programmeradmin0浏览0评论

How do I return 401 to the client, based on the statusCode returned from the lambda? (non-proxy integration). How do I return the headers from the headers field? (for 401 and 200)

return {
 "statusCode": 401,
 "headers": {"myHeader": 'abcd "efg"'}
}

with this cdk:

unauthorized_integration_response = _api_gw.IntegrationResponse(
    status_code="401",
    response_parameters=response_integration_parameters,
    selection_pattern='.*statusCode:401.*',
)
response_parameters = {
    "method.response.header.Access-Control-Allow-Headers": True,
    "method.response.header.Access-Control-Allow-Origin": True,
    "method.response.header.Access-Control-Allow-Methods": True,
    "method.response.header.Strict-Transport-Security": True,
    "method.response.header.Content-Security-Policy": True,
    "method.response.header.X-Frame-Options": True,
}
unauthorized_method_response = _api_gw.MethodResponse(
    status_code="401", response_parameters=response_parameters
)

myresource.add_method(
    "GET",
    _api_gw.LambdaIntegration(
        lambda_func,
        proxy=False,
        request_templates=default_request_template,
        integration_responses=[
            default_integration_response,
            unauthorized_integration_response,
        ],
    ),
    method_responses=[default_method_response, unauthorized_method_response],
)

发布评论

评论列表(0)

  1. 暂无评论