question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot activate API gateway logs for shared API gateway

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:21 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
paulalexcommented, Nov 3, 2021

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.

1reaction
tinexwcommented, Dec 8, 2019

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Turn on CloudWatch logs for API Gateway REST APIs and ...
To troubleshoot an API Gateway REST API or WebSocket API, turn on execution logging and access logging using Amazon CloudWatch Logs.
Read more >
How to enable execution logs for API Gateway - Seed.run
In this post we'll look at how to enable execution logs in API Gateway by creating an IAM role to allow API Gateway...
Read more >
How to enable CloudWatch logs for API Gateway
Navigate to Services -> IAM. · Click Roles. · Click Create a New Role Button. · Choose a name, I recommend the format:...
Read more >
ARN role for API Gateway to enable logs error - Stack Overflow
I was having this issue today as I was trying to set up a user that I had given those permissions to. Resolved...
Read more >
The Missing Guide to AWS API Gateway Access Logs
If I have a hairy API Gateway issue that I'm trying to debug, I might enable them for a brief time. Once I've...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found