import subprocess cmd='aws cloudtrail lookup-events --lookup-attributes AttributeKey=EventName,AttributeValue=RunInstances --max-results 20 --region us-east-1' cmds=cmd.split(' ') cl=subprocess.run(cmds, capture_output=True) lines=cl.readlines() print(lines)