ec2id #1

  • //
  • p4-sdp/
  • dev_rebrand/
  • Server/
  • Unix/
  • p4/
  • common/
  • cloud/
  • aws/
  • bin/
  • ec2id
  • View
  • Commits
  • Open Download .zip Download (738 B)
#!/bin/bash
set -u

# This is the cheater's trick to get the AWS EC2 Instance ID.
EC2_InstanceID=$(readlink /var/lib/cloud/instance)
EC2_InstanceID=${EC2_InstanceID##*/}
[[ -n "$EC2_InstanceID" ]] && echo "$EC2_InstanceID"

# For reference, this is a more "official" way to get an AWS EC2 Instance ID.
### TOKEN=$(curl -sS -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600") 2>/dev/null
### EC2_InstanceID=$(curl -sS -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/instance-id)
### echo "$EC2_InstanceID"

# Tip: The /var/lib/cloud/instances directory does not get cleaned up during AMI
# create/restore process.  It can contain multiple obsolete instance IDs.
# Change User Description Committed
#1 31914 C. Thomas Tyler p4 merge
  p4 resolve -am
  p4 resolve (for conflicts)
//p4-sdp/dev/Server/Unix/p4/common/cloud/aws/bin/ec2id
#1 31913 C. Thomas Tyler p4 merge -b SDP_Classic_to_Streams
  p4 resolve -as
//guest/perforce_software/sdp/dev/Server/Unix/p4/common/cloud/aws/bin/ec2id
#2 31877 C. Thomas Tyler Tweaked ec2id.
#1 31876 C. Thomas Tyler Better location for this script, and fixed it.
//guest/perforce_software/sdp/dev/Unsupported/Samples/bin/ec2id
#1 31875 C. Thomas Tyler Added utility to get EC2 instance id.