title: AWS Lambda Play Scala project with VPC throws UnknownHostException
body: <p>I am trying to run a scala Play application as an AWS Lambda function based on the example <a href="https://github.com/Enalmada/play-lambda-sample" rel="nofollow">here</a>
  The class is a simple function:</p>
  
  <pre><code> class PlayTask {
  
    // AWS Lambda Handler
    def exec(event: S3Event): String = WithApplication { App =&gt;
      Play.current.configuration.getString("Play.Lambda.Greet").getOrElse("")
    }
  
    private def WithApplication[A](f: Application =&gt; A): A = {
      val env = Environment(new java.io.File("."), getClass.getClassLoader, Mode.Prod)
      val context = ApplicationLoader.createContext(env)
      val app = ApplicationLoader(context).load(context)
      try {
        Play.start(app)
        f(app)
      } finally {
        Play.stop(app)
      }
    }
  }
  </code></pre>
  
  <p>The jar is loaded onto S3 container and connected to VPC for access to RDS and internet.
  However on connecting with VPC and running S3 put test I get the following error.</p>
  
  <pre><code>    at com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:132) [task/:na] 
   at com.google.inject.internal.MembersInjectorImpl$1.call(MembersInjectorImpl.java:93) [task/:na] 
   at com.google.inject.internal.MembersInjectorImpl$1.call(MembersInjectorImpl.java:80) [task/:na] 
   at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1103) [task/:na] 
   at com.google.inject.internal.MembersInjectorImpl.injectAndNotify(MembersInjectorImpl.java:80) [task/:na] 
   at com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:62) [task/:na] 
   at com.google.inject.internal.InjectorImpl.injectMembers(InjectorImpl.java:984) [task/:na] 
   at com.google.inject.util.Providers$GuicifiedProviderWithDependencies.initialize(Providers.java:149) [task/:na] 
   at com.google.inject.util.Providers$GuicifiedProviderWithDependencies$$FastClassByGuice$$2a7177aa.invoke(&lt;generated&gt;) [task/:na] 
   at com.google.inject.internal.cglib.reflect.$FastMethod.invoke(FastMethod.java:53) [task/:na] 
   at com.google.inject.internal.SingleMethodInjector$1.invoke(SingleMethodInjector.java:57) [task/:na] 
   at com.google.inject.internal.SingleMethodInjector.inject(SingleMethodInjector.java:91) [task/:na] 
   at com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:132) [task/:na] 
   at com.google.inject.internal.MembersInjectorImpl$1.call(MembersInjectorImpl.java:93) [task/:na] 
   at com.google.inject.internal.MembersInjectorImpl$1.call(MembersInjectorImpl.java:80) [task/:na] 
   at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092) [task/:na] 
   at com.google.inject.internal.MembersInjectorImpl.injectAndNotify(MembersInjectorImpl.java:80) [task/:na] 
   at com.google.inject.internal.Initializer$InjectableReference.get(Initializer.java:174) [task/:na] 
   at com.google.inject.internal.Initializer.injectAll(Initializer.java:108) [task/:na] 
   at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:174) [task/:na] 
   at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:110) [task/:na] 
   at com.google.inject.Guice.createInjector(Guice.java:96) [task/:na] 
   at com.google.inject.Guice.createInjector(Guice.java:73) [task/:na] 
   at com.google.inject.Guice.createInjector(Guice.java:62) [task/:na] 
   at play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:126) [task/:na] 
   at play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:93) [task/:na] 
   at play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21) [task/:na] 
   at example.PlayTask.WithApplication(PlayTask.scala:16) [task/:na] 
   at example.PlayTask.exec(PlayTask.scala:9) [task/:na] 
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_71] 
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_71] 
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_71] 
   at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_71] 
   at lambdainternal.EventHandlerLoader$PojoMethodRequestHandler.handleRequest(EventHandlerLoader.java:439) [lambda-sandbox.jar:na] 
   at lambdainternal.EventHandlerLoader$PojoHandlerAsStreamHandler.handleRequest(EventHandlerLoader.java:370) [lambda-sandbox.jar:na] 
   at lambdainternal.EventHandlerLoader$2.call(EventHandlerLoader.java:972) [lambda-sandbox.jar:na] 
   at lambdainternal.AWSLambda.startRuntime(AWSLambda.java:231) [lambda-sandbox.jar:na] 
   at lambdainternal.AWSLambda.&lt;clinit&gt;(AWSLambda.java:59) [lambda-sandbox.jar:na] 
   at java.lang.Class.forName0(Native Method) [na:1.8.0_71] 
   at java.lang.Class.forName(Class.java:348) [na:1.8.0_71] 
   at lambdainternal.LambdaRTEntry.main(LambdaRTEntry.java:93) [runtime/:na] 
  Caused by: java.net.UnknownHostException: ip-10-0-77-249: unknown error 
   at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method) ~[na:1.8.0_71] 
   at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928) ~[na:1.8.0_71] 
   at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323) ~[na:1.8.0_71] 
   at java.net.InetAddress.getLocalHost(InetAddress.java:1500) ~[na:1.8.0_71]
  </code></pre>
  
  <p>What I understand from the java.net.UnknownHostException is that the function cannot find the hostname of localhost and fall back onto local loopback. </p>