首页 > 解决方案 > 如何在 AWS 网络防火墙的 cloudformation 中读取 !GetAtt 返回的键列表:值

问题描述

我正在尝试访问在不同 AZ 的 3 个子网中创建的 3 个网络防火墙端点,这些端点被添加到路由表中:

网络防火墙的逻辑名称是“NetworkFirewall”

!GetAtt NetworkFirewall.EndpointIds.${AWS::Region}b
!GetAtt NetworkFirewall.EndpointIds.${AWS::Region}c```

As specified in AWS docs:

Fn::GetAtt
The Fn::GetAtt intrinsic function returns a value for a specified attribute of this type. The following are the available attributes and sample return values.

For more information about using the Fn::GetAtt intrinsic function, see Fn::GetAtt.

EndpointIds
The unique IDs of the firewall endpoints for all of the subnets that you attached to the firewall. The subnets are not listed in any particular order. For example: **["us-west-2c:vpce-111122223333", "us-west-2a:vpce-987654321098", "us-west-2b:vpce-012345678901"]**.

But this way:
!GetAtt NetworkFirewall.EndpointIds.${AWS::Region}a
of accessing endpoints, seems to be not working.

Any tips will be helpfull

标签: amazon-web-services

解决方案


正如你已经观察到的,你不能做你想做的事。CloudFormation (CFN) 根本不支持搜索列表等操作。

如果您想继续使用 CFN,实现您想要的唯一方法是通过自定义资源。在您的情况下,您必须以lambda 函数的形式开发这样的资源,它会EndpointIds为您进行自定义搜索和过滤。

另一种方法是不使用 CFN。您可以尝试使用其他基础设施即代码工具。例如,在 terraform 中,您想要的此类操作是自然且易于实现的。


推荐阅读