我可以通过编程访问 aws 帐户,当我尝试部署基本功能时,我得到:
用户:arn:aws:iam::xxxx:user/myname 无权对资源执行:cloudformation:DescribeStacks:arn:aws:cloudformation:eu-west-1:xxxxxx:stack/hello-世界开发/*
我检查了我的 key ,它们是正确的,我假设我的用户没有 cloudformation 访问权限。
我的问题是,是否可以在 yaml 文件中设置我的用户的权限?例如cloudformation完全访问、lambda完全访问等。
您可以在下面找到我的 functiona 和 yaml 文件:
handler.js
module.exports.helloWorld = (event, context, callback) => {
const response = {
statusCode: 200,
headers: {
'Access-Control-Allow-Origin': '*', // Required for CORS support to work
},
body: JSON.stringify({
message: 'Go Serverless v1.0! Your function executed successfully!',
input: event,
}),
};
callback(null, response);
};
serverless.yaml
service: hello-world
provider:
name: aws
runtime: nodejs8.10
region: eu-west-1
# iamRoleStatements:
# - Effect: "Allow"
# Action:
# - cloudformation: CreateStack
# - cloudformation: DescribeStacks
# - cloudformation: CreateChangeSet
# - cloudformation: ListStacks
# - cloudformation: UpdateStack
# - cloudformation: DescribeChangeSet
# - cloudformation: ExecuteChangeSet
# - iam: GetRole
# - lambda: UpdateFunctionCode
# - lambda: UpdateFunctionConfig
# - lambda: GetFunctionConfiguration
# - lambda: AddPermission
# - s3: GetObject
# Resource: "*"
# The `functions` block defines what code to deploy
functions:
helloWorld:
handler: handler.helloWorld
# The `events` block defines how to trigger the handler.helloWorld code
events:
- http:
path: hello-world
method: get
cors: true
最佳答案
所以这里的问题是您的默认 ~/.aws/credentials key 没有分配正确的权限。
您无法在 yaml 文件中为您的用户分配权限,您需要进入控制台并分配,您可以在资源部分中创建用户,但这将是违反直觉的 - 我不太确定您的知识水平如何,如果您需要更多帮助,请发表评论,我会充实我的答案。
您的部署角色/权限基本上应该具有 Lambda、IAM、Cloudformation 和 APIG 完全访问权限。
关于node.js - 如何从无服务器 cli 设置 Cloudformation 完全访问权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52365788/