Home > OS >  How to create Logs for NetworkLoadBalancedFargateService in CDK
How to create Logs for NetworkLoadBalancedFargateService in CDK

Time:06-23

I am trying to create logs for the Network Load Balancer (not the task). Currently using the following code:

taskImageOptions: {
                containerPort: 8080,
                image: BrazilContainerImage.fromBrazil({
                    brazilPackage: BrazilPackage.fromString('Service'),
                    transformPackage: BrazilPackage.fromString('ServiceImageBuild'),
                    componentName: 'service',
                }),
                containerName: 'Application',
                taskRole: this.taskRole,
                environment: {
                    'STAGE': props.stage,
                    'SERVICE_RUN': 'true'
                },
                logDriver: new AwsLogDriver({
                    streamPrefix: 'NetworkLoadBalancer-',
                    logGroup: new LogGroup(this, 'Service-NetworkLoadBalancer', {
                        removalPolicy: RemovalPolicy.RETAIN,
                        retention: RetentionDays.THREE_MONTHS,
                    })
                }),
            },

But this creating a new log group by deleting the existing ServiceTaskDefApplicationLogGroup. I guess this is happening because of logDriver is inside the taskImageOptions but no logging options are available in NetworkLoadBalancedFargateService. Any suggestions?

CodePudding user response:

The logDriver setting is specifically for your ECS tasks. It configures the logging for the output of your docker container(s). It is not related to load balancer access logs in any way.

You would need to take the loadBalancer property from the NetworkLoadBalancedFargateService and then call logAccessLogs() on it, as documented here.

  • Related