我有一个 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 中的流值:
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 控制台如何获取该值?
最佳答案
我终于在 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
关于amazon-cloudwatch - 如何确定 Fargate 服务的 Cloudwatch 日志流?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50397217/