10
votes

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
2
I hope someone has a solution or at least some ready-made custom resource, because meanwhile I'm stuck doing it manually. - Laurent Jalbert Simard
ya.. also It overrides the manual setting every deployment. - Nagalakshmi Srirama

2 Answers

2
votes

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

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

2
votes

It is now supported by Serverless framework and there is no need for a plugin. You need to add the following configuration to they serverless.yml file:

provider:
  name: aws

  logs:
    restApi: true

Notice that it was added in version 1.42.0.