Vikram Ranabhatt
Vikram Ranabhatt

Reputation: 7620

aws key and scret working on aws cli but not working on jenkins

I am trying to run python script which has code to access s3 using boto3 sdk. I have created default profile in my windows machine.

  1. aws cli commands are working fine in window cmd to access s3 bucket.
  2. python script is also working fine in when launched manually in window cmd

I am trying to automate it through jenkins. It is failing and complaining about Invalid token.

For testing purpose i ran following command in jenkins job.

aws sts get-caller-identity --debug

ClientError: An error occurred (InvalidClientTokenId) when calling the GetCallerIdentity operation: The security token included in the request is invalid 2019-06-17 18:09:06,513 - MainThread - awscli.clidriver - DEBUG - Exiting with rc 255

An error occurred (InvalidClientTokenId) when calling the GetCallerIdentity operation: The security token included in the request is invalid Build step 'Execute Windows batch command' marked build as failure

I tried following

  1. injecting AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN and AWS_ACCESS_KEY_ID, but no success.

  2. Added S3 profile plugin in jenkins and tried both option IAM role and by providing access token and secret.

Its not working.

I observed that jenkins is running on System User but i have created profile in window user.Is this the problem ?

Upvotes: 2

Views: 1481

Answers (1)

error404
error404

Reputation: 2823

The issue was with the USERPROFILE with which jenkins was running.

The default user profile creds were not loaded because the configurations was done for local user and not SYSTEM USER.

Adding .credentials under SYSTEM USER Jenkins worked fine.

Upvotes: 2

Related Questions