I also got the error 'Cannot perform an interactive login from a non-TTY device.' I fixed the issue this way, and I am sharing all possible different methods to resolve it.
1: Use Non-Interactive Methods
If you're trying to avoid interaction in an automation or script, you can configure AWS credentials instead of logging in each time.
Steps:
-
Run aws configure in the terminal.
-
Enter your Access Key ID, Secret Access Key, region, and output format.
-
Credentials are saved, and you won't need an interactive login for future commands.
2: Force a TTY (for SSH scenarios)
If you're using SSH and need an interactive session, you can force the use of a terminal with the—t flag.
Steps:
-
Use ssh -t user@hostname.
-
The -t flag forces an interactive terminal session.
-
You can now execute interactive commands remotely.
3: Running Docker Containers
When running Docker containers and facing this issue, make the container interactive using the -it flag.
Steps:
-
Run docker run -it <container-name>.
-
This opens an interactive terminal inside the Docker container.
4: CI/CD Pipelines
In CI/CD pipelines (like Jenkins), use environment variables instead of interactive logins.
Steps:
-
Set environment variables:
-
AWS_ACCESS_KEY_ID=your_access_key
-
AWS_SECRET_ACCESS_KEY=your_secret_key
-
AWS_DEFAULT_REGION=your_region
-
These are non-interactive and work well in automated environments.