title: How to start webserver in public port using Akka http in Scala
body: <p>I am using the below code to start server to handle http request. It is working in local machine. As It is deployed in EC2 instance, though inbound rules are added, it is not available to public. It is accessible only inside EC2 instance using curl command.</p>
  <pre><code>import akka.actor.typed.ActorSystem
  import akka.actor.typed.scaladsl.Behaviors
  import akka.http.scaladsl.Http
  import akka.Done
  import akka.http.scaladsl.server.Route
  import akka.http.scaladsl.server.Directives._
  import akka.http.scaladsl.model.StatusCodes
  // for JSON serialization/deserialization following dependency is required:
  // &quot;com.typesafe.akka&quot; %% &quot;akka-http-spray-json&quot; % &quot;10.1.7&quot;
  import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._
  import spray.json.DefaultJsonProtocol._
  
  import scala.io.StdIn
  
  import scala.concurrent.Future
  
  
  object WebServer {
  
    // needed to run the route
    implicit val system = ActorSystem(Behaviors.empty, &quot;SprayExample&quot;)
    // needed for the future map/flatmap in the end and future in fetchItem and saveOrder
    implicit val executionContext = system.executionContext
  
    
    def main(args: Array[String]): Unit = {
  
      val bindingFuture = Http().newServerAt(&quot;localhost&quot;, 8080).bind(routes)
      println(s&quot;Server online at http://localhost:8080/\nPress RETURN to stop...&quot;)
      StdIn.readLine() // let it run until user presses return
      bindingFuture
        .flatMap(_.unbind()) // trigger unbinding from the port
        .onComplete(_ =&gt; system.terminate()) // and shutdown when done
    }
  }
  </code></pre>
  <p>As I tried  this , I am getting the below error.</p>
  <pre><code>val bindingFuture = Http().newServerAt(&quot;3.8.161.134&quot;, 8080).bind(routes)
  
  16:39:36.811 [SprayExample-akka.actor.default-dispatcher-3] ERROR a.i.TcpListener - Bind failed for TCP channel on endpoint [/3.8.161.134:9000]
  java.net.BindException: [/3.8.161.134:9000] Cannot assign requested address
          at java.base/sun.nio.ch.Net.bind0(Native Method)
          at java.base/sun.nio.ch.Net.bind(Net.java:459)
          at java.base/sun.nio.ch.Net.bind(Net.java:448)
  </code></pre>
  <p><strong>What I should do to make the server and port available to outside EC2 instance?</strong></p>