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 Respuestas
1
Respuesta aceptada

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
respondido hace 2 años
  • 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.

respondido hace 2 años

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas