'How to solve the image not pushing to Amazon ECR throwing 'no basic auth creds'

I am trying to push my docker Image to my private amazon ecr using the Gitlab CI pipeline. When my CI pipeline ran I successfully got logged in but when docker push command runs it takes some time and after that, it shows status failed when I checked the logs then I got this.

$ docker tag 789542361688.dkr.ecr.ap-south-1.amazonaws.com/uiserver:latest 789542361688.dkr.ecr.ap-south-1.amazonaws.com/uiserver:$CI_COMMIT_SHA
$ aws ecr get-login-password --region ap-south-1 | sed 's|https://||' | docker login --username AWS --password-stdin $DOCKER_REGISTRY
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
$ docker push 789542361688.dkr.ecr.ap-south-1.amazonaws.com/uiserver:latest
The push refers to repository [789542361688.dkr.ecr.ap-south-1.amazonaws.com/uiserver]
574e6e6ada0f: Preparing
c78d5f0db824: Preparing
4f317a0a2f77: Preparing
3cddd9de99b4: Preparing
327e42081bbe: Preparing
6e632f416458: Preparing
e019be289189: Preparing
c9a63110150b: Preparing
6e632f416458: Waiting
e019be289189: Waiting
c9a63110150b: Waiting
no basic auth credentials
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1

I don't know what is the issue. If anyone know the problem then please reply.

This is the gitlab ci file code:

build_uiserver:
  stage: build
  image: 
    name: amazon/aws-cli
    entrypoint: [""]
  services:
    - docker:dind
  before_script:
    - amazon-linux-extras install docker
    - aws --version
    - docker --version
  script:
    - echo "build"
    - docker build -t 789542361688.dkr.ecr.ap-south-1.amazonaws.com/uiserver .
    - docker tag 789542361688.dkr.ecr.ap-south-1.amazonaws.com/uiserver:latest 789542361688.dkr.ecr.ap-south-1.amazonaws.com/uiserver:$CI_COMMIT_SHA
    - aws ecr get-login-password --region ap-south-1 | sed 's|https://||' | docker login --username AWS --password-stdin $DOCKER_REGISTRY
    - docker push 789542361688.dkr.ecr.ap-south-1.amazonaws.com/uiserver:latest
    - docker push 789542361688.dkr.ecr.ap-south-1.amazonaws.com/uiserver:$CI_COMMIT_SHA


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source