Verbjorns Ljosa 的回答仅包括 cloudwatch 调用 lambda 的权限。您是否指定了允许 lambda 执行其操作的正确策略和 iam 角色?
resource "aws_iam_role" "check_foo_role" {
name="check-foo-assume-role"
assume_role_policy="assume_role_policy.json"
}
assume_role_policy.json
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
以及引用上述资源 iam 角色的策略,即像
resource "iam_role_policy" "check-foo-policy" {
name="check-foo-lambda-policy"
# referencing the iam role above
role="${aws_iam_role.check_foo_role.id}"
policy="check-foo-policy.json"
}
最后是指定策略的 json,check-foo-policy.json。
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": ["*"]
},
{
"Effect": "Allow",
"Action": [
"abc:SomeAction",
"abc:AnotherAction",
],
"Resource": "some-arn-matching-the-actions"
}
请注意,您不能为与日志相关的操作指定资源限制。 abc:SomeAction 可能是 ssm:GetParameter,并带有一个附带的资源,例如 "arn:aws:ssm:us-east-1:${your-aws-account-id}:parameter/some/parameter/path/*