1

I'm using Elastic Beanstalk (EB) in AWS, and I have a serious problem. When my server is down, the EB removes its EC2 instance and creates another instance again. I guess this is how EB handles the server down problem so that the website keeps working.

The problem is that I lose SSL installed on the EC2 and the IP for EC2 changes when the server is removed and created again. How can I handle those issues although EB removes and creates again a new EC2 instance?

Jay
  • 189
  • 2
  • 8
  • An auto-scaling group will replace an unhealthy instance. Put the SSL on the Elastic Load Balancer, and use the load balancer's address instead of individual IPs. That's the whole point of Elastic Beanstalk - not worrying about individual servers. Follow the steps in the "Getting Started" page at https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/GettingStarted.html#GettingStarted.Walkthrough.CreateApp to set up the load balancer. – ceejayoz Jul 12 '18 at 18:13
  • I checked `Load Balancers` page under `EC2`, and then under `Description` tab at the bottom of the page, I see `DNS name` looking like a url. I tried to put this in my A record in `AWS Route 53`, but it says an invalid type. Is it the address I should use? – Jay Jul 12 '18 at 18:26
  • Yes, that's what you should use to access the site. When creating your record, select "Yes" where it asks if it should be an "alias" record. Then, type part of the name of the ELB and you should see it show up. – ceejayoz Jul 12 '18 at 18:30
  • @ceejayoz Awesome! the way you let me know is perfectly working! By the way, I have one more question. I set up redirection codes inside the EC2 instance through SSH. The redirection codes redirect a url without www to a url with www. Is there anywhere to set it up in AWS? I used to set it up at 443 port host inside the EC2 instance. – Jay Jul 12 '18 at 21:26

1 Answers1

4

This is intended behavior. Beanstalk uses autoscaling to manage instances, and autoscaling will terminate instances if there is a problem.

If you want to to make sure the new instance that is started is configured in exactly the same way, you need to bootstrap all configurations. You use ebextensions to do this. https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html

You should never rely on manual configurations with Beanstalk. If there is something you need to do on an instance before it works, you need to write a script and include that in your ebextensions. Add the script to /tmp in the "files" section, and in the "commands" or "container commands" section, you can execute that script.

To include ebextensions, create a directory at the root level of your source code name ".ebextensions". Files in this directory should end with the ".config" extension, and are all yaml files. https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/ebextensions.html

Brandon
  • 408
  • 2
  • 11
  • So, forwarding http to https should be done in that way too? – Jay Jul 13 '18 at 19:38
  • That is correct. I won't comment a novel so here is another server fault question answering that. https://serverfault.com/questions/705678/elastic-beanstalk-force-https – Brandon Jul 14 '18 at 03:17