AWS ECR
Non TTY Device Error
Amazon Container Services
Docker Login Issue
Command Line Error

aws ecr saying Cannot perform an interactive login from a non TTY device after copied cmd from Amazon Container Services

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Amazon Elastic Container Registry (ECR) is a fully managed container image registry service provided by AWS, making it easy for developers to store, manage, and deploy Docker container images. A common issue that users might encounter when interacting with ECR is the error message: "Cannot perform an interactive login from a non TTY device". This typically occurs when attempting to authenticate ECR using certain command-line environments or scripts.

Understanding the Error Message

The error message "Cannot perform an interactive login from a non TTY device" indicates that the authentication process expects an interactive TTY session, but the current environment does not provide one. TTY (TeleTYpewriter) refers to a terminal session that allows interaction with the user, typically seen in common command-line interfaces.

Why Does This Error Occur?

  1. Non-TTY Environments: When running shell scripts or commands via automation tools (like Jenkins, GitHub Actions, etc.), there is often no TTY associated with the process, which can confuse certain interactive programs or commands.
  2. Incorrect Command Usage: The command to authenticate with ECR may be misconfigured or executed in a non-interactive context where it expects user inputs.
  3. Scripted Environments: Using the ECR login commands in a CI/CD pipeline or other scripted environments without proper adjustments can lead to this error.

Resolving the Error

Use the $(aws ecr get-login-password) Command

The error is often encountered when copying commands directly from Amazon Container Services interfaces, which are typically intended for interactive use. Here's a solution for non-interactive sessions:

bash
aws ecr get-login-password --region <region> | docker login --username AWS --password-stdin <aws_account_id>.dkr.ecr.<region>.amazonaws.com
  • Explanation:
    • aws ecr get-login-password retrieves an authentication token using AWS CLI.
    • docker login --username AWS --password-stdin uses this token to authenticate with your ECR registry.
    • This method is preferred for non-TTY environments as it does not require interactive input.

Example in a CI/CD Pipeline

For those using Jenkins, GitHub Actions, or similar tools, consider incorporating AWS authentication in your pipeline scripts as follows:

yaml
1name: CI/CD Pipeline
2
3on:
4  push:
5    branches:
6      - main
7
8jobs:
9  build-and-deploy:
10    runs-on: ubuntu-latest
11    steps:
12      - name: Checkout code
13        uses: actions/checkout@v2
14
15      - name: Configure AWS Credentials
16        uses: aws-actions/configure-aws-credentials@v1
17        with:
18          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
19          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
20          aws-region: us-west-2
21
22      - name: Login to Amazon ECR
23        run: |
24          echo "Logging in to Amazon ECR..."
25          aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.us-west-2.amazonaws.com
26
27      - name: Build, tag, and push image
28        run: |
29          docker build -t my-app .
30          docker tag my-app:latest ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.us-west-2.amazonaws.com/my-app:latest
31          docker push ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.us-west-2.amazonaws.com/my-app:latest

Conclusion

When working with AWS ECR, encountering the "Cannot perform an interactive login from a non TTY device" error typically signals the need to adjust your approach to authentication for a non-interactive environment. Leveraging the aws ecr get-login-password command combined with Docker's --password-stdin option ensures smooth and error-free operations within scripted or automated workflows.

Summary Table

IssueCauseSolution
"Cannot perform an interactive login from a non TTY device"Non-interactive session Interactive commands in automation Misconfigured authenticationUse aws ecr get-login-password with Docker Employ script adaptations for CI/CD

This implementation helps override the interactive requirement, making it scalable and adaptable across various development and deployment strategies.


Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design