I have an spring boot application which is deployed on EC2 server which runs fine.
But after a certain amount of time, that task is killed automatically. I have tried to search for a solution but couldn't find any or may be I didn't exactly know what to search for. And hence the question on SO.
Is there anything that I can implement which will keep on pinging the instance which will keep it alive?
If yes, how do I implement it? And do I have to consider any other drawback for doing this?
Option 1. Elastic Container Service
Dockerize your app. Create a ECS cluster and publish you service. You Docker container will still run on a EC2 instance, but ECS will automatically maintain the number of app instances "alive". If you container gets killed (because the main Java process got killed), ECS will automatically restart the container.
Option 2. Elastic Beanstalk
Publish your Java app with Elastic Beanstalk and it will automatically monitor the "health" of you web app, and replace "unhealthy" EC2 instances automatically. It only works for web apps, since Elastic Beanstalk does HTTP(S) checks calling a URL you specify.
Option 3. Use Elastic Load Balancer with Auto Scaling Group
ELB can do HTTP(s) checks on you app. If an instance doesn't respond, it will be automatically replaced. You will require to create an AMI or cloud-init script to bootstrap new instances.
Related
So I have a website that was still being served even though I did not have an EC2 instance running on the us-east-1 dashboard.
I did have a load balancer running. When I terminated the load balancer the website is no longer being served.
My question is this...
Even though I had a load balancer there were no EC2 instances running. Where is the website being loaded from?
Doesn't an EC2 instance need to be running?
Not really, first of all, check if you have an Instance running in a different AWS region. If not, your site could be running in multiple other AWS Services like ECS, EKS or could be deployed Serverless (if the website is a Single Page Application: react, angular, vue).
So to answer your question: No, you don't need an EC2 instance running on AWS to host a website. And load balancers can be deployed in front of many other services that are not running on EC2.
Which is the best strategy to deploy .net Web application on AWS?
1. On EC2 instance where on single instance deploy both application and MS sql database.
2. On elastic beanstalk where the application is deployed on EC2 instance and database in RDS.
OR any other strategy.
What do you think?
This depends on your use case and budget. Running on the single instance is affordable but will be a single point of failure, and in case your instance goes down, your entire web app is gone. On top of that, any updates can be a nightmare. This is only ideal for development environments.
If you deploy via Beanstalk with external database, it will be expensive but it will be exponentially more fault tolerant. If your EC2 instance goes down, it will get replaced automatically (though you can achieve this even when using single instance. For prod, you must decouple your database instance from your environment, so you can run a database instance in Amazon RDS and configure your application to connect to it on launch. This enables you to connect multiple environments to a database, terminate an environment without affecting the database, and perform seamless updates with blue-green deployments.
Also, the 2nd option will be pretty convenient. All you have to do it give EB your application source bundle and it will do all the legwork. You can read more about EB and RDS setup here.
Is it possible to prevent Amazon Elastic Beanstalk from dropping an instance and creating a new one on its own, like for it to ask for approval first. I run a redis instance locally because elasticache is quite expensive and I dont want to have to keep installing and starting redis every time elastic beanstalk drops the instance and starts a new one. Is it possible to make sure it keeps a specific instance of EC2?
Elastic Beanstalk is meant for scaling web applications, so I'm not sure it's the right tool here.
If you are just looking to run a single instance with a manual install of redis at low cost, then launching an EC2 instance directly (rather than using Elastic Beanstalk) may be more appropriate?
You would of course then need to bear in mind that the EC2 would not automatically recover in the event of a problem, but it sounds like you don't have that currently anyway.
I created a elastic beanstalk environment and it created an EC2 instance. Then I thought I don't actually need this yet so I'll stop the EC2 instance, but then it seemed to start another one.
So my question is if I have an EB instance will I be charged by the hour for the underlying EC2 image all the time or only when the the service it provides is being access via the public elasticip. And if Im charged all the time is there a way to halt a elastic beanstalk application or only delete it or instantiate to a new environment.
The auto scaling feature of Elastic Beanstalk will automatically start another instance if a current instance continues to fail a health check. Stopping individual instances outside of the environment will cause failed health checks and trigger a new instance to be spun up.
You will be charged when the components within the environment are running as stated by Amazon here:
There is no additional charge for Elastic Beanstalk – you only pay for the underlying AWS resources (e.g. Amazon EC2, Amazon S3) that your application consumes.
You can completely stop an environment through the CLI. I gave this answer to a previous question about starting and stopping Elastic Beanstalk:
The EB command line interface has an eb stop command. Here is a little bit about what the command actually does:
The eb stop command deletes the AWS resources that are running your application (such as the ELB and the EC2 instances). It however leaves behind all of the application versions and configuration settings that you had deployed, so you can quickly get started again. Eb stop is ideal when you are developing and testing your application and don’t need the AWS resources running over night. You can get going again by simply running eb start.
I keep killing the default instance and it keeps coming back. Why?
This answer is based on the assumption that you are facing a specific issue I've seen several users stumbling over, but your question is a bit short on detail, so I might misinterpret your problem in fact.
Background
The AWS Toolkit for Visual Studio allows you to deploy applications to AWS Elastic Beanstalk, which is a Platform as a Service (PaaS) offering allowing you to quickly deploy and manage applications in the AWS cloud:
You simply upload your application, and Elastic Beanstalk
automatically handles the deployment details of capacity provisioning,
load balancing, auto-scaling, and application health monitoring.
You deploy an application to Elastic Beanstalk into an Environment comprised of an Elastic Load Balancer and resp. Auto Scaling policies, which together ensure your application will keep running even if the EC2 instance is having trouble servicing the requests for whatever reason (see Architectural Overview for an explanation and illustration how these components work together).
That is, your Amazon EC2 instances are managed by default, so you don't need to administrate the infrastructure yourself, but the specific characteristic of this AWS PaaS variation is that you still can do that:
At the same time, with Elastic Beanstalk, you retain full control over
the AWS resources powering your application and can access the
underlying resources at any time.
Now that's exactly what you unintentionally did by terminating the EC2 instance via a mechanism outside of the Elastic Beanstalk service, which the load balancer detects and, driven by those auto scaling policies, triggers the creation of a replacement instance.
Solution
Long story short, you need to terminate the Elastic Beanstalk environment instead, as illustrated in section Step 6: Clean Up within the AWS Elastic Beanstalk Walkthrough (there is a dedicated section for the Elastic Beanstalk service within the AWS Management Console).
You can also do this via Visual Studio, as explained in step 11 at the bottom of How to Deploy the PetBoard Application Using AWS Elastic Beanstalk:
To delete the deployment, expand the Elastic Beanstalk node in AWS
Explorer, and then right-click the subnode for the deployment. Click
Delete. AWS Elastic Beanstalk will begin the deletion process, which
may take a few minutes. If you specified an notification email address
the deployment, AWS Elastic Beanstalk will send status notifications
for the delete process to this address.