I’ve been having a bit of an issue with my AWS app going to sleep and taking a long time to handle initial requests.
I’m using .NET with Elastic Beanstalk on a T2 Micro Instance and MSSQL Server Express on RDS. My FrontEnd is a static ReactJS app that sits in S3 behind CloudFront. There’s also a load balancer across the backend.
My frontend was always instant but my initial Api calls were timing out. This ruled out S3 and CloudFront, leaving the following:
After a bit of Googling I came across something that looked fairly promising – MSSQL Server Express has a property called AutoClose set to ‘ON’ by default. AWS appears to correct this as mine was off however it’s worth checking:
-- If set to zero then auto close is off
-- Check all instances at once
SELECT name,is_auto_close_on FROM sys.databases
-- Turn off if on
ALTER DATABASE myDB SET AUTO_CLOSE OFF
In my case the actual problem turned out to be IIS idle timeout. By default IIS automatically times out an application after 20 minutes. In order to disable this create the following ebextension:
command: "appcmd set apppool /apppool.name:DefaultAppPool /.processModel.idleTimeout:0.00:00:00"
I ran into the following error while trying to start serverless offline:
throw er Unhandled ‘error’ event spawn java ENOENT at exports._errnoException (util.js:1020:11) at Process.ChildProcess._handle.onexit (internal/child_process.js:197:32) at onErrorNT (internal/child_process.js:376:16) at _combinedTickCallback (internal/process/next_tick.js:80:11) at process._tickDomainCallback (internal/process/next_tick.js:128:9)
It turned out to be because I didn’t have the Java JDK installed.
I expect you’ll have the same problem if the command prompt doesn’t have access to the JAVA_HOME variable or if your JAVA_HOME path isn’t set correctly.