Jenkins Server – trying to run AWS cli script – getting an error

aws-cliJenkins

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 !

Best Answer

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