serverless: Cannot activate API gateway logs for shared API gateway

Bug Report

Description

The API gateway log settings are not applied when using a shared API gateway as described here.

  1. What did you do?
  • Created serverless.yml my copying the example from the docs and added
logs:
    restApi: true
  • Ran sls deploy
  1. What happened?
  • API Gateway logs are not enabled.
  1. What should’ve happened?
  • API Gateway logs should have been enabled.
  1. What’s the content of your serverless.yml file?
service: my-api
provider:
  name: aws
  runtime: nodejs12.x
  region: eu-central-1
  logs:
    restApi: true
resources:
  Resources:
    MyApiGW:
      Type: 'AWS::ApiGateway::RestApi'
      Properties:
        Name: MyApiGW
  Outputs:
    apiGatewayRestApiId:
      Value:
        Ref: MyApiGW
      Export:
        Name: MyApiGateway-restApiId
    apiGatewayRestApiRootResourceId:
      Value:
        'Fn::GetAtt':
        - MyApiGW
        - RootResourceId
      Export:
        Name: MyApiGateway-rootResourceId
  1. What’s the output you get when you use the SLS_DEBUG=* environment variable (e.g. SLS_DEBUG=* serverless deploy) No difference. However, if I add a http function I can see that the AWS CLI is used to set the log settings. If no http function is defined, updateStage.js is not called. I tried to remove this line, but then I get
Serverless: [AWS apigateway 200 0.202s 0 retries] getRestApis({ position: undefined, limit: 500 })
 
  Serverless Error ---------------------------------------
 
  ServerlessError: Rest API id could not be resolved.
  This might be caused by a custom API Gateway configuration.
  
  In given setup stage specific options such as `tracing`, `logs` and `tags` are not supported.

I guess as a workaround I can define my own resources. However, I would gladly submit a PR to allow setting this with the log level properties.

Similar or dependent issues:

  • There are several issues on API gateway logs but I did not find the exact same one.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 23 (12 by maintainers)

Commits related to this issue

Most upvoted comments

I will attempt to move the logging config to Terraform, as you suggest. It is not straightforward as the log settings are per Stage and Serverless creates the Stage.

I moved my logging config to Terraform and outside of Serverless, but now terraform thinks it owns the “stage” and the “deployment” (these two are linked), so Terraform will roll back the AWS::ApiGateway::Deployment created by Serverless each time it runs.

Is there any way to have Serverless use a provided APIG but also to configure logging on the APIG?

I am a bit late but have hit this myself, same with the xray tracing.

Can someone explain to me why exactly sls considers it unsafe to set logging options? The API gateway is created externally but the logging and tracing options are on a stage, the stage is deployed as part of the sls cloudformation stack, it would seem that anyone creating an api gw externally and then using sls to attach functions would not be attaching them in say, terraform.

What is the reasoning behind the decision? It seems for me its actually impossible to get the logging working because the stages are never created by terraform, but the api gateway is.

Hi @medikoo , thanks for supplying this fix so soon. However, it’s still not working.

There is still the issue, that updateStage.js is not called unless I remove this line. I can submit a PR that removes the line but I’m not sure of the implications because it was explicitly added by this commit .(has probably been there since beginning).

Even after removing the line, it does not immediately work. The issue is that initially there is no stage - so the log settings cannot be applied. If I deploy the API gateway, then the first service and then the API gateway again, it works.

Do you prefer if I create a new issue for this or is it fine to track it in here?