我正在尝试将对我的API网关端点的访问限制为来自我的VPC的请求。有一些API网关资源策略的例子,甚至还有RestApi资源上的Policy属性,但是当我还没有创建API时,我无法弄清楚如何编写需要API ID的策略。基于AWS文档,我有一个了解堆栈应该如何的示例:
MyRestApi:
Type: 'AWS::ApiGateway::RestApi'
Properties:
Name: My Great API
Policy:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal: '*'
Action: execute-api:Invoke
Resource:
Fn::Join:
- - ''
- 'arn:aws:execute-api:'
- Ref: region
- ':'
- Ref: accountId
- ':'
- Ref: MyRestApi
- Effect: Deny
Principal: '*'
Action: execute-api:Invoke
Resource:
Fn::Join:
- - ''
- 'arn:aws:execute-api:'
- Ref: Region
- ':'
- Ref: AccountId
- ':'
- Ref: MyRestApi
Condition:
StringNotEquals:
"aws:SourceVpc":
Ref: VpcId
关键在于,当它仍然被创建时,我无法在策略中引用MyRestApi。我确信我不是唯一一个想要这样做的人......我宁愿认为这是一个常见的问题,所以我很可能还没有找到答案。
谢谢你的帮助,
斯特凡
PS:我使用的文件是https://docs.aws.amazon.com/de_de/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-policy和https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-resource-policies-examples.html
根据AWS documentation,由于这个问题,该政策支持Resource
的特殊语法。
"Resource": [
"execute-api:/stage/method/path"
]
在评论中,他们称之为:
//这里支持简化格式,因为apiId尚未知道,分区/区域/帐户可以在导入时导出