Unable to use AWS CLI in Jenkins due to "Unable to locate credentials" error

Solution 1:

You can export the credentials as environmental variables:

$ export AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
$ export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
$ export AWS_DEFAULT_REGION=us-west-2

See http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html for more information. Depending on how you're using Jenkins you may want to use the EvnInject Plugin

Solution 2:

Kindly update you aws credentials within the the bash of the jenkins server. Run the below commands:

# sudo -su jenkins
# aws configure

Reference Link: http://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-ami-jenkins.html

Solution 3:

This method worked for me:

  1. Make directory in /var/lib/jenkins that called .aws (or copy .aws folder from home directory if you already configured your aws credentials via "aws configure" command)
  2. Then go down to /var/lib/jenkins/.aws and write sudo shown -R jenkins ./ to change owner for files in .aws directory.