2017-01-04 3 views
5

私はこれが動作していないようServerless Frameworkで関数レベルのIamRoleStatementsを割り当てるにはどうすればよいですか?

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

私serverless.ymlに記載されているさまざまな機能のための異なる権限を割り当てます。プロバイダレベルでiamRoleStatementsを追加すると機能しますが、すべての機能に権限が適用されます。 docsから

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

答えて

5

、あなたは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: "*" 
関連する問題