Unfortunately, at the moment you cannot do what you want without cluttering up your application with the help of special AWS functions or changing the EB script / deployment process.
Options # 1: Check for AWS Metadata from Your Application
You can directly curlAWS metadata ( http://169.254.169.254/latest/meta-data/instance-id ) directly from your Docker container.

, EC2_INSTANCE_ID ( , ), AWS, . FYI, 169.254.0.0/16 - - . , AWS .
# 2:
Dockerfile ENV. , ENV Docker. Docker , , , Docker.
Injecting Dockerfile . appdeploy/pre .ebextensions:
files:
"/opt/elasticbeanstalk/hooks/appdeploy/pre/02injectdockerfile.sh":
mode: "000755"
content: |
. /opt/elasticbeanstalk/hooks/common.sh
EB_CONFIG_APP_CURRENT=$(/opt/elasticbeanstalk/bin/get-config container -k app_deploy_dir)
cd $EB_CONFIG_APP_CURRENT
echo "ENV EC2_INSTANCE_ID \"`curl -s http://169.254.169.254/latest/meta-data/instance-id`\"" >> Dockerfile
pre-appdeploy? container_commands?
container_commands . , . container_commands Dockerfile (docker build). Dockerfile, ENV docker build.
: . appdeploy hook:
[ec2-user@ip-172-31-62-137 ~]$ tree /opt/elasticbeanstalk/hooks/appdeploy/
/opt/elasticbeanstalk/hooks/appdeploy/
βββ enact
β βββ 00run.sh
β βββ 01flip.sh
βββ post
β βββ 01_monitor_pids.sh
βββ pre
βββ 00clean_dir.sh
βββ 01unzip.sh
βββ 02docker_db_check.sh
βββ 03build.sh
pre/01unzip.sh docker build pre/03build.sh. , script, ENV script 01unzip.sh 03build.sh. , . , , , Elastic Beanstalk. , "" , .
, - . : docker run enact/00run.sh. EB script.