【问题标题】:How do I assign function level IamRoleStatements in Serverless Framework?如何在无服务器框架中分配功能级别 IamRoleStatements?
【发布时间】:2017-05-19 08:47:14
【问题描述】:

我想为我的 serverless.yml 中列出的不同功能分配不同的权限

 functions:
  hello:
    handler: handler.hello
  crawl-distributor:
    handler: CrawlDistributor.handler
  product-scanner:
    handler: ProductScanner.handler
    iamRoleStatements:
      - Effect: Allow
        Action:
          - dynamodb:*
          - lambda:*
        Resource: "*"

这似乎不起作用。当我在提供者级别添加 iamRoleStatements 时,它可以工作,但最终会将权限应用于所有函数。

 provider:
  name: aws
  runtime: nodejs4.3
  stage: api
  region: us-east-1
  profile: dev
  iamRoleStatements:
    - Effect: Allow
      Action:
        - dynamodb:*
        - lambda:*
      Resource: "*"

【问题讨论】:

    标签: aws-lambda amazon-iam serverless-framework


    【解决方案1】:

    docs,您需要在resources 下创建函数角色,并在您的函数中引用这个新角色。

    例子:

    service: my-test
    
    provider:
      name: aws
      runtime: nodejs4.3
      stage: api
      region: us-east-1
      profile: dev
    
    functions:
      hello:
        handler: handler.hello
      crawl-distributor:
        handler: CrawlDistributor.handler
      product-scanner:
        role: myDynamoRole
        handler: ProductScanner.handler
    
    resources:
      Resources:
        myDynamoRole:
          Type: AWS::IAM::Role
          Properties:
            RoleName: myDynamoRole
            AssumeRolePolicyDocument:
              Version: '2012-10-17'
              Statement:
                - Effect: Allow
                  Principal:
                    Service:
                      - lambda.amazonaws.com
                  Action: sts:AssumeRole
            Policies:
              - PolicyName: myPolicyName
                PolicyDocument:
                  Version: '2012-10-17'
                  Statement:
                    - Effect: Allow
                      Action:
                        - dynamodb:*
                        - lambda:*
                      Resource: "*"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-05
      • 2018-02-16
      • 1970-01-01
      • 1970-01-01
      • 2020-09-25
      • 2017-09-30
      • 2019-08-31
      • 2021-07-27
      相关资源
      最近更新 更多