Skip to content

Commit fde4ddb

Browse files
Merge pull request #14987 from rabbitmq/mergify/bp/v4.1.x/pr-14986
Make `rabbitmq_aws` use the IPv6 discovery endpoints if the node is configured to use IPv6 (backport #14975) (backport #14986)
2 parents 6ecf64c + 5eb4a37 commit fde4ddb

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
@@ -419,13 +419,22 @@ instance_availability_zone_url() ->
419419
instance_credentials_url(Role) ->
420420
instance_metadata_url(string:join([?INSTANCE_METADATA_BASE, ?INSTANCE_CREDENTIALS, Role], "/")).
421421

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

0 commit comments

Comments
 (0)