Cloudformation 将字符串转换为带有条件的 apigateway 策略文档上的列表
Cloudformation to covert string into list on apigateway policy document with condition
下面是我的cloudformation模板。我想将 aws:SourceVpc 转换为资源策略文档中的列表。我尝试使用 spilled 但 cft 低于错误。
无效的政策文件。请检查策略语法并确保委托人有效。 (服务:AmazonApiGateway;状态代码:400;错误代码:BadRequestException;请求 ID:xxxxx;代理:null)
devl 和 sdbx 也有 1 个值,而其他 acnt 和 acpt 在映射中有两个值怎么能做到呢。请提出建议。
输出应该如下所示。
aws:SourceVpc: ["vpc-7830jkd", "vpc-a1236"]
Mappings:
vpcid:
us-east-1:
sdbx: "vpc-1234"
devl: "vpc-2345"
acpt: "vpc-7830jkd,vpc-a1236"
us-east-2:
acnt: "vpc-a1236,vpc-7830jkd"
Parameters:
Env:
Type: String
Resources:
apigateway:
Type: "AWS::ApiGateway::RestApi"
Properties:
Name: mygateway
EndpointConfiguration:
Types:
- "PRIVATE"
Policy: !Sub
- |-
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "execute-api:Invoke",
"Resource": [
"execute-api:/*"
]
},
{
"Effect": "Deny",
"Principal": "*",
"Action": "execute-api:Invoke",
"Resource": [
"execute-api:/*"
],
"Condition": {
"StringNotEquals": {
"aws:SourceVpc": !Split ["," , "${myappid}"]
}
}
}
]
}
- { myappid: !FindInMap [ vpcid, !Ref "AWS::Region", !Ref "Env" ] }
Output should like below. aws:SourceVpc: ["vpc-7830jkd", "vpc-a1236"]
遗憾的是,您不能这样做。 CFN 的功能非常有限,使用普通 CFN 根本无法实现您想要的。您必须修改您的地图并单独提供所有 vpc id,而不是将列表与单独的值混合。
另一种方法是通过开发 CFN macro or custom resource。
下面是我的cloudformation模板。我想将 aws:SourceVpc 转换为资源策略文档中的列表。我尝试使用 spilled 但 cft 低于错误。
无效的政策文件。请检查策略语法并确保委托人有效。 (服务:AmazonApiGateway;状态代码:400;错误代码:BadRequestException;请求 ID:xxxxx;代理:null)
devl 和 sdbx 也有 1 个值,而其他 acnt 和 acpt 在映射中有两个值怎么能做到呢。请提出建议。
输出应该如下所示。 aws:SourceVpc: ["vpc-7830jkd", "vpc-a1236"]
Mappings:
vpcid:
us-east-1:
sdbx: "vpc-1234"
devl: "vpc-2345"
acpt: "vpc-7830jkd,vpc-a1236"
us-east-2:
acnt: "vpc-a1236,vpc-7830jkd"
Parameters:
Env:
Type: String
Resources:
apigateway:
Type: "AWS::ApiGateway::RestApi"
Properties:
Name: mygateway
EndpointConfiguration:
Types:
- "PRIVATE"
Policy: !Sub
- |-
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "execute-api:Invoke",
"Resource": [
"execute-api:/*"
]
},
{
"Effect": "Deny",
"Principal": "*",
"Action": "execute-api:Invoke",
"Resource": [
"execute-api:/*"
],
"Condition": {
"StringNotEquals": {
"aws:SourceVpc": !Split ["," , "${myappid}"]
}
}
}
]
}
- { myappid: !FindInMap [ vpcid, !Ref "AWS::Region", !Ref "Env" ] }
Output should like below. aws:SourceVpc: ["vpc-7830jkd", "vpc-a1236"]
遗憾的是,您不能这样做。 CFN 的功能非常有限,使用普通 CFN 根本无法实现您想要的。您必须修改您的地图并单独提供所有 vpc id,而不是将列表与单独的值混合。
另一种方法是通过开发 CFN macro or custom resource。