rahul7827 Posted December 22, 2022 Share Posted December 22, 2022 Hello Team This might not be useful for some, I am asking just for future readers and those who would like to save the server cost. I have many staging instances on aws ec2, which runs 24 X 7. While developers work in their working hours only. I am trying to create a bash script which should auto start/stop the instance at a specified time (will use cron). I tried this : aws ec2 stop-instances –instance-ids i-instanceId Giving me error like : aws command is invalid. Is aws cli missing ? What if the script stop the instance, will cron execute ? (Since instance is stop) If anyone have done this or have any idea, Please suggest. Thank you 1 Link to comment Share on other sites More sharing options...
0 Burak Posted December 22, 2022 Share Posted December 22, 2022 Yes you should have AWS CLI to run such commands. Beside this AWS provides SDKs for nearly every languages. Nowadays I have been improving my python knowledge so if I were you I can try that. You may check https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html Also AWS lambda functions may be another alternative to do such things on AWS. You can use python also as Lambda function scripts. If you want to use it with CLI, I know someone who does this every time: @Murat Eminoglu 3 Link to comment Share on other sites More sharing options...
0 Murat Eminoglu Posted December 22, 2022 Share Posted December 22, 2022 (edited) Quote Giving me error like : aws command is invalid. The above error is a syntax error. Note the spaces and hyphens. aws ec2 stop-instances --instance-ids i-0d35245664 https://docs.aws.amazon.com/cli/latest/reference/ec2/stop-instances.html By the way, it will not work if you add to cron directly as a binary name. You must give the full path of the binary. /usr/local/bin/aws A Cloudwatch rule can be created and stopped the instance when there is no load on the server. I can create something like that in my copious free time@Burak Boto is also a good tool, thanks for the suggestion. Edited December 22, 2022 by Murat Eminoglu 2 Link to comment Share on other sites More sharing options...
0 rahul7827 Posted December 22, 2022 Author Share Posted December 22, 2022 Thank you @Burak @Murat Eminoglu for your inputs. I will explore these in my weekend. I am a beginner in server related stuff, Thanks again for the roadmap. 1 Link to comment Share on other sites More sharing options...
0 Murat Eminoglu Posted December 23, 2022 Share Posted December 23, 2022 On 12/22/2022 at 1:08 PM, rahul7827 said: Thank you @Burak @Murat Eminoglu for your inputs. I will explore these in my weekend. I am a beginner in server related stuff, Thanks again for the roadmap. Let me know if you are still having issues. We can jump on a meeting for your issue. 🙂 1 Link to comment Share on other sites More sharing options...
0 rahul7827 Posted December 23, 2022 Author Share Posted December 23, 2022 2 hours ago, Murat Eminoglu said: Let me know if you are still having issues. We can jump on a meeting for your issue. 🙂 I appreciate you @Murat Eminoglu ❤️. Today i have stopped all my staging instances manually. This weekend I am occupied with some work so may be next week I could explore this more. Will let you know if i get stuck in any steps, or something may not clear to me. I will invite you for a meeting. 1 Link to comment Share on other sites More sharing options...
Question
rahul7827
Hello Team
This might not be useful for some, I am asking just for future readers and those who would like to save the server cost.
I have many staging instances on aws ec2, which runs 24 X 7. While developers work in their working hours only.
I am trying to create a bash script which should auto start/stop the instance at a specified time (will use cron).
I tried this :
aws ec2 stop-instances –instance-ids i-instanceId
Giving me error like : aws command is invalid.
Is aws cli missing ?
What if the script stop the instance, will cron execute ? (Since instance is stop)
If anyone have done this or have any idea, Please suggest.
Thank you
Link to comment
Share on other sites
Top Posters For This Question
3
2
1
Popular Days
Dec 22
4
Dec 23
2
Top Posters For This Question
rahul7827 3 posts
Murat Eminoglu 2 posts
Burak 1 post
Popular Days
Dec 22 2022
4 posts
Dec 23 2022
2 posts
Popular Posts
Burak
Yes you should have AWS CLI to run such commands. Beside this AWS provides SDKs for nearly every languages. Nowadays I have been improving my python knowledge so if I were you I can try that. You may
Murat Eminoglu
The above error is a syntax error. Note the spaces and hyphens. aws ec2 stop-instances --instance-ids i-0d35245664 https://docs.aws.amazon.com/cli/latest/reference/ec2/stop-instances.html B
rahul7827
Hello Team This might not be useful for some, I am asking just for future readers and those who would like to save the server cost. I have many staging instances on aws ec2, which runs 24 X
5 answers to this question
Recommended Posts