Home > front end >  How can I get the credentials associated with the attached EC2 IAM role using the Java v2 SDK?
How can I get the credentials associated with the attached EC2 IAM role using the Java v2 SDK?

Time:07-23

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.

enter image description here

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();
  • Related