简体   繁体   中英

AWS CLI: The config profile (test) could not be found

I am automating the AWS IAM user creation from Jenkins. We have multiple Accounts with programmatic access. I am trying to create user account for one account from CLI. It's working fine from CLI, but not from jenkins Pipeline.

Output through CLI

aws iam create-user --user-name --profile test tets

{
    "User": {
    "Path": "/",
    "UserName": "tets",
    "UserId": "AIDAXTRPYNIV6HK7XE43R",
    "Arn": "arn:aws:iam::523012434475:user/tets",
    "CreateDate": "2019-09-18T06:49:41Z"
}



node
{
    stage ('creating IAM user'){
    sh 'aws iam create-user --user-name --profile test $Username'       
}

The config profile (test) could not be found is the error i am getting from Jenkins Pipeline.

AWS CLI is configured on jenkins server. From ssh i am able to execute all the commands.

I've just hit this problem too. Took an hour to unpick but FWIW in the interests of saving others' time (providing they have the same setup):

We use jenkins on an ec2 instance in AWS (built with "ubuntu" as the user). The actual home dir for jenkins is mounted on /data/jenkins

ssh'ing on to the server as ubuntu user puts you in shell as ubuntu. cd ~ # takes you to the home directory (you're already in) pwd # shows you in /home/ubuntu sudo su -jenkins # change to jenkins user cd ~ # actually still takes you to /home/ubuntu pwd # prooves you're still in /home/ubuntu

Creating the .aws folder with config and credentials at this location means you can't use the --profile switch with aws cli commands in the pipeline. The jenkins home dir is actually /data/jenkins so when the pipeline runs, calls to the aws cli will be looking for the .aws folder in /data/jenkins

Copying the .aws folder from /home/ubuntu to /data/jenkins, chowning objects for jenkins:jenkins and ensuring read perms (I used chmod 660) means that when the cli runs, it should see the config in /data/jenkins and the annoying "The config profile could not be found"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM