2

I have AWS cloudformation stacks with ec2 instances that are entirely isolated from external traffic. They seldom need to be directly accessed. For cases when they do need to be accessed, I have a stack to launch a bastion host. Is there an easy way, that I've missed from the docs, of getting the IPv6 of the bastion host in the stack outputs ?

# Cloudformation snippet
Resources:
  BastionHost:
    Type: AWS::EC2::Instance
    Properties:
      KeyName: !Ref KeyName
      SubnetId: !Ref MyBastionSubnetId
      Ipv6AddressCount: 1
      ImageId: !Ref LatestAmiId
Outputs:
  BastionIP:
    # Problematically only returns an IPv4
    Value: !GetAtt BastionHost.PublicIp
    Description: Publicly addressable IP of bastion host

3 Answers 3

2

Neither AWS::EC2::Instance nor AWS::EC2::NetworkInterface seem to support it. You can make a feature request at CloudFormation Public Roadmap but it's going to be a while before they implement it.

Your best option is to create a CloudFormation Custom Resource which is essentially a Lambda function that will be given the instance ID as a parameter and than calls EC2.Client.describe_instances() and return the IPv6 address from there. It should be just a few lines of code.

Hope that helps :)

1
  • A custom resource is a viable alternative. We already use those for returning the cloudfront distribution endpoints from cognito.
    – GcL
    Oct 6, 2020 at 23:34
2

As mentioned in the answer above you should use CloudFormation Custom Resource. You can find a Custom Resource which is extracting IPv6 address from EC2 server in https://gist.github.com/martin-garbe/57234836e23c5d53ebfdd157756cc3aa.

It looks like there is no other way and most likely there never will be another way because AWS has other solutions, e.g. use ELB in front and create additional CNAME, for such scenarios.

(Sorry to not using the comment function but my reputation points are too low.)

0

There is a new feature request for accessing the IPv6 address via Cloudformation'S GetAtt, see https://github.com/aws-cloudformation/cloudformation-coverage-roadmap/issues/916 Maybe you can support this feature request.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .