Can't get AWS Lambda function to log (text output) to CloudWatch

后端 未结 15 520
独厮守ぢ
独厮守ぢ 2020-12-13 12:14

I\'m trying to set up a Lambda function that will process a file when it\'s uploaded to an S3 bucket. I need a way to see the output of console.log when I uploa

15条回答
  •  轮回少年
    2020-12-13 12:21

    As other answers state you need to give lambda permission to post logs to cloud watch logs. AWS had provided AWSLambdaExecute policy just for that. It's json is -

    {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Effect": "Allow",
                "Action": [
                    "logs:*"
                ],
                "Resource": "arn:aws:logs:*:*:*"
            },
            {
                "Effect": "Allow",
                "Action": [
                    "s3:GetObject",
                    "s3:PutObject"
                ],
                "Resource": "arn:aws:s3:::*"
            }
        ]
    }
    

    You can add this policy in your role which is assigned to your lambda and you should start seeing the logs.

    NOTE: It also has S3 read/write access. If you do not want it you can create a custom policy with just the logs part.

提交回复
热议问题