'aws codebuild fetch docker token stored in aws secret manager from buildspec.yml file

I have store docker token in aws secrets manager and i am trying to fetch it from buildspec.yml file but i am getting this error. Error response from daemon: Get "https://registry-1.docker.io/v2/": unauthorized: incorrect username or password

The token is correct but i think, i am not using the correct approach to fetch the token.

version: 0.2
env:
  secrets-manager:

    DOCKER_TOKEN: dockertoken

phases:   
  pre_build:
    commands: 
      - echo Logging in to Docker Hub
      - echo $DOCKER_TOKEN | docker login -u dockeraccount --password-stdin 


Sources

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

Source: Stack Overflow

Solution Source