Skip to content

Instantly share code, notes, and snippets.

@grohiro
Created May 7, 2019 10:40
Show Gist options
  • Select an option

  • Save grohiro/e555a3c8e207449b9c9706bee62c7a9c to your computer and use it in GitHub Desktop.

Select an option

Save grohiro/e555a3c8e207449b9c9706bee62c7a9c to your computer and use it in GitHub Desktop.
Bash functions for EC2
# EC2のインスタンスIDを出力する
function ec2_instance_id()
{
curl -s http://169.254.169.254/latest/meta-data/instance-id/
}
# EC2のインスタンス名を出力する
function ec2_instance_name()
{
aws ec2 describe-instances --instance-ids $(ec2_instance_id) --output text --query 'Reservations[].Instances[].Tags[?Key==\`Name\`].[Value]'
}
export -f ec2_instance_id ec2_instance_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment