In V1 SDK, we can use EC2MetadataUtils.getIAMSecurityCredentials();
to get the temporary security credentials associated with the IAM roles on the instance.
Map<String, EC2MetadataUtils.IAMSecurityCredential> credMap = EC2MetadataUtils.getIAMSecurityCredentials();
What's the equivalent in the V2 SDK?
I can't find anything in the dev guides or on Stack Overflow.
CodePudding user response:
The EC2MetadataUtils
class also exists in the AWS SDK for Java v2.
getIAMSecurityCredentials
is documented here.
import software.amazon.awssdk.regions.internal.util.EC2MetadataUtils;
Map<String, EC2MetadataUtils.IAMSecurityCredential> credMap = EC2MetadataUtils.getIAMSecurityCredentials();