我们有一个位于私人安全组内部的 lambda,它需要通过互联网调用外部 API。为此,我们决定使用代理 REST API,该 API 允许 lambda 使用内部 AWS 地址调用端点,如下所示:
https://<myapigatewayid>.execute-api.<my-region>.amazonaws.com/<myname>/<my-proxy-call-path>/?arg1=123&arg2=345
代理集成如下所示:
MyAPIGetProxyMethod:
Type: AWS::ApiGateway::Method
Properties:
ResourceId: !Ref MyAPIGetProxyResource
RestApiId: !Ref Proxy
AuthorizationType: NONE
HttpMethod: GET
RequestParameters:
method.request.querystring.arg1: true
method.request.querystring.arg2: true
Integration:
IntegrationHttpMethod: GET
Type: HTTP_PROXY
RequestParameters:
integration.request.header.Authorization: "'Bearer <my-bearer-token>'"
integration.request.querystring.arg1: method.request.querystring.arg1
integration.request.querystring.arg2: method.request.querystring.arg2
Uri: https://some.api.com/reports/
该调用在某些情况下有效,但在其他情况下无效,并且它似乎取决于传入的调用参数。我们真的很想查看正在调用的实际转换后的 URL,以便查看格式是否为正确。
问:有谁知道如何为API配置APIGateway日志,以便它能够吐出转换后的URL?目前我们的日志格式如下:
requestId: $context.requestId, ip: $context.identity.sourceIp, caller: $context.identity.caller, user: $context.identity.user, contextPath: $context.path, contextOverRidePath: $context.requestOverride.path.path_name, requestTime: $context.requestTime, httpMethod: $context.httpMethod, resourcePath: $context.resourcePath, status: $context.status, protocol: $context.protocol, responseLength: $context.responseLength
您需要在阶段属性中启用完整请求和响应日志(或为单个方法覆盖它们)。
AWS::ApiGateway::Deployment/MethodSetting/LoggingLevel
设置为 INFO
来完成
DataTraceEnabled
设置为 ON