Bulk import fails on EC2 deployment

On ec2 deployment using UserData, I’m running commands to install and run mattermost. After these commands I’ve added bulk import command, which currently is failing.
Anyone else come across this?
(I’ve also added a loop so it will only run import command when system ping is OK)

Here’s part of the error log which is produced from bulk import --apply
“App.IsPhase2MigrationCompleted: This API endpoint is not accessible as required migrations have not yet completed., SqlSystemStore.GetByName: Unable to find the system variable., sql: no rows in result set
Error occurred on data file line 2”

What Mattermost server version are you on?

Using v 5.23.0

also mysql DB on RDS