Failed to load EC2 instance credentials in InstanceProfileCredentialsProvider instance

I have bound the EC2 role to the instance, to my EC2 instance, and I am running my AWS JAVA SDK. When I try to load credentials this way:

InstanceProfileCredentialsProvider instanceCred = new InstanceProfileCredentialsProvider();

I get the following error:

Exception in thread "main" com.amazonaws.AmazonClientException: Unable to load credentials.
    at com.amazonaws.auth.InstanceProfileCredentialsProvider.loadCredentials(InstanceProfileCredentialsProvider.java:195)
    at com.amazonaws.auth.InstanceProfileCredentialsProvider.getCredentials(InstanceProfileCredentialsProvider.java:124)

Can I assume that I can lose?

+4
source share
1 answer

I managed to get around this by running the code from my EC2 instance and improving my code, here is the code:

 String arn = "arn:aws:iam::"+accountnumber+":role/My-CrossAccount-CustomRole-ReadOnly";

InstanceProfileCredentialsProvider instanceCred = new InstanceProfileCredentialsProvider();

stscred = new STSAssumeRoleSessionCredentialsProvider(instanceCred.getCredentials(),arn,"123",clientConfiguration);

Be convinced that in actions of your role is "sts:AssumeRole".

+2
source

Source: https://habr.com/ru/post/1609324/


All Articles