Package software.amazon.awssdk.imds
Interface Ec2MetadataAsyncClient
- All Superinterfaces:
AutoCloseable
,SdkAutoCloseable
- All Known Implementing Classes:
DefaultEc2MetadataAsyncClient
Interface to represent the Ec2Metadata Client Class. Used to access instance metadata from a running EC2 instance.
Note: A single client instance should be reused for multiple requests when possible.
Instantiate the Ec2MetadataAsyncClient
Default configuration
Ec2MetadataAsyncClient client = Ec2MetadataAsyncClient.create();
Custom configuration
Example of a client configured for using IPV6 and a fixed delay for retry attempts :Ec2MetadataAsyncClient client = Ec2MetadataAsyncClient.builder()
.retryPolicy(p -> p.backoffStrategy(FixedDelayBackoffStrategy.create(Duration.ofMillis(500))))
.endpointMode(EndpointMode.IPV6)
.build();
Use the client
Call theget
method on the client with a path to an instance metadata:
Ec2MetadataAsyncClient client = Ec2MetadataAsyncClient.create();
CompletableFuture<Ec2MetadataResponse> response = client.get("/latest/meta-data/");
response.thenAccept(System.out::println);
Closing the client
Once all operations are done, you may close the client to free any resources used by it.Ec2MetadataAsyncClient client = Ec2MetadataAsyncClient.create();
// ... do the things
client.close();
Note: A single client instance should be reused for multiple requests when possible.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
The builder definition for aEc2MetadataClient
. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()
Creates a builder for an async client instance.static Ec2MetadataAsyncClient
create()
Create anEc2MetadataAsyncClient
instance using the default values.Gets the specified instance metadata value by the given path.Methods inherited from interface software.amazon.awssdk.utils.SdkAutoCloseable
close
-
Method Details
-
get
Gets the specified instance metadata value by the given path. For more information about instance metadata, check the Instance metadata documentation.- Parameters:
path
- Input path- Returns:
- A CompletableFuture that completes when the MetadataResponse is made available.
-
create
Create anEc2MetadataAsyncClient
instance using the default values.- Returns:
- the client instance.
-
builder
Creates a builder for an async client instance.- Returns:
- the newly created builder instance.
-