aws / chalice

Python Serverless Microframework for AWS
Apache License 2.0
10.66k stars 1.01k forks source link

`chalice logs` command does not work when deploying with CDK #1665

Open aleandros opened 3 years ago

aleandros commented 3 years ago

As mentioned in the title, the chalice logs command does not show any output when deploying the project with CDK as specified in the docs.

The lambda is correctly generating logs, both the ones generated by the framework and the ones I add manually via app.log.error for example. No CLI option seems to work (--num-entries, --follow, etc.) and no error message is printed.

I believe this has to do with this condition, that is, that the given name is not found in the deployed.resource_names(). I would be glad to help. My intuition tells me that this is due to the DeployedResources reading from a local deploy file, so it should be able to read from the CloudFormation output, transform it into the appropriate format, and be able to tell the CLI to read it from there, but I'm not very familiar with the code.

rsergiuistoc commented 2 years ago

As mentioned in the title, the chalice logs command does not show any output when deploying the project with CDK as specified in the docs.

The lambda is correctly generating logs, both the ones generated by the framework and the ones I add manually via app.log.error for example. No CLI option seems to work (--num-entries, --follow, etc.) and no error message is printed.

I believe this has to do with this condition, that is, that the given name is not found in the deployed.resource_names(). I would be glad to help. My intuition tells me that this is due to the DeployedResources reading from a local deploy file, so it should be able to read from the CloudFormation output, transform it into the appropriate format, and be able to tell the CLI to read it from there, but I'm not very familiar with the code.

Please check if you query logs on the correct stage, if not use --stage option to specify the desired stage where you're lambda is deployed. Usually chalice logs will always default the logs of the API lambda handler, if you have multiple lambda handlers defined use the option -n to query by it's name the name is the same as your function signatures if you haven't specified a custom one through the app "register" decorators. I had the same situation you're describing, what I did wrong is that I've added a custom policy for each environment I was planning to deploy. Doing that I forgot to add Cloudwatch specific policy rules, which gave the lambda permission to create the log group and put it's logs inside it:

{
    "Action": [
      "logs:CreateLogGroup",
      "logs:CreateLogStream",
      "logs:PutLogEvents"
    ],
    "Resource": "arn:aws:logs:*:*:*",
    "Effect": "Allow"
},

After adding this statement to each custom policy document, my issue was solved and I finally had logs.

NOTE: Tried lowering the log level to ERROR, but then my debug and info logs didn't show up anymore so I had to bring it back to BEBUG and the logs were shown. Cheers!

priamai commented 1 year ago

Hi there, I believe I have the same problem here:

Nothing shows up.

priamai commented 1 year ago

This is my config.json

{
  "version": "2.0",
  "app_name": "lcservice",
  "stages": {
    "dev": {
      "api_gateway_stage": "api",
      "lambda_functions": {
        "api_handler": {
          "environment_variables": {
            "APP_TABLE_NAME": ""
      }
    }
      }
    }
  }
}

This: chalice logs --stage api

Also returns nothing.

PS I can see all my log events in CloudWatch from the app, which is fine but would be nice to see from the commandline.