Control Retention of Log Group Created as part of EC2 ImageBuilder

0

I am creating an EC2 Image Builder pipeline using CloudFormation. Along with it, I am also creating a log group using the below snippet. However, the Retention is set to Never Expire, although I am setting it to 1. Can anyone please help with this?

ImageBuilderLogGroup: Type: AWS::Logs::LogGroup DependsOn: Recipe Properties: RetentionInDays: 1 LogGroupName: !Join ["/", [ "/aws/imagebuilder", !Ref myImageName]]

3 Answers
0

Hello.

Try creating only a log group with "AWS::Logs::LogGroup" before creating other resources.
Also, if there is an existing log group, try deleting it before running CloudFormation.

profile picture
EXPERT
answered 6 months ago
  • Thank you for the response. The order in the CloudFormation template matters? If yes, then I will check this. Also, there is no existing log group, as I am provisioning everything using CloudFormation.

  • There may be an issue with the order of resource creation, so try creating the log group first.

0

any chance your code deletes retention policy[1] Typically, a log group's retention is set to never expire if the 'RetentionInDays' property isn't specified. I'm wondering if there might be a syntax error related to this property. As Riku suggested, it might be worthwhile to create a log group separately to test your code [1] https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_DeleteRetentionPolicy.html

answered 6 months ago
0

Found that it is because of the naming. When we create the Image Builder related resources, we are using Target Image Name which has a dot. But the names of Image Builder Resources cannot have dots. Hence we are replacing it with underscore. But in the log group name, there is no such restriction, so I left it as is. But because of this, it is creating 2 log groups one with underscore naming and the other with dot. One of them has log retention set to Never Expire. Once I fixed the log group to make it's name consistent with that of the other Image Builder resources, it seems to be working fine.

answered 6 months 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