Reputation: 9979
I have an application deployed to Elastic Beanstalk with the Mutli-Container Docker configuration, which is backed by ECS and further backed by EC2. When I SSH onto the EC2 instance, is there some command I can run to identify the name of the EB application / environment that it's running under? Is there anything like aws elasticbeanstalk get-current-environment
?
Upvotes: 1
Views: 2768
Reputation: 5844
You could use this:
$ /opt/elasticbeanstalk/bin/get-config container -k environment_name
…as suggested in this answer.
Upvotes: 1
Reputation: 5844
You could use the Instance Metadata Service (IMDS):
[ec2-user@ip-10-231-25-159 current]$ TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` && curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data
This returns various resources you could request:
ami-id
ami-launch-index
ami-manifest-path
autoscaling/
block-device-mapping/
events/
hostname
iam/
identity-credentials/
instance-action
instance-id
instance-life-cycle
instance-type
local-hostname
local-ipv4
mac
metrics/
network/
placement/
profile
public-hostname
public-ipv4
public-keys/
reservation-id
security-groups
services/
system
If your instance has a public SSH key, you could use the http://169.254.169.254/latest/meta-data/public-keys
endpoint:
[ec2-user@ip-10-231-25-159 current]$ TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" aws-ec2-metadata-token-ttl-seconds: 21600"` && curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/public-keys
In my case, this returns the public key name:
0=my-key-name
This, of course, doesn't return the actual EB environment name. But if you have separate SSH keys for your environments, you can infer the current environment name from the SSH key name.
Upvotes: 1
Reputation: 7356
The EB environment name and id is present in your instance tags. You could run the AWS CLI: aws ec2 describe-tags
to get the environment name. The tag keys would be:
Please note: you would need an IAM role attached to the instances with ec2:DescribeTags
permission for this command to work.
Upvotes: 4
Reputation: 1
I'm a beginner in AWS as well but I believe you are able to enter:
eb status
This will show:
Environment details for: xxxx
Application name: xxxx
Region: us-east-1
Deployed Version: app-xxxxx
Environment ID: xxxxx
Platform: xxxx/Python 2.7 running on 64bit Amazon Linux/2.6.5
Tier: WebServer-Standard-1.0
CNAME: xxxxxxxx.us-east-1.elasticbeanstalk.com
Updated: 2018-04-13 19:10:45.354000+00:00
Status: Ready
Health: Green
Upvotes: -1