CloudFormation中如何获取用户选择的VPC的CIDR block?

How can I get the CIDR block of the VPC selected by the user in CloudFormation?

我要求用户选择现有的 VPC:

Parameters:
  MyVPC:
    Type: AWS::EC2::VPC::Id

然后在我的 'Resources' 块中,我试图获取该 VPC 的 CIDR 块。
当我尝试这个时:

      - Fn::GetAtt:
        - MyVPC
        - CidrBlock

我得到:

Template error: instance of Fn::GetAtt references undefined resource MyVPC

我理解我猜是因为从技术上讲 MyVPC 是一个参数而不是资源。

那么如何获取用户选择的VPC的网段呢?

我觉得不可能。

Parameter 只是一个 VPC ID,而不是 VPC 本身。

GetAtt 命令需要模板中的 Resource,但不存在。

您需要将 CIDR 块添加为另一个参数,或者创建一个 Lambda 支持的 Custom Resource 来获取信息并将其提供给模板。