我正在使用 AWS 的 Parameter Store 来存储 String 参数值。我在从 Lambda 函数中获取参数时使用以下代码:
const ssm = require('aws-sdk/clients/ssm');
const getConfig = (prefix) => {
return ssm.getParameter({ Name: `/${prefix}/config`}).promise()
.then(resp => JSON.parse(resp.Parameter.Value))
.catch(err => console.error(err));
};
但是在从 AWS 控制台运行 Lambda 时,我不断收到以下错误:
ERROR AccessDeniedException: User: arn:aws:sts::XXX:assumed-role/lambdaExecutionRole is not authorized to perform: ssm:GetParameter on resource: arn:aws:ssm:us-east-1:XXX:parameter/get/getValue
我尝试添加对角色的管理员访问权限:lambdaExecutionRole,但现在出现此错误:
ERROR SyntaxError: Unexpected token h in JSON at position 0
at JSON.parse (<anonymous>)
at /var/task/myFile.js:2:955529
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async Runtime.e.handler (/var/task/myFile.js:2:1065241)
我什至尝试在此文档之后添加 ssm 权限:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Action": "sts:AssumeRole"
},
{
"Sid": "GetParam1",
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Action": "ssm:GetParameter",
"Resource": "*"
}
]
}
- An error occurred: AssumeRole policy may only specify STS AssumeRole actions.
- An error occurred: Has prohibited field Resource
知道我可能在这里缺少什么吗?提前致谢。