How to make the FROM stage in Dockerfile dynamic?

Hi there,

I have two AWS accounts that contain the same ECR repo name i.e. my-ecr-repo.

Currently, the FROM stage in Dockerfile looks like this:

FROM 123XXXXXXX.dkr.ecr.my-aws-regionXXX.amazonaws.com/my-ecr-repo:latest as builder

which is manually passing of account name and region. And, I would like to make it dynamic such as this

FROM $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/my-ecr-repo:latest as builder

Does anyone know how can I achieve this?