This question is related to this: AWS SecretsManager works in Eclipse, can't connect to Service Endpoint in ColdFusion
I have the following function written in Java using the AWS SDK v1.12.459: (Courtesy of How to get accesskey, secretkey using java aws SDK running on EC2)
public String getEC2InstanceKeys() {
String result = "";
try
{
Map<String,EC2MetadataUtils.IAMSecurityCredential> credMap = EC2MetadataUtils.getIAMSecurityCredentials();
Iterator<Map.Entry<String,EC2MetadataUtils.IAMSecurityCredential>> it = credMap.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String,EC2MetadataUtils.IAMSecurityCredential> pair = (Map.Entry<String,EC2MetadataUtils.IAMSecurityCredential>)it.next();
EC2MetadataUtils.IAMSecurityCredential cred = pair.getValue();
result = cred.accessKeyId + "|" + cred.secretAccessKey;
}
}
catch (Exception e)
{
result = e.getMessage();
}
return result;
}
I am running this via RDP into an Amazon EC2.
When I run this in Eclipse or from the Command Line via the main function, it works every time.
When I run this function from ColdFusion running from the EC2, it gives me an empty string. No error, just an empty string.
<cfscript>
obj = CreateObject("java","SMtest");
obj.init();
y = obj.getEC2InstanceKeys();
</cfscript>
<cfdump var="#obj#" >
<cfoutput>#y#</cfoutput>
What is preventing me from getting the correct in ColdFusion ?