Hex*_*exy 10 amazon-iam aws-lambda serverless-framework
我想为serverless.yml中列出的不同功能分配不同的权限
functions:
hello:
handler: handler.hello
crawl-distributor:
handler: CrawlDistributor.handler
product-scanner:
handler: ProductScanner.handler
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:*
- lambda:*
Resource: "*"
Run Code Online (Sandbox Code Playgroud)
这似乎不起作用.当我在提供程序级别添加iamRoleStatements时,它可以工作,但最终会将权限应用于所有函数.
provider:
name: aws
runtime: nodejs4.3
stage: api
region: us-east-1
profile: dev
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:*
- lambda:*
Resource: "*"
Run Code Online (Sandbox Code Playgroud)
Zan*_*non 15
从文档中,您需要在函数中创建函数角色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: "*"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3162 次 |
| 最近记录: |