Yes, via EC2MetadataUtils.getIAMSecurityCredentials()
EC2MetadataUtils is a Java adapter for the metadata service that you are accessing via curl, and exposes these fields in EC2MetadataUtils.IAMSecurityCredential
.
Signature:
public static class EC2MetadataUtils.IAMSecurityCredential
Fields:
String accessKeyId
String secretAccessKey
To access these fields, use EC2MetadataUtils.getIAMSecurityCredentials()
:
public static Map<String,EC2MetadataUtils.IAMSecurityCredential> getIAMSecurityCredentials()
Documentation:
It is outside the scope of this question, but also worth noting that if you are using these credentials for the AWS SDK for Java on this instance that you don't need to define these credentials explicitly -- AWS Clients using the default constructor will search for these credentials as part of the default credentials provider chain. More info in this documentation.