AWS EC2 and Elastic Beanstalk - amazon-web-services

I am new to AWS and the question may seem very basic. However I need to see if I can find a solution to this.
I have created and launched an EC2 instance first and then created an Elastic Beanstalk instance with a sample application deployed on it. By default, the Elastic Beanstalk attaches "Default Environment" to this instance and I find no way to change this to my EC2 instance. How can I attach my EC2 instance (that I created earlier) to this Elastic Beanstalk instance? I am using Amazon Free Tier to learn.
Thanks a lot for your time and patience.

You cannot add an existing instance into an Elastic Beanstalk configuration.
Under the hood Elastic beanstalk uses Containers and a ton of configuration hooks, files, etc.
An instance is not the same and cannot even be guaranteed to be of matching types (perhaps the instance is CentOS and the Container runs on an ubuntu host).
It's simply not possible.

Related

AWS beanstalk EC2 instance within a VPC and without Load Balancing

I am creating the first betas of a project. I need a SpringBoot server connecting to MongoDBs in AWS.
MongoDB is already deployed as a replicaset in different EC2 instances. I was exploring AWS Beanstalk as environment to deploy the SpringBoot. However I am not yet ready to deploy a Load Balancer, because is costly.
I am looking for the way to deploy a Single-Instance Environment (https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features-managing-env-types.html?ref_=pe_395030_31184250_9#single-instance-environ) in a VPC (which would be shared with MongoDB).
Does AWS Beanstalk allows you to configure a EC2 instance within an VPC but without Load Balancer?
If not, I am planning to deploy an EC2 instance in the VPC myself without Beanstalk.
Other temporary solution would be accessing MongoDB over the internet, with the right security group rules, but i do not think is a good practice at all, so I am not considering it.
All Elastic Beanstalk environments are in a VPC, unless you have a really old AWS account that still supports EC2 classic. What you are looking for is the EB Single-Instance Environment type.

Elastic Beanstalk Instance keeps deleting Clamscan

I'm using clamscan to check content on my elastic beanstalk instance, however, I'm having an issue where AWS either moves the instance to another IP and then clam scan is suddenly uninstalled. Is there a good way to prevent this from happening?
Thanks.
Alex
If AWS is "moving the instance to a new IP" what is actually happening is that Elastic Beanstalk is deleting your instance and spinning up an entirely new instance. I assume you manually configured ClamAV on your EB EC2 instance via SSH, which is the wrong way to configure EB instances. You even get a warning on the screen when you SSH into the instance telling you not to make any changes to the server because they won't be persisted across EB instances.
You have to use the appropriate methods provided by Elastic Beanstalk to configure your instances so that Elastic Beanstalk knows how to configure new instances when it automatically creates them for you. The method for doing this is documented here.

Will existing EC2 instances be unaffected if I create an autoscalling solution with Elastic Beanstalk?

Maybe it is a simple question, but I want to be sure anyway.
We already have a simple architecture with one Amazon EC2 instance and are planning to scale to architecture with load balancing, multiple autoscaling EC2 instances, and separate RDS.
If I create such a configuration with Elastic Beanstalk, will the existing EC2 instance at the same account stay untouched and working?
Elastic Beanstalk will only modify the instances, autoscaling groups it creates as part of environment creation. If you already have instances running in your account they should not be affected by simply using Elastic Beanstalk to launch new instances.
Make sure you do not share those resources with your new environment. e.g. If you have an existing RDS and you access that RDS from your application on the newly launched instances by beanstalk, then it goes without saying that the state of the RDS can be modified by your application. Likewise if you use preexisting security groups then you are sharing state between your existing resources and your beanstalk environment and should be avoided.
But just launching a new beanstalk environment, deploying your application there will keep the existing instances in your account untouched.

Amazon Elastic Beanstalk fault recovery

I have a running Amazon Elastic Beanstalk environment.
Sometimes it runs into problems and the load balancer kills my ec2 instance and starts a new one. I don't know how to create an "AMI" or template so the load balancer starts a new ec2 instance which is exactly like the one that I have configured.
Also, I attached some EBS blocks and I want to be able to create a new instance with a EBS block attached.
How can I do that?
I read the documentation but I cannot find what I need, and I think this is a common scenario.
Thanks
You should use .ebextensions to configure your Elastic Beanstalk instances. http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers.html
These configurations and dependencies are handled on instance start-up.

Customizing an Elastic Beanstalk AMI

I need to use on Elastic Beanstalk a Java application written for Glassfish server.
Beacuse of Amazon doesn't let me choose an AMI with Glassfish, I choosed one with Tomcat and i modified my application to work properly on Tomcat.
Now, I've seen I also needed to use a Sun JDK, while by default Elastic Beanstalk AMI comes with openjdk. I googled a lot, finding some (not so many resources) interesting posts like this answer on StackOverflow
What I can't understand is this part of the answer:
Create your custom AMI from a running instance of Amazon's beanstalk
AMI that you manually launch from EC2, NOT one that was launched from
starting your application through beanstalk.
So, my question is: does anyone how to use a custom AMI with Glassfish on Elastic Beanstalk?
If it's not possible, can someone explain me how to create the custom AMI?
Thanks,
Andrea
That answer just means "Don't start a beanstalk application and cut an AMI directly from one of those instances. Instead, launch an instance based on the beanstalk AMIs (which are available in the public AMI listing)." I.e., use one of these; note there are 84 of them:
Cut your own private AMI when you're done configuring that instance, and specify it in your beanstalk environment.
I personally found the selected answer confusing for me to follow, maybe because I am still climbing up the AWS learning curve. Maybe this answer will help other newbies. Having just figured out how to successfully launch an Elastic Beanstalk instance with my own custom AMI, what I believe this quote is saying, is to do the following totally non-obvious steps which just worked for me:
Go to the EC2 services (not Elastic Beanstalk services) and launch an instance based on the Elastic Beanstalk AMI that you would like to use as a starting point for your custom AMI. You will throw this away in a minute.
Select the instance and choose "Create Image / EBS AMI". Once created, you can delete the temporary EC2 instance you created. It's only purpose was to create the custom AMI.
Now go to Elastic Beanstalk services and edit your configuration to reference your custom AMI.
#Danger It would speed up the scaling up process.
I'm using a docker app on EB but "docker pull" from Docker Hub is so slow so when all instances are unhealthy my site would be down in 15-30 minutes. Create a customize AMI and pull a base Docker image will save time.