AWS lambda cloudwatch订阅

时间:2019-05-14 15:11:11

标签: amazon-web-services aws-lambda amazon-iam amazon-cloudwatch

我想向AWS lambda日志添加cloudwatch订阅,从而使我的AWS lambda由cloudwatch日志触发。我应该为使用lambda的角色添加哪些权限以启用此功能?

1 个答案:

答案 0 :(得分:1)

默认情况下,您的Lambda将具有访问CloudWatch的权限以写入日志(具有默认的AWSLambdaBasicExecutionRole),但是,如果您要手动添加它,则这是具有所需权限的策略:

{
  "document": {
    "Version": "2012-10-17",
    "Statement": [
      {
        "Effect": "Allow",
        "Action": [
          "logs:CreateLogGroup",
          "logs:CreateLogStream",
          "logs:PutLogEvents"
        ],
        "Resource": "*"
      }
    ]
  },
  "name": "AWSLambdaBasicExecutionRole",
  "id": "xxxxx",
  "type": "managed",
  "arn": "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}

Lambda上的CloudWatch事件触发器的Lambda功能策略:

{
  "Version": "2012-10-17",
  "Id": "default",
  "Statement": [
    {
      "Sid": "uuid",
      "Effect": "Allow",
      "Principal": {
        "Service": "events.amazonaws.com"
      },
      "Action": "lambda:invokeFunction",
      "Resource": "arn:aws:lambda:us-east-x:xxxxxxxxxxxx:function:LambdaFunction",
      "Condition": {
        "ArnLike": {
          "AWS:SourceArn": "arn:aws:events:us-east-x:xxxxxxxxxxxx:rule/CloudWatchRule"
        }
      }
    }
  ]
}