web UI and API for quickly starting and stopping AWS environments
aws-power-toggle groups your instances by environments (via instance tag described below), then allows you power toggle them with a single action. This can be very useful when you have to deal with a ton of developers who have multiple environments and need to use them sporadically. While you could leave them on all the time, it may result in your boss(es) freaking out about the bill :) Just hand this web UI and/or API to the devs and let them decide when to start/stop the environment(s). Don't forget to check up on them to make sure they are actually turning them down when not in use :)
The backend polls the aws API periodically (or on demand through web ui). In order for your instances to show up the following
instance tags
are required (all other instances are ignored):
power-toggle-enabled
set totrue
Environment
set to non-empty value
Both the tags listed above are configurable via the config file (see power-toggle-config.yaml).
Instances are grouped by the value of Environment
tag. Please note that tag values are *case-sensitive.
the backend requires an API key to successfully poll AWS (shock). Once you have obtained it, set the following environment variables:AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY
Once you have tagged your AWS instances appropriately (hopefully with terraform or the aws cli) then your ready to deploy. Ofcourse, this is done quickest via docker:
docker run -d --name "aws-power-toggle" \
-p 8080:8080 \
-e "AWS_ACCESS_KEY_ID=<your_key_id>" \
-e "AWS_SECRET_ACCESS_KEY=<your_secret_key>" \
gbolo/aws-power-toggle:3.0
Then open your browser to: http://127.0.0.1:8080
Requirements:
go
v1.8+ (withGOPATH
set)npm
v3.5+make
docker
(optional)
follow these steps:
# clone source
mkdir -p ${GOPATH}/src/github.com/gbolo/aws-power-toggle
git clone https://github.com/gbolo/aws-power-toggle.git ${GOPATH}/src/github.com/gbolo/aws-power-toggle
cd ${GOPATH}/src/github.com/gbolo/aws-power-toggle
# make your changes to source code or config then export your aws api key
export AWS_ACCESS_KEY_ID=<your_key_id>
export AWS_SECRET_ACCESS_KEY=<your_secret_key>
# build it (builds both frontend and backend)
make all
# run it
./bin/aws-power-toggle -config testdata/sampleconfig/power-toggle-config.yaml
# do a test API call
curl -v 127.0.0.1:8080/api/v1/env/summary
Optional
If you prefer to use docker
for building (which I recommend), you can build the docker image with:
make docker
For further details on an API endpoint (including example responses), click on the endpoint's name.
-
EnvAllSummary:
GET /api/v1/env/summary
retrieves a summary of all known environments -
EnvSummary:
GET /api/v1/env/{env-id}/summary
retrieves a summary of a single environment -
EnvAllDetails:
GET /api/v1/env/details
retrieves full details of all known environments (including list of instances) -
EnvDetails:
GET /api/v1/env/{env-id}/details
retrieves full details of a single environment (including list of instances) -
StopEnv:
POST /api/v1/env/{env-id}/stop
triggers a shutdown of an environment -
StartEnv:
POST /api/v1/env/{env-id}/start
triggers a startup of an environment -
StopInstance:
POST /api/v1/instance/{instance-id}/stop
triggers a shutdown of a single instance -
StartInstance:
POST /api/v1/instance/{instance-id}/start
triggers a startup of a single instance -
Refresh:
POST /api/v1/refresh
forces backend to refresh it's cache -
Version:
GET /api/v1/version
returns backend version information
Need to finish these...
- Config:
GET /api/v1/config
returns relevant backend configuration
It may be useful to mock the aws API when doing development work against the API (like for web ui development). This means you don't need an aws api key. To enable this feature:
# modify aws.go and set this constant to true:
MOCK_ENABLED = true
# set fake AWS API keys
export AWS_ACCESS_KEY_ID=DOESNT_MATTER
export AWS_SECRET_ACCESS_KEY=DOESNT_MATTER
# build then start
make all
./bin/aws-power-toggle -config testdata/sampleconfig/power-toggle-config.yaml
if you would like to add/remove/change any of the fake inventory, then modify this file:
testdata/mock/mock_env_cachedTable.json