AWS credentials in application.properties

I’m not happy about putting my credentials in the application.properties file. I’m sure there’s a better way to do this. I looked around and found lots of text but no code of help.

I managed to discover this property to be put in application.properties:

#cloud.aws.credentials.accessKey=XXX
#cloud.aws.credentials.secretKey=XXX
cloud.aws.region.static=us-east-2
cloud.aws.credentials.instanceProfile=true

But I got an error when running this command:

curl -H “Content-Type: text/plain” localhost:8080/generateShortcode -d ‘”https://www.google.co.uk/”‘

{
“timestamp”: “2018-10-16T12:28:53.098+0000”,
“status”: 500,
“error”: “Internal Server Error”,
“message”: “Unable to load AWS credentials from any provider in the chain: [com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper@46f388f7: Unable to load credentials from service endpoint, com.amazonaws.auth.profile.ProfileCredentialsProvider@349515a3: No AWS profile named ‘default’]”,
“path”: “/generateShortcode”
}

Google brought me here: https://github.com/aws/aws-sdk-java/issues/1324

SDK has a credential resolution logic to resolve the aws credentials to use when interacting with aws services. See the below link:
http://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html

When you see the error “Unable to load AWS credentials from any provider in the chain”, it means we could not find credentials in any of the places the DefaultAWSCredentialsProviderChain looks at. Please make sure the credentials are located at at least one of the places mentioned in the above link.

Urgh, I just put them in… a problem for another day…

Unable to find a region via the region provider chain. Again! Maven install in eclipse.

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 10.008 sec <<< FAILURE!
testLambdaFunctionHandler(com.backtojavaland.imageresizer.LambdaFunctionHandlerTest) Time elapsed: 8.923 sec <<< ERROR!
com.amazonaws.SdkClientException: Unable to find a region via the region provider chain. Must provide an explicit region in the builder or setup environment to supply a region.

This is when following along the tutorial and trying to Run As.. > Maven install

I just can’t get it to work. It should be picking it up from the config file. So I tried adding an environment variable, adding something to settings.xml (although tbh I didn’t know what name to give it). Nothing worked, so I just disabled running tests for the install Run Configuration. At least I have my jar now.

No idea what’g going on!

.aws/config profile warning

Oct 15, 2018 11:36:31 AM com.amazonaws.auth.profile.internal.BasicProfileConfigLoader loadProfiles
WARNING: Your profile name includes a ‘profile ‘ prefix. This is considered part of the profile name in the Java SDK, so you will need to include this prefix in your profile name when you reference this profile from your Java code.

 

[profile awsdeveloper]
region = us-east-2
output = json

Removed profile bit. Removed Warning.

 

Unable to find a region via the region provider chain. Must provide an explicit region in the builder or setup environment to supply a region

Building Serverless Applications with Spring and AWS -Marc Thomas

Creating an Image Resizing Application

The first time I try to run something, it doesn’t work… surprise, surprise…

Anyway… I look online and it says that all the credentials should have been picked up from when I setup the CLI (Command Line Interface). I checked in Eclipse via Window > Preferences > AWS Toolkit, and it all seemed fine. I did set up a profile of awsdeveloper because I wanted to keep it separate from work aws stuff.

Unable to find a region via the region provider chain. Must provide an explicit region in the builder or setup environment to supply a region. at com.amazonaws.client.builder.AwsClientBuilder.setRegion(AwsClientBuilder.java:436)#

Found the answer in the first stackoverflow question Google found:

“I solved this by adding the AWS_REGION environment variable. E.g. us-east-2. When using Eclipse, you can add this using the Run –> Run Configurations.”

As I was running a JUnit test, I updated the Debug Configuration. 😀