Skip to content

niftycode/aws-ec2-start-stop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 

Repository files navigation

aws-ec2-start-stop

About

Start your Amazon Web Services EC2 Instance with Python 3:

# Start EC2 instance
python3 start_stop_ec2.py -u

# Stop EC2 instance
python3 start_stop_ec2.py -d

Requirements

Python Modules

If you never used Amazon Web Services with Python before, you have to install two additional modules:

pip install boto3 botocore

or

pip3 install boto3 botocore

EC2 Instance ID

Enter your EC2 ID in a file with the name instance_id.txt and save this file in your Users/home folder:

/Users/[username]/instance_id.txt // Windows
/Users/[username]/instance_id.txt // macOS
/home/[username]/instance_id.txt // Linux

Check your EC2 dashboard for the available IDs.

AWS Credentials

Save your AWS Credentials in your home/users folder:

Linux:

/home/[username]/.aws

macOS:

/Users/[username]/.aws

Windows:

/Users/[username]/.aws

For more information about the content of the .aws folder check the AWS documentation: Configuration and Credential Files.

Instead of creating the .aws folder manually you can use the AWS Command Line Interface:

After you've installed the AWS CLI open the PowerShell (or the Command Prompt) in Windows. In UNIX-like systems open a Shell. Then run the following command:

aws configure

Enter

  • your AWS Access Key ID and
  • your AWS Secret Access Key.
  • As default region name enter your Availability Zone (AZ) and
  • use "json" as default output format.

Changelog

  • 30/07/2017 - Receiving public IPv4 address
  • 10/06/2018 - Added more print statements and updated read_credentials(). The path to your "instance_id.txt" is no longer hard coded.
  • 29/11/2018 - Updated parse_arguments() and added more comments

References

About

Start or Stop an AWS EC2 Instance with Python

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages