question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(ecs): AwsLogDriver ignores log group's region

See original GitHub issue

What is the problem?

ECS supports cross-region logging with awslogs with the awslogs-region option. When I pass a cross-region LogGroup (constructed from an arn), the awslogs-region option in the resulting template is always the current region, ignoring the log group’s region.

Reproduction Steps

Create a cross-region log group and pass it to ecs.AwsLogDriver:

log_group = logs.LogGroup.from_log_group_arn(f"arn:aws:logs:eu-west-2:{self.account}:log-group:my_log_group")

container = ecs.ContainerDefinition(self, "container", 
    ...
    logging=ecs.AwsLogDriver(stream_prefix="my_prefix", log_group=log_group)
)

What did you expect to happen?

The logs are written to the specified log group.

What actually happened?

The task execution role is given the correct permissions for the log group (including the correct region).

But the awslogs-region option in the container definition is always the same as the container’s region.

Task fails to start.

CDK CLI Version

1.134

Framework Version

No response

Node.js Version

17.1.0

OS

Linux

Language

Typescript, Python, .NET, Java, Go

Language Version

No response

Other information

I’m resorting to escape hatches to override Properties.ContainerDefinitions.0.LogConfiguration.Options.awslogs-region on the task definition, but this doesn’t work if there are multiple containers.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
skinny85commented, Dec 29, 2021

It’s a bug in the LogGroup.fromLogGroupArn() method - you can see here that the region is not passed from the ARN to the returned Resource, like it should be (here’s a working example).

1reaction
kornicameistercommented, Dec 29, 2021

I have submitted my fix for log group’s region: https://github.com/aws/aws-cdk/pull/18215

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using the awslogs log driver - Amazon Elastic Container Service
If you're using the EC2 launch type, you can view different logs from your ... Make sure that the specified log group exists...
Read more >
ECS awslogs Log group not being created for Task
The possible reason that causes this error as the error seems like the container instance able to get the list of Log group....
Read more >
Amazon CloudWatch Logs logging driver
Use the awslogs-region log option or the AWS_REGION environment variable to set the region. By default, if your Docker daemon is running on...
Read more >
Logging Using awslogs Log Driver in Amazon ECS
Amazon ECS supports multiple log drivers and awslogs is one of them. ... CloudWatch Log Group, AWS region, and the Log group stream...
Read more >
Guide: How to centralize and analyze AWS logs - Coralogix
AWS EC2 logs is the most popular and widely-used AWS service. ... file that specifies the log group, log stream, time zone, and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found