skip to Main Content

We have a lambda sitting inside of a private security group which needs to make a call to an outside API across the internet. To do this we decided to go with a proxy REST API that will allow the lambda to call the endpoint using an internal AWS address like this:

https://<myapigatewayid>.execute-api.<my-region>.amazonaws.com/<myname>/<my-proxy-call-path>/?arg1=123&arg2=345

The proxy integration looks like this:

    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/

We want to log the actual transformed URL that is being called in order to see if the format is correct. Ie something like this:

https://some.api.com/reports/?arg1=123&arg2=345

Q: does anyone know how to configure the APIGateway log for the API so that it will log the transformed URL? Currently our log format looks like this:

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

2

Answers


  1. Chosen as BEST ANSWER

    An update on this. The needed logs were apparently available to us the whole time, just not where we expected.

    We had been looking at the CloudWatch log group configured for the API-Gateway REST API proxying our calls. While there were logs in there they did not contain the transformed URI we wanted to see. Instead we found them in another log group that API Gateway seems to configure automatically named API-Gateway-Execution-Logs_<api-id>/<stage>. In this log group we found the transformed URI we needed. It looked like this:

    (ea182623-ac18-49bb-a6d4-95bee66a5039) Endpoint request URI: https://some.api.com/reports/?arg1=123&arg2=345
    

    I do believe that Quassnoi's answer is also correct in that you still need full request and response logs configured for this to work.


  2. You need to enable Full Request and Response Logs in your stage properties (or override them for an individual method).

    In CloudFormation, it’s done by setting AWS::ApiGateway::Deployment/MethodSetting/LoggingLevel to INFO

    Make sure that you also have DataTraceEnabled set to ON

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search