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!!!