amazon-web-services - AWS Cloudformation:为 IpAddress 设置多个条件
问题描述
我正在使用 AWS SAM,我用它来部署 lambda 并与 API Gateway 端点集成。
对于 API 网关,我有类似的东西:
Api:
Type: AWS::Serverless::Api
Properties:
Cors:
AllowHeaders: "'Authorization,Content-Type,X-Amz-Date,X-Amz-Security-Token,X-Api-Key,X-Requested-With'"
AllowMethods: "'GET,HEAD,POST'"
AllowOrigin: "'*'"
DefinitionBody:
swagger: 2.0
info:
version: 1.0
title: !Sub MyAPIGateway-${EnvironmentName}
paths:
/{proxy+}: # https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html
x-amazon-apigateway-any-method:
x-amazon-apigateway-integration:
httpMethod: POST
type: aws_proxy
uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Function.Arn}/invocations
x-amazon-apigateway-policy:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal: "*"
Action: execute-api:Invoke
Resource: execute-api:/*/*/*
Condition:
IpAddress:
Fn::Transform:
Name: AWS::Include
Parameters:
Location: s3://foo/bar/latest/cidr.yaml
将s3://foo/bar/latest/cidr.yaml
其视为包含所有列入白名单的 IP 的文件,我无权更新或编辑它,因为它由安全管理。
假设在这些 CIDR 块之上,我想添加一些 NAT IP,在Condition
我可以有一些东西的情况下,以便在IpAddress
元素下我有另一个条目并硬编码其中的 NAT IP,以便在 CloudFormation 运行时将两者合并为一个包含来自两者的 IP 的资源策略?
现在,我部署并手动转到 API Gateway Web 控制台下的资源策略,添加我的 NAT IP,保存并重新部署它。
我想避免继续进行此手动更新。
附带说明一下,我可以拥有自己的 yaml 文件,其中包含所有内容,但我不想克隆该s3://foo/bar/latest/cidr.yaml
文件并将我的 NAT IP 添加到其中并在我的CloudFormation
配置中使用克隆的文件,因为我也必须更新克隆的副本如果主文件中的某些内容发生变化,security
例如添加/删除 CIDR 块,则经常发生这种情况。
解决方案
作为Statement
一个列表,我添加了另一个条目以包含 NAT IP,它起作用了。
就像是:
Statement:
- Effect: Allow
Principal: "*"
Action: execute-api:Invoke
Resource: execute-api:/*/*/*
Condition:
IpAddress:
Fn::Transform:
Name: AWS::Include
Parameters:
Location: s3://foo/bar/latest/cidr.yaml
- Effect: Allow
Principal: "*"
Resource: execute-api:/*/*/*
Condition:
IpAddress:
aws:SourceIp:
- "myNatIp1/32"
- "myNatIp2/32"
- "myNatIp3/32"
Action: execute-api:Invoke
谢谢!
推荐阅读
- css - 如何在图表上滑动图像
- jenkins - 等待多个作业完成后再开始另一个作业
- google-cloud-platform - Apache Airflow 与在 gcp 计算引擎实例上安装 google-cloud-bigquery 版本不一致
- javascript - 后端端点上的链接在电子邮件文本中显示不正确
- c# - 将 Mysql 数据填充到 asp 日历需要很长时间才能加载
- mysql - 如何修复“选择每列中没有空值或空白值的行”?
- android - 真正的手机可以工作,但是当我在 Android 项目上工作时,模拟器无法在 intellij idea 中运行
- python-3.x - 我如何使用 python 在 gmail 中找到两个给定日期之间的电子邮件
- php - 如何使用 php 和 google gmail api 将电子邮件发送到多个电子邮件抄送 ID?
- javascript - Vue.js 通过 Axios 使用 API 给出错误:未捕获(承诺中)TypeError:无法读取未定义的属性“协议”