how to get volume id attached to instance from AWS CLI

The volumes IDs are not available from the metadata. The virtual devices are available under block-device-mapping/

You will need to use the AWS CLI (or script, program, etc.) to get the volume IDs assigned to an instance.

With the CLI:

aws ec2 describe-volumes

The output will include the instance ID that a volume is attached to.

Once you know the instance ID, you can filter on just those volumes attached to that instance:

aws ec2 describe-volumes --filters Name=attachment.instance-id,Values=i-555550604eaf99999

The documentation will have more details and examples.

describe-volumes