I have a Flask app with code like the following in application.py
:
if __name__ == "__main__":
print('loading model...')
model = load_model('my_model.h5')
print('model loaded')
application.run()
Upon running python application.py
in my local environment, this code executes. However, in my Elastic Beanstalk environment, this code doesn't get run as there is no print('loading model...')
statements in the logs and the application fails with a "model is undefined" error when the model needs to get used (as it must have never been loaded when the application started). Why is this behaving different to my local environment and how can I ensure code is run when the application is started on Elastic Beanstalk? I'm using the default free t2.micro for this example.