设置CloudWatch Log Group for Lambda Function的到期时间 [英] Set expiration of CloudWatch Log Group for Lambda Function
问题描述
默认情况下,当我创建Lambda函数时,CloudWatch Log Group设置为Never Expire.是否可以设置到期时间(例如14天),这样我在创建后不必从控制台手动设置它?
By default when I create a Lambda function, the CloudWatch Log Group is set to Never Expire. Is it possible to set the expiration (saying 14 days) so I don't have to set it manually from the console after creation?
已更新#1
感谢 @jens walter答案这是如何解决问题的代码段
Thanks to @jens walter answer this is a code snippet of how to solve the problem
Resources:
LambdaFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs6.10
CodeUri: <your code uri>
Policies: <your policies>
LambdaFunctionLogGroup:
Type: "AWS::Logs::LogGroup"
DependsOn: "LambdaFunction"
Properties:
RetentionInDays: 14
LogGroupName: !Join ["", ["/aws/lambda/", !Ref LambdaFunction]]
推荐答案
如果通过控制台创建Lambda,则无法相应地设置日志保留时间.也不可能为所有CloudWatch Logs设置默认保留.
If you are creating your Lambda through the console, it is not possible to set the log retention accordingly. It is also not possible to set a default retention for all CloudWatch Logs.
影响日志保留的唯一方法是通过CloudFormation.在这种情况下,您需要通过CloudFormation部署Lambda,然后可以在该模板中定义一个具有自定义保留的匹配LogGroup.
The only way you can influence the log retention is through CloudFormation. In that case, you need to deploy you Lambda through CloudFormation and then you can define a matching LogGroup with a custom retention within that template.
这篇关于设置CloudWatch Log Group for Lambda Function的到期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!