2017-01-04 12 views
5

benim serverless.yml Bu işe görünmüyorSunucu Düzeyinde IamRoleStatements işlev düzeyini nasıl ataırım?

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

sıralanan farklı işlevler için farklı izinler atamak istiyoruz. IamRoleStatements'ı sağlayıcı düzeyinde eklediğimde, çalışır, ancak tüm işlevlere izinler uygulanmaya başlar. docs itibaren

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

cevap

5

, sen resources altında fonksiyon rol oluşturmak ve işlevi içinde bu yeni role başvurmak gerekir.

Örnek:

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: "*" 
İlgili konular