# AWS ECS session replication

**URL:** https://forum.payara.fish/t/aws-ecs-session-replication/393
**Category:** Payara Server
**Created:** [July 15, 2022, 5:56pm UTC](https://forum.payara.fish/t/aws-ecs-session-replication/393 "2022-07-15T17:56:43Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![fkj](https://avatars.discourse-cdn.com/v4/letter/f/a698b9/32.png) [@fkj](https://forum.payara.fish/u/fkj)
#### Post date: [July 15, 2022, 5:56pm UTC](https://forum.payara.fish/t/aws-ecs-session-replication/393/1 "2022-07-15T17:56:43Z")

</div>

Hi,

I’m trying to set up a data grid on AWS ECS.

I was able to get JCache working with these tutorials:

> **[Get Started with Embedded Hazelcast on ECS](https://docs.hazelcast.com/tutorials/ecs-embedded)**
>
> In this tutorial, you'll deploy an application with embedded Hazelcast on an ECS cluster. Hazelcast members from each application replica will automatically discover themselves and form one consistent Hazelcast cluster. Thanks to...

> **[GitHub - mikecroft/payara-hazelcast-aws: Demo of Hazelcast-AWS plugin using...](https://github.com/mikecroft/payara-hazelcast-aws)**
>
> Demo of Hazelcast-AWS plugin using DiscoveryStrategy configuration - GitHub - mikecroft/payara-hazelcast-aws: Demo of Hazelcast-AWS plugin using DiscoveryStrategy configuration

But session replication is not working. I developed a very simple JSF webapp to test based on the hajspcluster demo, it has on web.xml and the session attributes are serializable.

What am I missing?

Thanks

Session test application code:

```auto
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
   <h:head>
      <title>Facelet Title</title>
   </h:head>
   <f:view transient="true">
      <h:body>
         <h:form id="form">
            Key <h:inputText value="#{indexBean.key}" />
            Value <h:inputText value="#{indexBean.value}" />
            <h:commandButton value="add" action="#{indexBean.add()}" />
            <br /><br />
            <ul>
               <li>server: <h:outputText value="#{facesContext.externalContext.request.serverName}" /></li>
               <li>session id: <h:outputText value="#{facesContext.externalContext.request.session.id}" /></li>
               <li>Served From Server instance: #{indexBean.instanceName}</li>
               <li>Executed Server IP Address: #{indexBean.hostAddress}</li>
            </ul>
            <br /><br />
            <ui:repeat id="itens" value="#{indexBean.sessionMap}" var="item">
               #{item.key} - #{item.value} <br />
            </ui:repeat>
         </h:form>      
      </h:body>
   </f:view>
</html>

```

```auto
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/JSF/JSFManagedBean.java to edit this template
 */
package com.mycompany.session.test;

import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
import java.net.UnknownHostException;
import java.util.Map;
import javax.faces.context.FacesContext;

/**
 *
 * @author fjaekel
 */
@Named(value = "indexBean")
@SessionScoped
public class IndexBean implements Serializable {

   private String key;
   private String value;
   
   /**
    * Creates a new instance of IndexBean
    */
   public IndexBean() {
      
   }
   
   public void add()
   {
      getSessionMap().put(key, value);
      
      System.out.println(getSessionMap());
   }
   
   public String getInstanceName()
   {
      return System.getProperty("com.sun.aas.instanceName");
   }
   
   public String getHostAddress()
   {
      try {
         return java.net.InetAddress.getLocalHost().getHostAddress();
      } catch (UnknownHostException ex) {
        return ex.getMessage();                
      }
   }

   public String getKey() {
      return key;
   }

   public void setKey(String key) {
      this.key = key;
   }

   public String getValue() {
      return value;
   }

   public void setValue(String value) {
      this.value = value;
   }

   public Map<String, Object> getSessionMap() {
      return FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
   }   
}

```

```auto
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
   
    <distributable/>
    
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <context-param>
       <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
      <param-value>client</param-value>       
    </context-param>
    
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
    
    <session-config>
        <session-timeout>
            30
        </session-timeout>
        <!--<tracking-mode>COOKIE</tracking-mode>-->
    </session-config>
    
    <welcome-file-list>
        <welcome-file>index.jsf</welcome-file>
    </welcome-file-list>
</web-app>

```

```auto
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
   <session-config>
      <session-manager persistence-type="hazelcast"> 
         <manager-properties>
            <property name="relaxCacheVersionSemantics" value="true"/>
         </manager-properties> 
      </session-manager> 
   </session-config>
</glassfish-web-app>

```

---

<div class="post-metadata">

### Author: ![JamesHillyard](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.payara.fish/jameshillyard/32/134_2.png) [@JamesHillyard](https://forum.payara.fish/u/JamesHillyard)
#### Post date: [July 22, 2022, 10:02am UTC](https://forum.payara.fish/t/aws-ecs-session-replication/393/2 "2022-07-22T10:02:51Z")

</div>

HI @fkj,

We have a blog written regarding setting up session replication in Payara Server, although the blog is written as part of a series using Apache web server, the setup should still be applicable when using AWS ECS.

The blog can be found here: [Session Replication in Payara Server with Hazelcast](https://blog.payara.fish/session-replication-in-payara-server-with-hazelcast)

If you are still unable to configure session replication after following that blog, I will gladly take a further look.

Thanks,  
James

---

<div class="post-metadata">

### Author: ![fkj](https://avatars.discourse-cdn.com/v4/letter/f/a698b9/32.png) [@fkj](https://forum.payara.fish/u/fkj)
#### Post date: [August 4, 2022, 4:05am UTC](https://forum.payara.fish/t/aws-ecs-session-replication/393/3 "2022-08-04T04:05:27Z")

</div>

I followed these steps.

I can see some action at the logs, but when I stop one of the two instances of the test the session is lost

```auto
|[#|2022-08-04T03:49:09.869+0000e[1;92m|INFO|e[0mPayara 5.2022.2|e[1;94mfish.payara.nucleus.cluster.PayaraCluster|e[0m_ThreadID=146;_ThreadName=hz.gracious_wu.event-7;_TimeMillis=1659584949869;_LevelValue=800;||
| --- | --- | --- | --- | --- | --- | --- |
|Data Grid Instance Added 69af623f-4e29-4c6f-b6e3-b342f6df6985 at Address /172.31.10.219:5701|#]|
|[#|2022-08-04T03:49:09.872+0000e[1;92m|INFO|e[0mPayara 5.2022.2|e[1;94mfish.payara.nucleus.cluster.PayaraCluster|e[0m_ThreadID=146;_ThreadName=hz.gracious_wu.event-7;_TimeMillis=1659584949872;_LevelValue=800;||
|Data Grid Status|
|Payara Data Grid State: DG Version: 4 DG Name: dev DG Size: 2|
|Instances: {|
|DataGrid: dev Name: server Lite: false This: true UUID: 74107202-7a29-4ae7-a840-b0f0b57f3b97 Address: /172.31.21.224:5701|
|DataGrid: dev Lite: false This: false UUID: 69af623f-4e29-4c6f-b6e3-b342f6df6985 Address: /172.31.10.219:5701|
|}|#]|

```

---

<div class="post-metadata">

### Author: ![fkj](https://avatars.discourse-cdn.com/v4/letter/f/a698b9/32.png) [@fkj](https://forum.payara.fish/u/fkj)
#### Post date: [August 31, 2022, 8:50pm UTC](https://forum.payara.fish/t/aws-ecs-session-replication/393/4 "2022-08-31T20:50:29Z")

</div>

I was able to get this working by using hazelcast-wm, but I’m still interested in using payara’s embedded hazelcast.

Anyone?
