2

Below is the error when I am using Ehcache 2 to cache one of the variable in Java code in AWS lambda. Does EhCache run on serverless Aws Lambda?

ERROR Unable to set localhost. This prevents creation of a GUID. Cause was: ip-10-22-209-10: ip-10-22-209-10: Name or service not known (net.sf.ehcache.Cache:224)
java.net.UnknownHostException: ip-10-22-209-10: ip-10-22-209-10: Name or service not known
    at java.net.InetAddress.getLocalHost(InetAddress.java:1505)
    at net.sf.ehcache.Cache.<clinit>(Cache.java:222)
    at net.sf.ehcache.config.ConfigurationHelper.createCache(ConfigurationHelper.java:305)
    at net.sf.ehcache.config.ConfigurationHelper.createCaches(ConfigurationHelper.java:238)
    at net.sf.ehcache.CacheManager.addConfiguredCaches(CacheManager.java:816)
    at net.sf.ehcache.CacheManager.doInit(CacheManager.java:498)
    at net.sf.ehcache.CacheManager.init(CacheManager.java:394)
    at net.sf.ehcache.CacheManager.<init>(CacheManager.java:269)
    at net.sf.ehcache.CacheManager.newInstance(CacheManager.java:1103)
    at net.sf.ehcache.CacheManager.newInstance(CacheManager.java:879)
    at net.sf.ehcache.CacheManager.create(CacheManager.java:860)
    at net.sf.ehcache.CacheManager.getInstance(CacheManager.java:894)
    at com.capitalone.stsedh.datawise.engine.lite.core.service.RuleExecutionServiceImpl.<init>(RuleExecutionServiceImpl.java:50)
Henri
  • 5,551
  • 1
  • 22
  • 29
Manoj4068
  • 123
  • 1
  • 7
  • 14

1 Answers1

2

EHCache uses the local machine's IP address as part of a (dubious) way to construct a GUID (adding the local machine's IP address really doesn't give any more global-uniqueness than a 128-bit cryptographically random number, especially in a world where many servers run on private IPs).

It appears that, while the Java code is able to retrieve the hostname of the local machine, Lambda is not able to resolve that hostname. So that information can't be used in the GUID.

However, failing to resolve the IP won't cause the GUID generation to fail. The log message comes from a catch block and it looks like the exception merely leaves the localhost variable set to null. So the generated GUIDs will have "null" rather than "10.22.209.10".

guest
  • 21
  • 1
  • Link just times out for me today but https://github.com/ehcache/ehcache2/blob/main/ehcache-core/src/main/java/net/sf/ehcache/Cache.java#L224 looks likely a reasonable replacement – Martin Dorey May 09 '22 at 19:28