aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.62k stars 3.91k forks source link

ecs: set loggroup retention period for FireLensLogDriver #28258

Open malatep opened 10 months ago

malatep commented 10 months ago

Describe the feature

Hello,

I would like to be able to set the maximum retention for the CloudWatch log group that is created with FireLensLogDriver.

The interface FireLensLogDriverProps does not have the option to set the logRetention.

Similar to how it is currently done in AwsLogDriver using logRetention from AwsLogDriverProps

Thanks

Use Case

Be able to set the maximum retention for the CloudWatch log group

Proposed Solution

No response

Other Information

No response

Acknowledgements

CDK version used

2.81.0

Environment details (OS name and version, etc.)

Mac OS 13.6.2

pahud commented 10 months ago

Yes it would be great to support that.

sakurai-ryo commented 10 months ago

Hi @malatep, I think we can set the retention period for the newly created Log Group by specifying log_retention_days in FireLensLogDriverProps.options.

const taskDefinition = new ecs.Ec2TaskDefinition(this, 'TaskDef');
taskDefinition.addContainer('TheContainer', {
  image: ecs.ContainerImage.fromRegistry('example-image'),
  memoryLimitMiB: 256,
  logging: ecs.LogDrivers.firelens({
    options: {
      Name: 'cloudwatch',
      region: 'us-west-2',
      log_group_name: 'firelens-fluent-bit',
      log_stream_prefix: 'from-fluent-bit',
      auto_create_group: 'true',
      log_retention_days: '1',
    },
  }),
});

https://docs.fluentbit.io/manual/pipeline/outputs/cloudwatch#configuration-parameters

Please note that the logs:PutRetentionPolicy policy needs to be in the task role.