Parameterize LogGroup name & LogStream Prefix in ECS Task Definition

0

When we create an ECS Task Definition, we have log configuration which allows us to create log groups, log streams etc. Instead of providing the name for log group and log stream prefix, I want to parameterize these and pass them during execution of the ECS Task Definition. Is this possible? I tried passing something like ${log-group-name} for awslogs-group attribute. But, it is throwing an error saying it has invalid characters. Please help. I am looking for something like below.

"logConfiguration": {
                "logDriver": "awslogs",
                "options": {
                    "awslogs-create-group": "true",
                    "awslogs-group": "${log-group-name}",
                    "awslogs-region": "us-east-1",
                    "awslogs-stream-prefix": "${log-stream-prefix}"
                },
            }
已提問 1 年前檢視次數 452 次
2 個答案
0

Check this out: https://github.com/aws/containers-roadmap/issues/74, does it fit your case?

profile picture
專家
已回答 1 年前
  • Thank you for the prompt response. However, I don't want to use Firelens. I just want to parameterize log group & stream. I see there is a feature request. Wondering when it will be implemented.

0

Hi, How do Launch your ECS Task ?

Often in my CICD pipeline, I'm using a generic ECS Task Definition as template, and I use sed to replace all variables inside it to create a new one.

For instance:

export CI_AWS_ECS_TASK_DEFINITION_FILE="taskdef.json"
export log-group-name="/ecs/myproject/app"

cp ./files/$CI_AWS_ECS_TASK_DEFINITION_FILE ./artifacts/$CI_AWS_ECS_TASK_DEFINITION_FILE
cd artifacts
sed -i "s|<log-group-name>|$log-group-name|g" $CI_AWS_ECS_TASK_DEFINITION_FILE
aws ecs register-task-definition --cli-input-json file://artifacts/$CI_AWS_ECS_TASK_DEFINITION_FILE.json
profile picture
Donov
已回答 1 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南