0

I want to fetch configuration properties from Parameter Store on boostrap application, for that I am using io.awspring.cloud:spring-cloud-starter-aws-parameter-store-config:2.3.3 and I run the same configuration on Windows where it works but on linux ec2 instance or WSL2 I am receiving below error message:

AwsParameterPropertySourceNotFoundException: com.amazonaws.SdkClientException: Unable to load AWS credentials from any provider in the chain: [EnvironmentVariableCredentialsProvider: Unable to load AWS credentials from environment variables (AWS_ACCESS_KEY_ID (or AWS_ACCESS_KEY) and AWS_SECRET_KEY (or AWS_SECRET_ACCESS_KEY))

but before run it I am doing

export AWS_ACCESS_KEY_ID="xxxx"
export AWS_SECRET_ACCESS_KEY="xxxxx"

I also verify it using printenv and yes they are there. So the question is why I am receiving ...Unable to load AWS credentials from environment variables AWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY...does anyone know?

EDIT:

Forgot to mention but I use io.awspring.cloud:spring-cloud-starter-aws-parameter-store-config with configuration:

cloud:
  aws:
    credentials:
      access-key: ${AWS_ACCESS_KEY_ID}
      secret-key: ${AWS_SECRET_ACCESS_KEY}
    region:
      static: eu-west-1
      auto: false
      use-default-aws-region-chain: true
    stack:
      auto: false

But underhood it use DefaultAWSCredentialsProviderChain so it should works like AWS SDK for Java

Adriano
  • 874
  • 2
  • 11
  • 37
  • Are you doing that in the same 'shell' window? Try replacing `AWS_SECRET_ACCESS_KEY ` with `AWS_SECRET_KEY` – Ermiya Eskandary Dec 21 '22 at 12:43
  • Upgrade to AWS SDK for Java V2 and use the cred providers documened in the DEV Guide: https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/credentials.html – smac2020 Dec 21 '22 at 13:40
  • @ErmiyaEskandary I've tried and I used the same console – Adriano Dec 21 '22 at 13:48
  • `on linux ec2 instance` - why don't you just attach an IAM role to the instance? – Ermiya Eskandary Dec 21 '22 at 14:35
  • @ErmiyaEskandary Param Store is on totaly different AWS account – Adriano Dec 21 '22 at 14:55
  • Are you sure your key ID and secret access key both work 100%? No typos for when you're doing an export? – Ermiya Eskandary Dec 21 '22 at 14:58
  • @smac2020 But I don't think I need aws sdk for java when I am only using `io.awspring.cloud:spring-cloud-starter-aws-parameter-store-config` – Adriano Dec 21 '22 at 15:03
  • I use the Official AWS SDK and answer question with this in mind. The above API looks like a 3rd party AWS API. – smac2020 Dec 21 '22 at 15:27
  • @ErmiyaEskandary Yes both works but when I am running them on Windows machine – Adriano Dec 21 '22 at 15:41
  • For me it seems like my jar has no access to ENV properties. Using the same console I export params then `java -jar ...` – Adriano Dec 21 '22 at 16:11
  • Ok I found the issue. Problem was with that I export variables as user but run java jar as sudo https://stackoverflow.com/questions/8633461/how-to-keep-environment-variables-when-using-sudo – Adriano Dec 21 '22 at 16:23

0 Answers0