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 offSELECT DATABASEPROPERTY('mydatabasename','IsAutoShrink')-- Check all instances at onceSELECT name,is_auto_close_on FROM sys.databases
-- Turn off if onALTERDATABASE 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.
I ran into the following error while attempting to copy files to a bucket via the AWS CLI:
Could not connect to the endpoint URL: “https://wildrydes-us-east-1.s3.wildrydesxxxx.amazonaws.com/?prefix=WebApplication%2F1_StaticWebHosting%2Fwebsite%2F&encoding-type=url”
The solution turned out to be pretty straight-forward. The region on the cli-config was set incorrectly. For example, mine was set to “Sydney” instead of “ap-southeast-2”. Type “aws configure list” to check what yours is set to.
Get your server instance security group:
– Log into AWS
– Navigate to elastic beanstalk
– Open your application instance
– Open configuration
– Open instances
– Find “server” on the page and copy the value in the “EC2 security groups” field
Add your server instance security group to your rds rules:
– Navigate to the RDS Dashboard
– Open your RDS instance
– Click on view details (left hand side or top)
– Find Security and Network
– Click on the rds-launch-wizard under security groups
– Click on inbound rules (very bottom currently)
– Add a new inbound rule with the copied security group as the source