TaskDefinition CDK and LogConfiguration

1

Hello All

I am trying to accomplish the following

If you are using the Fargate launch type for your tasks, all you need to do to turn on the awslogs log driver is add the required logConfiguration parameters to your task definition.

I am using CDK to generate the FargateTaskDefn

task_definition = _ecs.FargateTaskDefinition(self, "TaskDefinition",
                                                 cpu=2048,
                                                 memory_limit_mib=4096,
                                                 execution_role=ecs_role,
                                                 task_role = ecs_role,
                                                 )
    task_definition.add_container("getFileTask",
                                  memory_limit_mib = 4096,
                                  cpu=2048,
                                  image = _ecs.ContainerImage.from_asset(directory="assets", file="Dockerfile-ecs-file-download"))

I looked up the documentation and did not find the any attribute called logConfiguration.

What am I missing?

I am not able to send the logs from Container running on ECS/Fargate to Cloudwatch and what is needed is to enable this logConfiguration option in the task defn.

Thank you for your help. Regards

2 個答案
1
已接受的答案

logging property in ContainerDefinitionOptions passed to ContainerDefinitionOptions.

This is where it is documented.

Sample Code(nodeJs):

taskDefinition.addContainer('Container', {
    image: ecs.ContainerImage.fromEcrRepository(
        respository,`1.0`),
    logging: ecs.LogDrivers.awsLogs({ streamPrefix: 'my-log-group', logRetention: 30 }),
});

Balu
已回答 2 年前
  • Ty for the response. Was able to get this to work.

0

Finally figured out the logging option in add_container is the on that sends it to cloudwatch.

已回答 2 年前

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

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

回答問題指南