如何确定Fargate服务的Cloudwatch日志流?

Ala*_*lan 5 amazon-cloudwatch aws-fargate

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

我正在查看有关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
Run Code Online (Sandbox Code Playgroud)

编辑2:

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

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
Run Code Online (Sandbox Code Playgroud)

AWS控制台如何获得该价值?

Ala*_*lan 5

我终于在这里的AWS文档中找到了日志流名称的格式:

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
Run Code Online (Sandbox Code Playgroud)

请注意,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
Run Code Online (Sandbox Code Playgroud)