AMI doesn't execute command

The connection is broken when the script exits. The script is exiting before all the responses have been received.