Run EC2 Command from a different website hosting platform - amazon-web-services

I'm new to EC2 and most website hosting stuff in general. Throwing myself in the deep end, I guess.
I have a free micro instance of EC2 running and I git pulled a little program I have. After some setup stuff that program runs perfectly.
I also have a website hosted by namecheap. It isn't much but whatever, it's there.
I want to have a button on my website that will run the program on my EC2 instance. It looks like I need some kind of AWS Lambda function, or their gateway api, or something, but as I said, new to this stuff. Confused. Where should I start? I saw something about hosting through AWS as well, but it looks like that would mean a lot more management needs to be done by me that namecheap does for me.
Any thoughts are appreciated. Thanks!

As I see it, you have 2 viable options:
First, running a simple server on the instance and make REST calls to it. Second, connect with SSH or AWS SSM to the instance and run the command directly.
Depending on the situation, you need to decide which option is better for you.
For the first option, I would recommend you try running a simple server (like flask, or whatever) and send POST call to it using the button on your site.
When handling the call in the server, run the application locally.
For the second option, it can be trickier but essentially you would want to SSH to EC2 instances via AWS Lambda.
Nevertheless, you will need to configure the security group for that instance and open some ports to be able to connect remotely.
SSH(22)
HTTPS/HTTP(80/443)
Probably there are more ways to do it. so feel free to investigate more.

Related

If my own server is down, my aws container needs to go up. Is it possible?

I have a web app that is deployed on my server. But, I want to be able to know when the server is down. I know there are many tools on the internet that I can use to monitor. So, I want to know if is possible, if my server is down, another container located on AWS container be automatically set to go up. Or, vice versa.
Thank you.
Well, yes.
The most straightforward solution is to have a lambda checking /health of your own server every minute let's say. If you need to check more often, you'd have to either start a micro instance of ec2 or fargate or loop in lambda which is not ideal. Then if your server is down, you simply start a container using aws-sdk (boto3 in python for example, or aws-sdk in javascript). Now, the other way around could be also based on lambda, but the trick is, you need to expose some mechanism which starts your own server. But if you use for example fargate service, your task will be recreated based on your policies, so no need to start external server

How to add some new code to an existing EC2 instance

Bear with me, what I am requesting may be impossible. I am a AWS noob.
So I am going to describe to you the situation I am in...
I am doing a freelance gig and was essentially handed the keys to AWS. That is, I was handed the root user login credentials for the AWS account that powers this website.
Now there are 3 EC2 instances. One of the instances is a linux box that, from what I am being told, is running a Django Python backend.
My new "service" if you will must exist within this instance.
How do I introduce new source code into this instance? Is there a way to pull down the existing source code that lives within it?
I am not be helped by any existing/previous developers so I am kind of just handed the AWS credentials and have no idea where to start.
Is this even possible. That is, is it possible to pull the source code from an EC2 instance and/or modify the code? How do I do this?
EC2 instances are just virtual machines. So you can use SSH/SCP/SFTP files to and from. You can use the AWS CLI tools to copy stuff from S3. Dealers choice...
Now to get into this instance... If you look in the web console you can find its IP(s), what the security groups (firewall rules), and the key pair name. Hopefully they gave you the keys. You need these to SSH in.
You'll also want to check to make sure there's a security group applied that has SSH open. Hopefully only to your IP :)
If you don't have the keys you'll have to create an AMI image of the instance so you can create a new one with a key pair you do have.
Amazon has a set of tools for you in Amazon CodeSuite.
The tool used for "deploying" the code is Amazon CodeDeploy. By using this service you install an agent onto your host, then when triggered it will pull down an artifact of a code base and install it matching hosts. You can even specify additional commands through the hook system.
But you also want to trigger this to happen, maybe even automatically? CodeDeploy can be orchestrated using the CodePipeline tool.

Capistrano and Auto-Scaling AWS

We're trying to figure out the best way to deploy to an auto-scaling AWS setup using Capistrano, and stuck on the best way to ensure new servers automatically get the latest code, without having to rely on AMIs.
Any ideas?
Using User Data, you can have your EC2 instances pull the latest code each time a new instance is launched.
More info on user data here: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html
tldr: user data is pretty much a shell script thats executed when your ec2 instance launches. you can get it to pull the latest code and run it
#Moe's answer (or something like it is the right one). But just as another thought, you could write some Ruby which queries AWS on deploy to fetch the list of servers to which Capistrano will deploy. The issue with this approach is that you will have to manually deploy to all servers every time auto-scaling adds a server, which kind of defeats the purpose.

Create Basic Landing Page to allow a user to start/stop an AWS Windows EC2 instance

I would like to create a landing page using Beanstalk/EC2 (beanstalk for PHP or .NET) that is a simple HTML landing page with a Start and Stop button, allowing a non-technical person to spin start/stop a specific AWS EC2 instance (Windows Server 2012) in the same VPC.
Is it possible for me to start/stop the separate EC2 Windows instance from my beanstalk web app?
Would I need to setup anything specifically on the EC2 Windows instance to enable this to work?
Would I need to setup anything special on the Beanstalk instance to enable what I've described to work?
Thanks again for any pointers anyone can provide.
Is it possible for me to start/stop the separate EC2 Windows instance from my beanstalk web app? Yes
Would I need to setup anything specifically on the EC2 Windows instance to enable this to work? No
Would I need to setup anything special on the Beanstalk instance to enable what I've described to work? No
So how do you achieve this?
1. If you wanted a frontend GUI, you could use nodeJS. This is a good resource for that: https://aws.amazon.com/sdk-for-browser/
2. Your backend will have AWS CLI installed and handle all the API calls. This is a good resource for that: https://aws.amazon.com/cli/
3. You can always automate a pipeline structure using Jenkins and the many AWS plugins. So say you want to give the user parameters to select from without building anything fancy. Jenkins will do this for you with the AWS plugin and the parameter plugin.
So there are many ways to handle this. To decide which works best for you make sure you have the business requirements well defined and then maybe setup an agile like structure were you have an epic and user stories.
Hope that helped. Happy hacking!!!

Is s3cmd a safe option for sync EC2 instances?

I have the following problem: we are working on a project on AWS which will use autoscaling, so the EC2 instances will start and die very often. Freeze images, update the launch configurations, auto scalling groups, alarms, etc, takes a while and several things can go wrong.
I just want the new instances to sync the most recent code, so I was just thinking about fetching it from S3 using s3cmd once the instance finishes booting and manually updating it everytime we have new codes to be uploaded. So my doubts are:
Is it too much risky to store the code on s3? How secure are the files in there? Using the s3cmd encryption password it is unlikely someone will be able do decrypt them?
What other ooptions would be good for this? I was thinking about rsync, but then I think I would need to store the private key for the servers inside them, which I don't think its a good idea.
Thanks for any advices
You might be a candidate for Elastic Beanstalk - using a plain vanilla AMI.
Then package your application, use AWS's ebextensions tool to customize the instance when it is spun up. ebextensions will allow you to do anything you like to the image, in place, as it is deploying. change .htaccess, erase a file, place a cron job, whatever.
When you have code updates, package them, upload and do a rolling update.
All instances will use your latest code, including auto-scaled ones.
The key concept here is to never have your real data in the instance, where it might go away if an instance dies or is shut down.
Elastic Beanstalk will allow you to set up the load balancing, auto-scaling, monitoring, etc.