How to enable api gateway logs through cloud formation template (serverless.yml)?

I want to enable api gateway logs for my api gateway, which is protection 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 see lambda logs in the cloud clock. But the API gateway logs are not recoded into cloudwatch. Can someone enlighten me on cloud formation syntax to enable logs for my api path?

I tried adding the code below, but it looks like it is trying to create a new API point.

Resources: Resources:

ApiGatewayStage:
  Type: AWS::ApiGateway::Stage
  Properties:
    RestApiId:
        Ref: ApiGatewayRestApi
    StageName: ${opt:stage}
    MethodSettings:
      - DataTraceEnabled: true
        HttpMethod: "*"
        LoggingLevel: INFO
        ResourcePath: "/*"
        MetricsEnabled: true
+6
source share
2 answers

You can do this through external plugins, and this solution is discussed in detail here.

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

+1

Serverless Framework . serverless.yml:

provider:
  name: aws

  logs:
    restApi: true

, 1.42.0.

0

Source: https://habr.com/ru/post/1686242/


All Articles