Specify log group for an AWS lambda?

前端 未结 4 1546
星月不相逢
星月不相逢 2020-12-05 06:27

Is there a way to specify the CloudWatch log group that an AWS lambda logs to? It seems to be generated directly from the lambda name; however, it would be especially conve

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-05 07:05

    Actually, maybe you can, to an extent at least. I too was in search of the answer and gave this a try. Here's a snippet of two resources; the lambda function and the log group:

    "MyLambdaFunction": {
        "Type": "AWS::Lambda::Function",
        "DependsOn": "ReadWriteRole",
        "Properties": {
            //snip
        }
    },
    
    "MyLambdaFunctionLogGroup": {
        "Type": "AWS::Logs::LogGroup",
        "DependsOn": "MyLambdaFunction",
        "Properties": {
            "LogGroupName": {"Fn::Join": ["", ["/aws/lambda/", {"Ref": "MyLambdaFunction"}]]},
            "RetentionInDays": 14
        }
    },
    

    I found that the log group was created with a retention of 14 days as indicated. When the lambda function runs, it does create log streams in this group. When I deleted the stack, however, it seems that the log groups is not deleted, and the retention is now set to never expire. Perhaps that's good enough so the streams don't get too out of hand...

提交回复
热议问题