2017-01-04 13 views
5

मैं अपने serverless.ymlमैं सर्वर रहित फ्रेमवर्क में फ़ंक्शन स्तर IamRoleStatements को कैसे असाइन करूं?

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: "*" 

उत्तर

5

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: "*" 
संबंधित मुद्दे