1

Problem:

I am trying to configure AWS profile on remote host using python paramiko.

My code can connect to the server and able to execute the command. But unable to pass the input one-by-one to the command "aws configure".

Code:

import paramiko
import sys

ip = 'x.x.x.x'
port = 22
username = 'test'
password = "123"
command = "aws configure --profile user1"

ssh=paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip,port,username,password)
stdin,stdout,stderr=ssh.exec_command(command)
stdin.write(id+ '\n')
stdin.write(key+ '\n')
stdin.write('us-east-1'+ '\n')
stdin.write(''+ '\n')
stdin.flush()
print(stdout.read().decode())
ssh.close()

Output: Getting a blank output and when I ssh the server & run "aws configure list" to check whether aws is configured, then showing the following output feilds

    Name                    Value             Type    Location
    ----                    -----             ----    --------
   profile                <not set>             None    None
access_key                <not set>             None    None
secret_key                <not set>             None    None
    region                <not set>             None    None

I am unable to understand where I am making the mistake, can't able to configure the aws on the sshed host. Please provide the solution for this by modifying the code, Thanks!!!

Salik47
  • 149
  • 1
  • 2
  • 9
  • @MartinPrikryl I tried in that way, but dosen't worked. I have updated the above code. – Salik47 Dec 27 '18 at 04:00
  • Can you add more information on what happens? How do you recognize the failure? What's the output of `print(stdout.read().decode())`? Is there an error? If so, what is the error? – TheNavigat Dec 27 '18 at 05:03
  • stderr showing "bash: aws: command not found" – Salik47 Dec 27 '18 at 11:02
  • Didn't understand how this is related to the given solution, can you please provide the explanation. thanks – Salik47 Dec 28 '18 at 19:17

0 Answers0