How to use ipv6 in Java Lambda functions?


Given that ipv6 is now supported in aws lambda, I have this code-

System.setProperty("", "true");
InetAddress ipAddress = Inet6Address.getByName("");"ip is {}", ipAddress.getHostAddress());

and yet, the hostname is resolving to an ipv4. Note that I am deploying my function as an image with base When I run the code locally or on an ec2 instance, I see ipv6 address but on lambda, I see ipv4 address.

FWIW, I have also tried java runtime version 17 (as opposed to a docker image) but I still can't make lambda resolve to an ipv6 address.

asked 18 days ago65 views
1 Answer


This update seems to allow Lambda connected to VPC to use IPv6, but is your Lambda connected to VPC?

profile picture
answered 18 days ago
  • Of course :) and I can see "Allow IPv6 traffic = true" in the VPC config of the lambda

  • The code below is in Python, but in that case I was able to obtain IPv6. Therefore, you can check the IPv6 address with Lambda as well.

    import json
    import socket
    def lambda_handler(event, context):
            ipv6_address = socket.getaddrinfo("", None, socket.AF_INET6)[0][4][0]
            print(f"IPv6 address for {ipv6_address}")
        except socket.gaierror as e:
            print(f"Error getting IPv6 address: {e}")

    Is IPv6 linked to VPC?

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions