【发布时间】:2021-05-19 17:16:39
【问题描述】:
我正在使用 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 块。
【问题讨论】:
标签: amazon-web-services amazon-cloudformation aws-api-gateway amazon-iam