'API Gateway Access Log using Cloudformation

I need to enable Custom Access Logging in API Gateway. The cloudformation is written in yaml. But for the format of the custom logs it is in json, xml such formats but nothing is mentioned how to set format of access log in yaml. Does anyone knows how to do it?



Solution 1:[1]

From the CloudFormation user guide, the Format attribute requires your input to be String.

  DestinationArn: String
  Format: String

For example:

  DestinationArn: !Sub ${ApiAccessLogGroup.Arn}
  Format: "{ 'requestId':'$context.requestId', 'ip': '$context.identity.sourceIp', 'caller':'$context.identity.caller', 'user':'$context.identity.user','requestTime':'$context.requestTime', 'xrayTraceId':'$context.xrayTraceId', 'wafResponseCode':'$context.wafResponseCode', 'httpMethod':'$context.httpMethod','resourcePath':'$context.resourcePath', 'status':'$context.status','protocol':'$context.protocol', 'responseLength':'$context.responseLength' }"

To simplify your String or make it looks better, please use !Sub as this post.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Binh Nguyen