【问题标题】:Cloudformation AWS: Assign an ip address to a CustomerGateway using parametersCloudformation AWS:使用参数将 IP 地址分配给 CustomerGateway
【发布时间】:2020-02-26 00:15:07
【问题描述】:

我正在设计一个cloudformation模板,但我需要将源IP定义为参数

我试图将参数定义为字符串,但它会产生以下错误:

Value (${MyCustomerGateway}) for parameter ipAddress is invalid. Invalid Format. (Service: AmazonEC2; Status Code: 400; Error Code: InvalidParameterValue; Request ID: 4de02112-fb1f-47a1-931c-97727568df99)

这是模板的片段:

Parameters:
  MyCustomerGateway:
    Description: IpAddress.
    Default: 0.0.0.0
    Type: String  

Resources:
  CustomerGateway_1:
    Type: 'AWS::EC2::CustomerGateway'
    Properties:
      Type: ipsec.1
      BgpAsn: 3352
      IpAddress: ${MyCustomerGateway} 
      Tags:
        - Key: Name
          Value: CustomerGateway_1

IP翻译有什么特殊数据吗?

我不确定哪种方法是正确的

【问题讨论】:

    标签: amazon-web-services amazon-ec2 amazon-cloudformation ip-address ipsec


    【解决方案1】:

    将IpAddress: ${MyCustomerGateway} 更改为IpAddress: !Ref myCustomerGateway

    更多关于Ref:

    内部函数 Ref 返回指定的值 参数或资源。

    > 当你指定一个参数的逻辑名时,它返回的值是 参数。

    当您指定资源的逻辑名称时,它会返回一个值 您通常可以用来指代该资源,例如物理资源 身份证。

    奖励:

    如果您想验证参数输入,可以使用AllowedPattern 属性。

    用法:

    PrimaryIPAddress:
        Type: String
        Description: This must be a valid IP address.
        AllowedPattern: (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})
        ConstraintDescription: must be a valid IP address of the form x.x.x.x.
    

    输入无效IP时出错:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-22
      • 2021-04-19
      • 2018-11-13
      • 1970-01-01
      • 2015-07-29
      • 2016-04-15
      • 1970-01-01
      相关资源
      最近更新 更多