I try to figure out whether I run on regular computer or ec2 (from JVM based app). The simple method could be attempt to get instance data, however that means I should wait until timeout, and it does not feel right. Is there a quicker way to know this?
Asked
Active
Viewed 162 times
1
-
In my case it's windows – J-unior Jun 23 '14 at 14:29
-
1Please edit your question to include this relevant information. – EEAA Jun 23 '14 at 14:53
1 Answers
1
Amazon Windows AMIs come with the "EC2Config" service installed. If we can make some assumptions about your environment (like... you're not also running some service called EC2Config locally), then you may be able to take advantage of this.
If you can list the services available on your machine, you can search for the EC2Config service. Here's an example in PowerShell where I use Get-Service
, and return true if the count of services named "Ec2Config" is greater than zero:
On EC2:
PS C:\> @(Get-Service -Name "Ec2Config" -ErrorAction 'SilentlyContinue').Count -gt 0
True
On Local:
PS C:\> @(Get-Service -Name "Ec2Config" -ErrorAction 'SilentlyContinue').Count -gt 0
False
I can't help you with a Java implementation, but some quick googling suggests it shouldn't be too bad.
![](../../users/profiles/184431.webp)
Anthony Neace
- 1,011
- 10
- 18