How to emit IPv6 address of EC2 instance in the ouputs of a cloudformation stack?
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
Solution 1:
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 :)