OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

FastApi session cookies and AWS ECS

  • Thread starter Thread starter user104
  • Start date Start date
U

user104

Guest
I have a FastAPI server that creates a user session with the following code:

Code:
@app.post("/session")
async def create_session(req: reqs.LoginRequest, response: Response):

    session = uuid.uuid4()
    data = SessionData(session_id=str(session), username=req.username, world_id="1")

    await backend.create(session, data)
    cookie.attach_to_response(response, session)

I deploy the server to AWS ECS. There are two tasks running, serving the same image. When I try to get the session, it alternates between a correct response, and a 403 forbidden invalid session response.

I might be wrong, but it seems the cookie is being set such that it only works with the ECS task/instance that set it.

What's the correct way to go around this?
<p>I have a FastAPI server that creates a user session with the following code:</p>
<pre><code>@app.post("/session")
async def create_session(req: reqs.LoginRequest, response: Response):

session = uuid.uuid4()
data = SessionData(session_id=str(session), username=req.username, world_id="1")

await backend.create(session, data)
cookie.attach_to_response(response, session)
</code></pre>
<p>I deploy the server to AWS ECS. There are two tasks running, serving the same image.
When I try to get the session, it alternates between a correct response, and a 403 forbidden <code>invalid session</code> response.</p>
<p>I might be wrong, but it seems the cookie is being set such that it only works with the ECS task/instance that set it.</p>
<p>What's the correct way to go around this?</p>
 

Latest posts

Top