我有一個 Fargate ECS 容器,用于通過 ECS 中的任務運行 Docker 容器。當任務啟動時,會調用一個sh腳本runner.sh,,#!/bin/shecho "this line will get logged to ECS..."python3 src/my_python_script.py # however print statements from this Python script are not logged to ECS這又會啟動一個長時間運行的 Python 腳本my_python_script.py. 我知道 Python 腳本運行良好,因為它執行了需要執行的操作,但我看不到 Python 腳本的輸出。里面my_python_script.py有好幾條print()語句。在我的 ECS Fargate 任務的 CloudWatch 日志中,我看到 sh 腳本 ( "this line will get logged to ECS...") 的輸出,但沒有看到print()Python 腳本中執行的語句的輸出。這是我的任務定義中的日志配置:{ "ipcMode": null, "executionRoleArn": "myecsTaskExecutionRolearn", "containerDefinitions": [ { "dnsSearchDomains": null, "environmentFiles": null, "logConfiguration": { "logDriver": "awslogs", "secretOptions": null, "options": { "awslogs-group": "/ecs/mylogsgroup", "awslogs-region": "eu-west-1", "awslogs-stream-prefix": "ecs" } }, "entryPoint": null, "portMappings": [], "command": null, "linuxParameters": null, "cpu": 0, "environment": [], "resourceRequirements": null, "ulimits": null, "dnsServers": null, "mountPoints": [], "workingDirectory": null, "secrets": null, "dockerSecurityOptions": null, "memory": null, "memoryReservation": null, "volumesFrom": [], "stopTimeout": null, "image": "1234567.dck.aws.com/mydockerimage", "startTimeout": null, "firelensConfiguration": null, } 我想我正在遵循https://docs.aws.amazon.com/AmazonECS/latest/userguide/using_awslogs.html中的 awslogs 說明,但也許不是?我是否需要做一些明顯的事情來確保print()在我的 ECS 任務的 CloudWatch 日志中捕獲 Python 腳本中的語句?
如何查看正在運行的 Fargate ECS 任務的 Python 打印語句?
ibeautiful
2023-09-26 14:20:13