LoginSignup
3
3

More than 1 year has passed since last update.

EC2で自身が所属しているVPCのIDを調べるワンライナー

Posted at

タイトルの通り、EC2上で自身が所属しているVPC IDを取得するワンライナーです。

aws ec2 describe-instances --query "Reservations[].Instances[?InstanceId == \`$(curl -s 169.254.169.254/2021-01-03/meta-data/instance-id)\`].VpcId" --output text

変数に入れて使いたい場合。

$ vpcid=$(aws ec2 describe-instances --query "Reservations[].Instances[?InstanceId == \`$(curl -s 169.254.169.254/2021-01-03/meta-data/instance-id)\`].VpcId" --output text)

$ echo $vpcid
vpc-xxxxx
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3