AWS Instance Profile doesn't work with Spring Cloud AWS
The solution to this problem comes from two distinct facts.
Instance profile credentials are going to be used only and only if
application.properties
hasinstanceProfile
property set totrue
andaccessKey
set tonull
(ContextCredentialsAutoConfiguration).Even if you will provide your custom
application.properties
file, Spring is going to readapplication.properties
file bundled with app jar (if it does exist). If that's the case, properties from both files will sum up to create an execution enviroment. I suspect that bundled file is parsed first, then custom second, overriding any property present in bundled file.
In my case, bundled application.properties
had accessKey and secretKey placeholders (with phony values) which were filled out by developer whenever he wanted some testing outside of EC2 enviroment. That made accessKey not null and therefore, excluded instance profile path. I just removed the application.properties file from jar and that solved the problem.
cloud:
aws:
credentials:
accessKey:
secretKey:
instanceProfile: true
useDefaultAwsCredentialsChain: true
This would do the trick, if you were using the latest (2.X.X) Spring AWS Cloud.