Search code examples
amazon-web-servicesamazon-ec2namecheap

Run EC2 Command from a different website hosting platform


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!


Solution

  • 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.