1

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?

2
  • In my case it's windows
    – J-unior
    Jun 23, 2014 at 14:29
  • 1
    Please edit your question to include this relevant information.
    – EEAA
    Jun 23, 2014 at 14:53

1 Answer 1

2

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.

Not the answer you're looking for? Browse other questions tagged .