CloudFormation ElasticIP参数

问题描述 投票:-1回答:1

我有一个CloudFormation模板,它将OpenVPN添加到现有的VPC中,并需要弹性IP分配ID作为参数。它还将来自相同弹性IP的公共IP地址添加到OpenVPN实例配置(在其UserData部分中)。

我目前已将其实现为2个参数(使用假定的默认值),即

Parameters:

  ElasticIpAddress:
    Description: >-
      IP Address of an Elastic IP.
    Type: String
    Default: 53.176.52.215

  ElasticIpAllocationId:
    Description: >-
      Allocation id of the same Elastic IP to associate OpenVPN server with.
    Type: String
    Default: eipalloc-f2013ba5

  ...

注 - 这两者都必须指向AWS中的相同ElasticIP!

ElasticIpAddress部分创建OpenVPN实例时使用AWS::EC2::Instance参数,如下所示: -

openVPN:
  Type: 'AWS::EC2::Instance'
  Properties:
    Tags:
      - Key: Name
        Value: openVPN server
    UserData:
      Fn::Base64: !Sub |
        public_hostname=${ElasticIpAddress}
        admin_user=${OpenVPNASAdminUser}
    ...

...并且ElasticIpAllocationIdAWS::EC2::EIPAssociation部分使用...

IPAssoc:
  Type: 'AWS::EC2::EIPAssociation'
  Properties:
    AllocationId: !Ref ElasticIpAllocationId
    InstanceId: !Ref openVPN
  DependsOn: openVPN

拥有(a)分配ID和(b)相同弹性IP的IP地址似乎非常冗余!

我的主要问题是 - 是否存在以下功能: -

  1. 从弹性IP分配ID或中检索IP地址
  2. 从弹性IP的IP地址检索分配ID?

我的直觉是,我必须在实例的UserData:部分内使用CLI并使用AWS CLI命令 - 不确定它与OpenVPN AMI有多好用,因为它目前只需要OpenVPN特定配置。

任何建议表示赞赏!

amazon-web-services amazon-cloudformation openvpn elastic-ip
1个回答
0
投票

实现您想要的正确方法是创建R53记录,例如vpn.mydomain.com,它指向您的弹性IP地址(A记录)。然后,您可以在userdata而不是$ {ElasticIpAddress}中分配此记录,并消除对IP地址参数的需要。

public_hostname=vpn.mydomain.com

只要你的EIP在R53记录上更新,你应该是好的。如果您需要更改EIP地址,这仍然有用,您仍然可以通过Route53控制已部署实例上的记录。

Getting Started with Route53

© www.soinside.com 2019 - 2024. All rights reserved.