amazon-web-services - AWS Api Gateway 附加现有策略
问题描述
通常,如果我想创建一个私有AWS::ApiGateway::RestApi
策略,只允许 VPC 流量调用 API 上的任何资源,我会这样做:
"ApiGatewayRestApi": {
"Type": "AWS::ApiGateway::RestApi",
"Properties": {
"Name": "api-foo-bar",
"EndpointConfiguration": {
"Types": [
"PRIVATE"
]
},
"Policy": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": [
"execute-api:Invoke"
],
"Resource": "execute-api:/*",
"Condition": {
"StringEquals": {
"aws:SourceVpc": "vpc-000000000000"
}
}
}
]
}
}
}
有人问我是否可以创建一个策略,然后将其重用于我们可能创建的不同 Api 网关?其中包括:
"ApiGatewayRestApi": {
"Type": "AWS::ApiGateway::RestApi",
"Properties": {
"Name": "api-foo-bar",
"EndpointConfiguration": {
"Types": [
"PRIVATE"
]
},
"Policy": "arn:aws:*whatever*"
}
},
我不知道!我也找不到任何说明这一点的文档或示例。有人做过吗?这完全可行吗?谢谢 :)
解决方案
不,目前不可行。您附加到 Api 网关的策略是基于资源的策略。
从 aws 文档中,
使用基于资源的策略,您可以指定谁有权访问资源以及他们可以对其执行哪些操作。
Aws 文档显示了 cloudformation 中每个属性可以采用的类型。以下是“AWS::ApiGateway::RestApi”中允许的属性和类型
{
"Type" : "AWS::ApiGateway::RestApi",
"Properties" : {
"ApiKeySourceType" : String,
"BinaryMediaTypes" : [ String, ... ],
"Body" : Json,
"BodyS3Location" : S3Location,
"CloneFrom" : String,
"Description" : String,
"DisableExecuteApiEndpoint" : Boolean,
"EndpointConfiguration" : EndpointConfiguration,
"FailOnWarnings" : Boolean,
"MinimumCompressionSize" : Integer,
"Mode" : String,
"Name" : String,
"Parameters" : {Key : Value, ...},
"Policy" : Json,
"Tags" : [ Tag, ... ]
}
}
请注意,Policy 属性采用 JSON 类型。此外,文档为 Policy 属性编写了以下内容:
包含 RestApi 资源权限的策略文档。
并提示我们 Policy 属性不采用以下形式:"Policy": "arn:aws:*whatever*"
并且只接受 JSON 形式的策略文档作为 Api Gateway 的基于资源的策略。
参考: https ://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-policy https://docs.aws.amazon.com/IAM /latest/UserGuide/access_policies_identity-vs-resource.html
推荐阅读
- node.js - 在 Dockerfile 中执行 npm 构建时未生成“dist”文件夹
- php - 如何使用标题而不是 Id 行::find(); 在 laravel 中选择一行 方法
- java - 收到通知时如何将所有firebase通知保存到firebase实时数据库
- c# - PayFast 通知 URL 未命中 c# 核心
- ruby-on-rails - Rack::File 已弃用,请改用 Rack::Files - 新的 Ruby on Rails 项目
- laravel - 我已经使用 laravel 刀片模板制作布局但没有工作
- jenkins - Jenkins 管道在 ssh 期间挂起
- kotlin - 什么时候调用对象的 init 块?
- android - 在通知区域中收听“黑暗主题”切换并收到更改通知
- python - 带有硬币系统的 discord.py 机器人中的 UnboundLocalError