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년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠