Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to enable api gateway logs via cloud formation template (serverless.yml)?

I want to enable api gateway logs for my api gateway which is the wraparound for my lambda function.

service: myservice

provider:
  name: aws
  runtime: python3.6
  stage: ${opt:stage}
  region: ${self:custom.AwsRegion}
  timeout: 130
  memorySize: 128


functions:
  create_user:
    handler: functions/create_user.lambda_handler

    events:
      - http:
          path: /create_user
          method: post
          authorizer: aws_iam
          private: true

When I deploy this I do see lambda logs in cloud watch. But API gateway logs are not being recoded in cloudwatch. Can any one enlighten me on cloud formation syntax to enable logs for my api gate way?

I tried adding below code, but looks like it is trying to create new api endpoint.

resources: Resources:

ApiGatewayStage:
  Type: AWS::ApiGateway::Stage
  Properties:
    RestApiId:
        Ref: ApiGatewayRestApi
    StageName: ${opt:stage}
    MethodSettings:
      - DataTraceEnabled: true
        HttpMethod: "*"
        LoggingLevel: INFO
        ResourcePath: "/*"
        MetricsEnabled: true
like image 993
Nagalakshmi Srirama Avatar asked Sep 22 '17 18:09

Nagalakshmi Srirama


People also ask

How do I enable CloudWatch Logs for API gateway using CloudFormation?

Enabling logging in API Gateway for your stage is fairly easy. You go into the Console, setup a role for API Gateway to use for logging, find the stage and enable logs. It will enable logging for all methods within that stage.


1 Answers

You can do it via external plugins and the solution is discussed in detail here.

https://github.com/serverless/serverless/issues/1918

like image 137
Kannaiyan Avatar answered Oct 21 '22 05:10

Kannaiyan