我正在尝试编写一个lambda来侦听来自CloudWatch的Parameter Store更改事件,并通过调用boto3.client('ssm').get_parameter_history(Name=event["name"],WithDecryption=True)
获取参数的历史数据。此方法失败,并显示以下消息:
botocore.exceptions.ClientError:调用GetParameterHistory操作时发生错误(AccessDeniedException):密文是指客户主密钥,该密钥不存在,在此区域中不存在,或者您不允许访问。 (服务:AWSKMS;状态代码:400;错误代码:AccessDeniedException;请求ID:blah-blah-blah)
以下是lambda执行角色的样子:
{
"roleName": "myapp-paramstore-updates-webhook-role",
"policies": [
{
"document": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "logs:CreateLogGroup",
"Resource": "arn:aws:logs:eu-west-1:000000000000:*"
},
{
"Effect": "Allow",
"Action": [
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": [
"arn:aws:logs:eu-west-1:000000000000:log-group:/aws/lambda/ssm-paramstore-updates-webhook:*"
]
}
]
},
"name": "LambdaBasicExeRole",
"type": "inline"
},
{
"document": {
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"kms:DescribeKey",
"ssm:GetParameter"
],
"Resource": [
"arn:aws:kms:eu-west-1:000000000000:key/*",
"arn:aws:ssm:eu-west-1:000000000000:parameter/myorg/myteam/slack/webhooks/ssm-paramstore-updates-webhook",
"arn:aws:ssm:eu-west-1:000000000000:parameter/myorg/myteam/slack/webhooks/system-eventsupdates-webhook"
]
},
{
"Sid": "VisualEditor1",
"Effect": "Allow",
"Action": "ssm:GetParameterHistory",
"Resource": "arn:aws:ssm:*:*:parameter/*"
}
]
},
"name": "readonly-ssm-paramstore-updates-webhook",
"type": "inline"
}
],
"trustedEntities": [
"lambda.amazonaws.com"
]
}
在我使用ssm:GetParameterHistory
之前,有ssm:DescribeParameters
,但我需要获得一些版本信息,因此更改。一切都在同一个区域,lambda和参数。
我现在需要什么附加权限以及用于解决此问题的资源?
想出需要访问密钥的lambda角色需要作为KMS中的关键用户添加。基本上,需要授予角色(或用户)权限,以使其使用密钥对秘密执行加密/解密。
这是从KMS控制台完成的,单击客户管理密钥列表中的密钥名称(假设它是您自己创建的密钥),向下滚动到关键用户并将需要使用密钥的角色添加到列表中允许的用户。