Use ECS repository image as build image in CircleCI

I have been using my Docker-hub account till now in CircleCI, and now for some reason I’m trying to use my ECR repository image in the same place as build image in CircleCI (2.0)

But I see ECR doesn’t support public images. So I can’t mention my image as below as I did for Dockerhub image,

version: 2

jobs:
build:
working-directory: ~/tmp
docker:
- image: /

as,

version: 2
jobs:
build:
working-directory: ~/tmp
docker:
- image: aws-id.dkr.ecr.eu-central-1.amazonaws.com/image

It will throw error,

no basic auth credentials

In a straight forward operation it needs to get authenticated via command,

aws ecr get-login --region

and then running,

docker login -u AWS -p -e none https://aws-id.dkr.ecr.eu-central-1.amazonaws.com

I tried putting this commands in Pre-dependency commands section of CircleCI plan settings and didn’t work.

Ideas?

StackOverflow Question :