【问题标题】:How to determine the Cloudwatch log stream for a Fargate service?如何确定 Fargate 服务的 Cloudwatch 日志流?
【发布时间】:2018-10-28 01:30:15
【问题描述】:

我有一个 Fargate 服务正在运行,并且可以使用 AWS 控制台查看其 Cloudwatch 日志流(导航到该服务,然后单击其日志选项卡)。

我正在查看 GetLogEvents 的 AWS 文档,发现您可以使用日志组名称和日志流名称访问日志。虽然我知道服务的日志组名称,但日志流名称是动态生成的。

如何获取正在运行的 Fargate 服务的当前日志流名称?

我正在查看 AmazonECSClient 文档,任何指针都会有所帮助。

编辑:

我发现日志组实际上是为容器指定的,而不是服务。检索服务的任务定义,我可以遍历具有指示选项的 LogConfiguration 部分的容器定义,但是只提供日志组和流前缀,没有日志流名称

- service
 - task definition
  - container definitions
   - LogConfiguration:
       LogDriver:  awslogs
       Options:    awslogs-group=/ecs/myservice
                   awslogs-region=us-east-1
                   awslogs-stream-prefix=ecs

编辑 2:

我从 AWS 控制台看到,日志选项卡中的链接确实包含日志流名称。请参阅此示例 URL 中的 stream 值:

https://us-east-1.console.aws.amazon.com/cloudwatch/home
?region=us-east-1
#logEventViewer:group=/ecs/myservice;stream=ecs/myservice/ad7246dd-bb0e-4eff-b059-767d30d40e69

AWS 控制台如何获取该值?

【问题讨论】:

    标签: amazon-cloudwatch aws-fargate


    【解决方案1】:

    终于在AWS文档here找到了日志流名的格式:

    awslogs-stream-prefix
    
    Required: No, unless using the Fargate launch type in which case it is required.
    
    The awslogs-stream-prefix option allows you to associate a log stream
    with the specified prefix, the container name, and the ID of the Amazon
    ECS task to which the container belongs. If you specify a prefix with
    this option, then the log stream takes the following format:
    
        prefix-name/container-name/ecs-task-id
    

    请注意,ecs-task-id 是任务 ARN 的 GUID 部分:

    For this sample Task ARN:
    arn:aws:ecs:us-east-1:123456789012:task/12373b3b-84c1-4398-850b-4caef9a983fc
    
    the ecs-task-id to use for the log stream name is:
    12373b3b-84c1-4398-850b-4caef9a983fc
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-19
      • 1970-01-01
      • 2020-05-21
      • 1970-01-01
      • 2019-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多