简体   繁体   English

AWS 网关和 CloudWatch 日志

[英]AWS Gateway and CloudWatch logs

I seem to have an issue with seeing logs in AWS CloudWatch for my AWS Gateway.在 AWS CloudWatch 中查看我的 AWS 网关的日志时,我似乎遇到了问题。

I did the following:我做了以下事情:

  • created IAM role that allows for CloudWatch logs创建了允许 CloudWatch 日志的 IAM 角色
  • created API and set IAM ARN in the API settings创建 API 并在 API 设置中设置 IAM ARN
  • Enabled CloudWatch Logs in the stage settings在阶段设置中启用 CloudWatch Logs

Now I can see a Log Group that seem to correspond to my AWS Gateway and Log Streams but all of them are empty.现在我可以看到一个日志组,它似乎与我的 AWS 网关和日志流相对应,但它们都是空的。

I think I'm missing something here.我想我在这里遗漏了一些东西。

Thanks, Michal谢谢,迈克尔

Set up API Logging Using the API Gateway Console使用 API Gateway 控制台设置 API 日志记录

To set up API logging, you must have deployed the API to a stage.要设置 API 日志记录,您必须已将 API 部署到阶段。 You must also have configured an appropriate CloudWatch Logs role ARN for your account.您还必须为您的账户配置适当的 CloudWatch Logs 角色ARN。

  1. Sign in to the API Gateway console at here .此处登录 API Gateway 控制台。
  2. Choose Settings from the primary navigation panel and type an ARN of an IAM role with appropriate permissions in CloudWatch log role ARN.从主导航面板中选择设置,然后在 CloudWatch 日志角色 ARN 中键入具有适当权限的 IAM 角色的 ARN。 You need to do this once.你需要这样做一次。
  3. Do one of the following:执行以下操作之一:
    • Choose an existing API and then choose a stage.选择一个现有的 API,然后选择一个阶段。
    • Create an API and deploy it to a stage.创建 API 并将其部署到阶段。
  4. Choose Logs/Tracing in the Stage Editor.在 Stage Editor 中选择 Logs/Tracing。
  5. To enable execution logging:要启用执行日志记录:
    1. Choose Enable CloudWatch Logs under CloudWatch Settings.在 CloudWatch 设置下选择启用 CloudWatch 日志。
    2. Choose Error or Info from the dropdown menu.从下拉菜单中选择错误或信息。
    3. If desired, choose Enable Detailed CloudWatch Metrics.如果需要,选择启用详细 CloudWatch 指标。

For more information about CloudWatch metrics, see Monitor API Execution with Amazon CloudWatch .有关 CloudWatch 指标的更多信息,请参阅使用 Amazon CloudWatch 监控 API 执行

  1. To enable access logging:要启用访问日志记录:
    1. Choose Enable Access Logging under Custom Access Logging.在自定义访问日志下选择启用访问日志。
    2. Type the ARN of a log group in CloudWatch Group.在 CloudWatch Group 中键入日志组的 ARN。 The ARN format is arn:aws:logs:{region}:{account-id}:log-group:API-Gateway-Execution-Logs_{rest-api-id}/{stage-name}. ARN 格式为 arn:aws:logs:{region}:{account-id}:log-group:API-Gateway-Execution-Logs_{rest-api-id}/{stage-name}。
    3. Type a log format in Log Format.在日志格式中键入日志格式。 You can choose CLF, JSON, XML, or CSV to use one of the provided examples as a guide.您可以选择 CLF、JSON、XML 或 CSV 以使用提供的示例之一作为指南。
  2. Choose Save Changes.选择保存更改。

Note: You can enable execution logging and access logging independent of each other.注意:您可以启用彼此独立的执行日志记录和访问日志记录。

Reference: Set Up CloudWatch API Logging in API Gateway参考: 在 API Gateway 中设置 CloudWatch API 日志记录

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM