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 Answers
1
Accepted Answer

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
answered 2 years ago
  • 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.

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions