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年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ