Instance ID immutable identifier

259 views
Skip to first unread message

Lucía Monte Soto

unread,
Apr 28, 2021, 5:11:38 AM4/28/21
to Google Cloud Developers
Hi,

I am using java to use Google Cloud Platform.

I need an immutable instance identifier, so I tried to use instance.id instead of Project/Zone/InstanceName(orID) identifier since Zone and even IntanceName could change.

But, to find the instance by ID I have to call to aggregatedList with filter (id = xxxxxx) that find in all regions and zones.

Recently I have used the filters to find label and having unexpected results, so I am insecure about use this solution.

It is another way to find by instance ID?

(the app is outside the vm so to access to metadata instance id is not possible if I am not wrong)

Thanks,
Lucia.

Sean Sáez Fuller

unread,
Apr 30, 2021, 6:12:46 AM4/30/21
to Google Cloud Developers
Hello, Lucia,

Can you show me the unexpected results? I want to know what are your results to be sure if it's showing the correct answer. If you can also provide me your code i can also search your possible issue.

Thank you,
Sean.

Lucía Monte Soto

unread,
Apr 30, 2021, 11:03:47 AM4/30/21
to Google Cloud Developers
Hello,
thanks for answering.

The "unexpected results" was finding by label's value. It only found results for instances in us-central-1.

It was 2 month ago and I din't have time, so I changed the way to find the instance. Now, trying to recover the code for you, I did a quick test and it works... so I guess it is working(now I suppose xD, it is reported to me like an issue and I checked and changed it)

So, sorry for the noise. I attach an example of the code where I was getting unexpected results anyway

I return to my original question, It is another way to find by ID instead of aggregatedList + filter ? or is it the better way to do what I try ?

Thank you,
Lucia.
MainTest.java

Roger Chao Espinalt

unread,
May 3, 2021, 9:42:31 AM5/3/21
to Google Cloud Developers
Hello Lucia,

I'd like to further understand what are you attempting by finding by instance ID, as it is not fully clear to me whether you want: 

1. To obtain the instance ID of a certain instance, which could be done calling the API as found here [1] or following this Stack Overflow post where the user was successful in retrieving it using Java [2].
2. To list the instances of a project and sort an specific one in your application, which could be done also calling the API to obtain the list of instances found within a project [3].

Thank you very much, hoping to hear from you soon,
Roger.
__________________________________________________________
[1] -
[2] -
[3] -
El dia divendres, 30 d’abril de 2021 a les 17:03:47 UTC+2, lucia...@abiquo.com va escriure:

Lucía Monte Soto

unread,
May 3, 2021, 10:32:59 AM5/3/21
to Google Cloud Developers
Hello,
thanks for answering.

I am trying to manage instance lifecycles from an external webapp using java sdk , I store in a DB the instanceId because I need a ID that does not change.

If I store and find using zone or name I could not find the VM some day, because they can change by instance renaming or moving the instance to other zone.

Since it is a external webapp to use metadata it is also not a valid solution. The path does not contains the instance I try to find so I suppose(and for what I have read)is to GET the instance ID from inside a deployed VM, isn't it ?

Due to your response seems like there is no another way, so: I will keep finding the instance from aggregated list(ignoring zone) + id filter.

It is just a little strange to me that this was the only way to "findByID".

Thanks anyway, have a nice day.
Lucia.
Reply all
Reply to author
Forward
0 new messages