IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    在aws ec2机器上查看本机instance ID

    深夜的蚊子发表于 2016-11-30 15:36:34
    love 0

    今天蚊子遇上个小需求,要使用aws ec2的user-data让机器在启动的时候挂载一个已经存在的ebs volume,这样就需要在机器启动的时候知道自己当前机器的instance-id,其实办法也很简单,只需要安装一个包,运行一条命令就可以实现了

    sudo apt-get install cloud-utils

    然后运行如下命令

    $ ec2metadata --instance-id
    i-4b5f8ac5

    可以使用下面的方法获得ec2metadata更多的用法

    $ ec2metadata --help
    Syntax: /usr/bin/ec2metadata [options]
    
    Query and display EC2 metadata.
    
    If no options are provided, all options will be displayed
    
    Options:
        -h --help               show this help
    
        --kernel-id             display the kernel id
        --ramdisk-id            display the ramdisk id
        --reservation-id        display the reservation id
    
        --ami-id                display the ami id
        --ami-launch-index      display the ami launch index
        --ami-manifest-path     display the ami manifest path
        --ancestor-ami-ids      display the ami ancestor id
        --product-codes         display the ami associated product codes
        --availability-zone     display the ami placement zone
    
        --instance-id           display the instance id
        --instance-type         display the instance type
    
        --local-hostname        display the local hostname
        --public-hostname       display the public hostname
    
        --local-ipv4            display the local ipv4 ip address
        --public-ipv4           display the public ipv4 ip address
    
        --block-device-mapping  display the block device id
        --security-groups       display the security groups
    
        --mac                   display the instance mac address
        --profile               display the instance profile
        --instance-action       display the instance-action
    
        --public-keys           display the openssh public keys
        --user-data             display the user data (not actually metadata)

     

    © 2016, 深夜的蚊子. 版权所有. 如转载,请注明:转载自 蚊子空间[http://www.wenzizone.cn]



沪ICP备19023445号-2号
友情链接