0

I am running a Jenkins server on Windows server with AWS CLI installed. while trying to run a script through Jenkins job i get the following error:

"You must specify a region. You can also configure your region by running "aws configure"."

AWS cli is configured (running the script manually - all good)

Script: aws ec2 run-instances --image-id ami-12345 --count 1 --instance-type m4.large --key-name my-key --security-groups defaultSG

(If i add a --region im getting: "Unable to locate credentials")

Thanks !

3 Answers3

0

Try adding --region <your-region-name> to the options.

For example

aws ec2 run-instances --region your-region-name --image-id ami-12345 --count 1 --instance-type m4.large --key-name my-key --security-groups defaultSG 
Thomas
  • 4,225
  • 5
  • 23
  • 28
0

Find which user you have configured awscli and on which user jenkins is running. If both users are different change that. In windows go to services select jenkins and change the user. In linux check pid on which jenkins is running and search who has that pid in /etc/passwd and check on which user u configured awscli or configure awscli on the user who running jenkins. I have the same issue i solved like this hope it helps.

Alexander Tolkachev
  • 4,608
  • 3
  • 14
  • 23
0

This question is pretty old so I guess the answer is no more relevant to the OP but it may help others.

In order to use AWS-CLI, you need to first create a pair of "aws_access_key_id" and "aws_secret_access_key" in AWS IAM service by finding the user there, selecting it and then "Security Credentials" and "Create Access Key".

Write both of them down, because you will not be able to display "aws_secret_access_key" again.

Then, in the machine where you intend to use AWS CLI from, assuming you've installed it...

Find the user which is running Jenkins process, sudo into it and run:

aws configure

Then, in the first question, provide the generated "aws_access_key_id", in the second question provide the generated "aws_secret_access_key", skip the next question or input "json" and then in the last question, insert the region code where most your servers reside, for example, "us-east-1".

Itai Ganot
  • 10,644
  • 29
  • 93
  • 146