Self Host | RDS | Stuck at "Building structure def...
# support
s
Hello there! First of all thank you for this awesome open-source project, I've used it in the past and am looking forward to working with it again soon 🙂 I work as a DevOps at a healthtech startup and I'm currently trying to self host Medplum on our own AWS account using the recommended services (ie. RDS, ElastiCache, ECS, EC2, etc). After finally getting all the different components up and running (backend, frontend & storage), my ECS task running the Medplum Server boots up. However, after executing all the pre-deploy migrations, it seems to be getting stuck on the "Building structure definitions...." step (see attached screenshot). I waited over an hour earlier, but it's like if the process just decided to stop without erroring or anything. I connected to my RDS instance via our VPN, and all the tables are there. They have been successfully created. Most of them are empty (
User
included) which makes me think the
createSuperAdmin
step also might not have completed successfully, or it might just be because the transaction never completes. There is however a Project with id
161452d9-43b7-5c29-aa7b-c85680fa45c6
which seems to come from here https://github.com/medplum/medplum/blob/5fc4c2928a66f881049d1ad50f82d3d87e96666e/packages/server/src/constants.ts#L11
Is there anything obvious I'm missing here? I ran the docker compose setup locally to compare, and the "Building structure definitions...." step took no longer than 5 seconds total. Any input or guidance would be much appreciated. Obviously if there's any more info you guys need in order to help out, I'll be happy to provide. For what it's worth I'm using the official
medplum/medplum-server:4.1.8
Docker image on a 2 vCPU / 4 GB container with an RDS PostgreSQL
db.t4g.medium
. Best, Sam. https://cdn.discordapp.com/attachments/1384639030817193984/1384639031018524672/Screenshot_2025-06-17_at_4.50.14_PM.png?ex=68532916&is=6851d796&hm=bf10496cd1c2c2a787bbc281af3b28589a7258d8492191b365fbbfcfca43dbbd&
f
Hey @Sam , sorry about this. Looking into it for ya
s
Awesome thank you!
f
Ok, so it makes sense that only Project/161452d9-43b7-5c29-aa7b-c85680fa45c6 would exist since that one is created during the pre-deploy migrations. Would you be able to try again and then when it's hanging, run the following two queries on your database to try to ascertain where it's stuck.
Copy code
-- shows active connections
SELECT application_name, pid, state, age(now(), xact_start) age,
  left(regexp_replace(query,E'[\\n\\r]+',' ','g'), 100)
  FROM pg_stat_activity WHERE state <> 'idle' ORDER BY age;

-- shows locks
SELECT a.datname, c.relname, l.tuple, l.transactionid, l.mode, l.GRANTED, a.usename,
       a.query_start, age(now(),a.xact_start) AS xact_age, age(now(),a.query_start) AS query_age, a.pid 
  FROM  pg_stat_activity a
  JOIN pg_locks l ON l.pid = a.pid
  JOIN pg_class c ON c.oid = l.relation
  WHERE a.query_start < NOW() - INTERVAL '1 seconds'
  ORDER BY a.query_start;
s
Just ran those two, here are the results: - Showing active connections: only shows the current connection that I'm on (ie. my device -> VPN -> RDS); - Showing locks: none. I think it is worth mentioning that today I tried booting up the medplum server locally using
cd medplum/packages/server && npm run dev
after having changed the medplum.config.json file to point to the RDS database. The seed process worked flawlessly. So I'm starting to think the issue might be caused by ECS somehow?
Also probably worth mentioning, my AWS infra is all written with Terraform, I tried making it as close as possible to your guys’s official CDK package, but I might have missed something.
f
Ahh, gotcha. Thanks for the clarification there @Sam
s
Another issue I'm having is I'm completely unable to have the medplum server container healthcheck pass, it always reports as unhealthy. Here's my ECS task definition; the port number I'm using is
8103
and do note I updated the image to
medplum-server:latest
since I saw you guys pushed a few updates since last time. I also tried hitting the private IP address of my container directly on
{PRIVATE-IP}:8103/healthcheck
and it just spins forever (I did update the security group to allow inbound 8103 traffic via our VPN). https://cdn.discordapp.com/attachments/1384639030817193984/1385304588902596768/Screenshot_2025-06-19_at_1.04.04_PM.png?ex=685594ef&is=6854436f&hm=ac9d8e863250241837b77ef35c69beed0f2ca2190d2bdcb5a4e029567e6550fd& https://cdn.discordapp.com/attachments/1384639030817193984/1385304589229625554/Screenshot_2025-06-19_at_1.05.43_PM.png?ex=685594ef&is=6854436f&hm=e37c9325e6d059a18df73a4cfd238ba07674a5ae3d76be9dfdb0a3044668db83&
r
hi sam! Quick question - is there a reason the CDK doesn't work for you? Would love to understand if there are some limitations in your organization/environment?
s
Hello @reshma ! Thanks for jumping in. Most (if not all) of our other infra is written with Terraform already; we try to keep it consistent across our different services. However I will be trying out the CDK this afternoon to compare and hopefully find the root of the issues I'm having. Does that answer your question?
r
Totally helps ty!
s
Hey @finnbergquist , small update here. I re-ran the medplum server init on a fresh installation (still on ECS), and now whenever it gets stuck on
Building structure definitions....
I'm seeing a bunch of locks on RDS: https://cdn.discordapp.com/attachments/1384639030817193984/1385620661220933652/Screenshot_2025-06-20_at_9.59.12_AM.png?ex=6856bb4d&is=685569cd&hm=6288845ebf12536dcdcd0ee79c78dc69099bb48c2389206ec8aa5df72ac91e18&
Any idea what it could mean?
r
What does your healthcheck say? To perform a healthcheck, access the endpoint
/healthcheck
on your server. For example, if your private server IP is
{PRIVATE-IP}
and it's running on port
8103
, use
http://{PRIVATE-IP}:8103/healthcheck
. Ensure network access, security group settings, and the server are correctly configured to allow and serve this request.
Networking and security groups were configured properly to accept connections from my device.
After a lot of debugging, I finally figured out that my issue was the connection to Redis. The [Redis connection initialization](https://github.com/medplum/medplum/blob/main/packages/server/src/redis.ts#L9) was unsuccessful, so I'm suspecting the Node server was just indefinitely waiting for that connection to succeed and wasn't able to process any other code in the meantime. Thank you @reshmaand @User for helping out! 🙂
f
Ahh, got it. Glad you were able to get that figured out!
164 Views