Search code examples
alibaba-cloudalibaba-cloud-ecs

How to get the instance id from within an ECS instance?


In the Alibaba cloud Enviroment, how to find out the instance id of an ECS instance from within the ECS instance?


Solution

  • Steps for Linux Instance

    1. Connect to a Linux instance by using a password.
    2. Run curl http://100.100.100.200/latest/meta-data/ to access the root directory of the metadata.
    3. Add the specific metadata name to the preceding command to access the specified metadata. For example: Run curl http://100.100.100.200/latest/meta-data/instance-id to get the ID of an ECS instance. Run curl http://100.100.100.200/latest/meta-data/image-id to get the image ID of an ECS instance.

    For Windows Instances

    1. Connect to a Windows instance.
    2. Use PowerShell to run Invoke-RestMethod http://100.100.100.200/latest/meta-data/ to get the metadata.
    3. Add the specific metadata name to the preceding command to access the specified metadata. For example: Run Invoke-RestMethod http://100.100.100.200/latest/meta-data/instance-id to get the ID of an ECS instance. Run Invoke-RestMethod http://100.100.100.200/latest/meta-data/image-id to get the image ID of an ECS instance.