Skip to content

Commit 3bb3cca

Browse files
Merge pull request #14986 from rabbitmq/mergify/bp/v4.2.x/pr-14975
Make `rabbitmq_aws` use the IPv6 discovery endpoints if the node is configured to use IPv6 (backport #14975)
2 parents 8a38a2a + 13dae27 commit 3bb3cca

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

deps/rabbitmq_aws/include/rabbitmq_aws.hrl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
-define(DEFAULT_PROFILE, "default").
1616

1717
-define(INSTANCE_AZ, "placement/availability-zone").
18+
19+
% https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html
1820
-define(INSTANCE_HOST, "169.254.169.254").
21+
-define(INSTANCE_HOST_6, "fd00:ec2::254").
1922

2023
% rabbitmq/rabbitmq-peer-discovery-aws#25
2124

deps/rabbitmq_aws/src/rabbitmq_aws_config.erl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,13 +420,22 @@ instance_availability_zone_url() ->
420420
instance_credentials_url(Role) ->
421421
instance_metadata_url(string:join([?INSTANCE_METADATA_BASE, ?INSTANCE_CREDENTIALS, Role], "/")).
422422

423+
-spec instance_metadata_host() -> string().
424+
%% @doc Return the appropriate instance metadata host based on IP family configuration
425+
%% @end
426+
instance_metadata_host() ->
427+
case proplists:get_value(inet6, inet:get_rc(), false) of
428+
true -> ?INSTANCE_HOST_6;
429+
false -> ?INSTANCE_HOST
430+
end.
431+
423432
-spec instance_metadata_url(string()) -> string().
424433
%% @doc Build the Instance Metadata service URL for the specified path
425434
%% @end
426435
instance_metadata_url(Path) ->
427436
rabbitmq_aws_urilib:build(#uri{
428437
scheme = http,
429-
authority = {undefined, ?INSTANCE_HOST, undefined},
438+
authority = {undefined, instance_metadata_host(), undefined},
430439
path = Path,
431440
query = []
432441
}).

0 commit comments

Comments
 (0)