node.js - 如何从无服务器 cli 设置 Cloudformation 完全访问权限

标签 node.js aws-lambda aws-cloudformation serverless aws-serverless

我可以通过编程访问 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/

相关文章:

python - 如何使用 cloudformation 或 yaml 设置日志流的保留天数

node.js - 无法安装@angular/cli

mysql - INSERT INTO 因 node-mysql 而失败

javascript - AWS Cognito Admin 创建用户临时密码验证和重置

amazon-web-services - 如何将变量传递到 AWS Cloudformation cfn-init 文件内容中

amazon-web-services - AWS Codebuild - 执行命令时出错 : python -m pip install --upgrade --force pip. 原因:退出状态 1

amazon-web-services - 为什么 AWS Cloudformation 中的自定义资源未能在预期时间内稳定下来?

angularjs - 错误 : CSRF token missing, hackathon-starter 加 AngularJS

javascript - Node.js REPL 在函数声明或函数表达式后自动声明下划线?

amazon-web-services - AWS Lambda 请求者付费模式