I have many Lambdas and I would like to set the log retention policy in AWS Cloudformation using AWS::Logs::LogGroup for all of them, but the only examples I have seen set LogGroupName for each one. Is it possible to set a retention policy for all Lambdas logs using a wildcard or without having to specify each Lambda function?
I tried this:
LambdaLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: '/aws/lambda/*'
RetentionInDays: 14
However, this fails to deploy (stack fails) unsurprisingly with the following error: "Model validation failed (#/LogGroupName: failed validation constraint for keyword [pattern])".
I also tried:
LambdaLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: /aws/lambda/
RetentionInDays: 14
However, that only sets the policy for the top, not for any individual Lambda.
Sadly its not possible in plain CFN. You would have to do it using custom resource in CloudFormation.