0

出现“EIP 无法稳定”错误。代码如下...可能是代码,也可能是 cloudformation 错误。

我想将 2 个 EIP 连接到接口,一个连接到主私有 IP,一个连接到辅助私有 IP。当我从控制台执行此操作时,它可以工作。

如果我注释掉“VIP”或“EIP”代码,我还可以成功添加 2 个私有 IP 和一个附加到主私有 IP 或辅助私有 IP 的 EIP。两者都可以,但不能同时使用。

  #ServerOne.
  ServerOne:
    Type: AWS::EC2::Instance
    Properties:
      AvailabilityZone: !Ref AvailabilityZoneA
      DisableApiTermination: !Ref disableInstanceDeletion
      ImageId: !FindInMap [ RegionMap, !Ref "AWS::Region", ServerOne ]
      InstanceType: !FindInMap [ InstanceSizingMap, !Ref StackSizing, ServerOne ]
      EbsOptimized: !FindInMap [ InstanceSizingMap, !Ref StackSizing, ebsOptimizedInstances ]
      BlockDeviceMappings: 
          - DeviceName: "/dev/sda1"
            Ebs: 
              DeleteOnTermination: !FindInMap [ InstanceSizingMap, !Ref StackSizing, DeleteOnTermination ]
      KeyName: !Ref SSHKeyName
      Monitoring: 'false'
      NetworkInterfaces:
        -
          NetworkInterfaceId: !Ref ServerOneInterface
          DeviceIndex: 0
      Tags:
      - Key: Name
        Value: ServerOne
      - Key: Role
        Value: Infrastructure

        # ServerOne Server Network.  2 Private IPs, 2 EIPs all on one interface.
          ServerOneEIP:
            Type: AWS::EC2::EIP
            DependsOn: IGW
            Properties:
              InstanceId: !Ref ServerOne
              Domain: vpc

          ServerOneVIP:
            Type: AWS::EC2::EIP
            DependsOn: IGW
            Properties:
              InstanceId: !Ref ServerOne
              Domain: vpc

          ServerOneEIPAssociation:
            Type: AWS::EC2::EIPAssociation
            DependsOn: ServerOneVIPAssociation
            Properties:
              AllocationId: !GetAtt ServerOneEIP.AllocationId
              NetworkInterfaceId: !Ref ServerOneInterface
              PrivateIpAddress: !GetAtt ServerOneInterface.PrimaryPrivateIpAddress

          ServerOneVIPAssociation:
            Type: AWS::EC2::EIPAssociation
            DependsOn: IGW
            Properties:
              AllocationId: !GetAtt ServerOneVIP.AllocationId
              NetworkInterfaceId: !Ref ServerOneInterface
              PrivateIpAddress: !Select [ 0, !GetAtt ServerOneInterface.SecondaryPrivateIpAddresses ]

          ServerOneInterface:
            Type: AWS::EC2::NetworkInterface
            Properties:
              SubnetId: !Ref PublicSubnetA
              SecondaryPrivateIpAddressCount: 1
              Description: ServerOne Network Interface
              GroupSet: [
                !Ref PuppetClientSG ]
        # ServerOne is doing NAT, so Source/Dest is false.
              SourceDestCheck: false
4

1 回答 1

1

代码如下。

---
Parameters:
Subnet:
Description: ID of the Subnet the instance should be launched in, this will 
link the instance to the same VPC.
Type: List<AWS::EC2::Subnet::Id>
Resources:
EIP1:
    Type: AWS::EC2::EIP
Properties:
  Domain: VPC
EIP2:
Type: AWS::EC2::EIP
Properties:
  Domain: VPC
Association1:
  Type: AWS::EC2::EIPAssociation
DependsOn:
- ENI
- EIP1
Properties:
  AllocationId:
    Fn::GetAtt:
    - EIP1
    - AllocationId
  NetworkInterfaceId:
    Ref: ENI
  PrivateIpAddress:
    Fn::GetAtt:
    - ENI
    - PrimaryPrivateIpAddress
Association2:
Type: AWS::EC2::EIPAssociation
DependsOn:
- ENI
- EIP2
Properties:
  AllocationId:
  Fn::GetAtt:
    - EIP2
    - AllocationId
  NetworkInterfaceId:
    Ref: ENI
  PrivateIpAddress:
    Fn::Select:
    - '0'
    - Fn::GetAtt:
      - ENI
      - SecondaryPrivateIpAddresses
ENI:
Type: AWS::EC2::NetworkInterface
Properties:
  SecondaryPrivateIpAddressCount: 1
  SourceDestCheck: false
  SubnetId:
    Fn::Select:
    - '0'
    - Ref: Subnet
OpenVPN:
    Type: AWS::EC2::Instance
    DependsOn:
    - ENI
    Properties:
    InstanceType: t2.micro
      AvailabilityZone: us-east-2a
      NetworkInterfaces:
      - NetworkInterfaceId:
          Ref: ENI
        DeviceIndex: '0'
    ImageId: ami-8a7859ef
    KeyName: jimkey
于 2017-06-26T20:13:04.190 回答