EC2 Start/Stop Function with HTTP Endpoint

Hi all,

I’ve an instance which has been using by one of my friend. Most of the times it’s turned off. Whenever my friend is needed to use it he has to ask me to turn it on again. I’m looking for Lambda (or something else) solution with HTTP endpoint, so he can trigger everywhere & everytime. Once I did a start/stop trigger in GCP with cloud function which gave me an endpoint.

So how can I do the same thing with lambda? Also is it reasonable price? Any tutorial or guide would be nice.

Thanks in advanced!

ps: This is for the GCP one

ps vol II: My friend has not any idea about cloud or aws. So he can’t use cli or console interface. That’s why I’m asking for the http endpoint. He needs to just click on the start and stop link.

Lambda with an aws user for your friend to use awscli or aws api. Or you can add an apigw to the lambda… but its not as pretty/easy as an iam user.

You can do the whole thing with the serverless framework. It’ll let you create a script to start the instance, and give it a role that allows it to do so. You’re best giving the role a condition that the instance has a specific tag (rather than allowing for all instances, or binding to the id) which makes it safe but flexible. You’ll want some sort of security on the endpoint - a simple pre-shared password would probably suffice, depends how bad it would be if someone gained access.

you can adopt this solution and add API gateway to trigger lambda.

don’t forget to add elastic IP to the instance.

Is stopping and starting through an http endpoint a must? The alternative is just to use the aws cli and issue stop or start commands, you can also use boto3 in python to do it.

Thanks but he doesn’t have any idea about cloud or aws, he is just a regular end user of an app on the instance. Because of this especially I asked about http trigger.

I’ll check this out. Thanks!

To be honest I haven’t thought about the security part, thanks for reminding me.

Just creat an IAM user and show them how to use the console. It’s as simple as login, navigate to ec2 click start. Folks trying to reinvent the wheel but there is an even simpler solution. This person will get use to it.

AWS already has an API that does this so seems the most obvious is just have them use that? You can create a limited IAM user that can only start that instance

I.e. awscli, boto3, the http API directly