我一直在努力解决如何让云生成模板和无服务器按预期工作是多么繁琐和复杂的问题。
我目前有一个API网关,其中特定的端点调用不同的lambda。
我是一个向世界开放的/subscribe
,但/users
只能通过一个特定的资源访问。我该怎么做呢?
functions:
createEmailEntry:
handler: src/Email.addUser
events:
- http:
method: POST
path: /subscribe
retrieveAllSubscribers:
handler: src/Email.getUsers
events:
- http:
method: GET
path: /users
此自动生成API网关访问检索端点的策略(内联).正确的语法是什么,只允许某些ARN访问/users
端点?
发布于 2022-01-21 08:57:31
这里有一个语法示例,它只允许从一个特定的Arn访问“用户”(同时允许每个人调用订阅)。您需要向resourcePolicy部分添加一个provider.apiGateway,在“主体”下指定允许的Arn,并允许调用特定的API路径/资源。
您还希望将aws_iam类型的授权程序添加到所讨论的路径中。
provider:
name: aws
runtime: nodejs12.x
lambdaHashingVersion: 20201221
apiGateway:
resourcePolicy:
- Effect: Allow
Principal:
AWS:
- /* write allowed Arn here */
Action: execute-api:Invoke
Resource:
- execute-api:/stagename/*/users
- Effect: Allow
Principal: '*'
Action: execute-api:Invoke
Resource:
- execute-api:/stagename/*/subscribe
functions:
createEmailEntry:
handler: src/Email.addUser
events:
- http:
method: POST
path: subscribe
retrieveAllSubscribers:
handler: src/Email.getUsers
events:
- http:
method: GET
path: users
authorizer:
type: aws_iam
https://stackoverflow.com/questions/70726176
复制相似问题