{"id":22477189,"url":"https://github.com/base2services/stop-start","last_synced_at":"2025-03-27T17:44:16.724Z","repository":{"id":145345515,"uuid":"59536794","full_name":"base2Services/stop-start","owner":"base2Services","description":null,"archived":false,"fork":false,"pushed_at":"2016-06-16T08:55:43.000Z","size":1076,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-02-01T20:46:17.758Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/base2Services.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-05-24T03:17:06.000Z","updated_at":"2016-06-16T02:05:28.000Z","dependencies_parsed_at":"2024-04-19T08:15:49.935Z","dependency_job_id":null,"html_url":"https://github.com/base2Services/stop-start","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/base2Services%2Fstop-start","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/base2Services%2Fstop-start/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/base2Services%2Fstop-start/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/base2Services%2Fstop-start/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/base2Services","download_url":"https://codeload.github.com/base2Services/stop-start/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245897308,"owners_count":20690455,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-06T14:09:47.758Z","updated_at":"2025-03-27T17:44:16.695Z","avatar_url":"https://github.com/base2Services.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Stop-Start - scheduling stopping and starting of AWS EC2 instances\n==================================================================\n\nOVERVIEW\n--------\n\nThis project enables the automated stopping and starting of instances in an AWS account, primarily according to the environment type specified. Motivtion for its creation was generated from the desire to automate the shut down and start up of non production accounts in order to save costs, typically it would be configured to ensure that ec2 instances in an acocunt were only running during business hours. It will handle all instaces for the specified environment in an AWS account whether they are in an auto scaling group or standing on their own. For the ASGs their size details are set and cleared according to whether a start or stop command is issued, data is kept about their sizing details in a DynamoDB database.\n\nThe AWS Serverless framework is used for deployment, more details can be found here: http://docs.serverless.com/v0.5.0/docs\n\nDEPLOYING\n---------\n\nPlease ensure that Node (v5.10.1+) and NPM (v3.8.6+) are installed. Earlier versions may work but have not been tested.\n\n### Getting Started - a typical workflow\n\nFirst the Serverless environment will need to be installed:\n\n`npm install serverless -g`\n\nVerify a successful install by running `serverless` or `sls` for short to display the list of commands, the version should be v0.5.3 or later.\n\nThen clone the repo somewhere and change directory into the stop-start folder:\n\n```\ngit clone https://github.com/base2Services/start-stop\ncd stop-start\n```\n\nSet up the Serverless project (see http://docs.serverless.com/docs/project-init for more details):\n\n`serverless project init`\n\n#### A note on stages\n\nWhen initialising the project - Serverless, with your input, will set up what is called a stage for you. Stages can be used for various things, typically they are used to separate production accounts from dev/test/uat acocunts. Each stage maps to a separate AWS account and these need to be configured in the user's profile under ~/.aws/. Here they can be used to separate various accounts if so desired - this is the way to manage multiple AWS accounts. When ready run the relevant Serverless deploy command (see below), you will then be prompted for the stage to use.\n\nConfigure Cloudformation resources: a basic set of resources exists to allow the functon to run against the instances in EC2, located in the s-resources-cf.json file. These can be reconfigured if need be prior to deploying but it is not mandatory to do so and can be left as-is. When initialising Serverless will automatically deploy these resources for you. Any additional resoureces that are to be included can also go into this file.\n\nIf changes are made deploy the configured resources:\n\n`sls resources deploy`\n\nThen deploy the function:\n\n`sls function deploy`\n\nConfigure the desired Cloudwatch events - one or more are needed. These are in placed in the functions/stop-start/s-function.json file and are of the following format:\n\n```\n{\n  \"name\": \"stop-prod\",\n  \"type\": \"schedule\",\n  \"config\": {\n    \"enabled\": true,\n    \"description\": \"Event to invoke the function to stop all instances each week night\",\n    \"schedule\": \"cron(0 18 ? * MON-FRI *)\",\n    \"input\": {\n      \"stopStart\": \"stop\",\n      \"reportOnly\": false,\n      \"environment\": \"prod\",\n      \"tableName\": \"stop-start\",\n      \"region\": \"ap-southeast-2\"\n    }s\n  }\n}\n```\n\nGenerally these will need to be configured in pairs: one to stop the instances and one to start the instances. Add these blocks of JSON accordingly into the `\"events\": [ ... ]` array separated by commas. Note the following parameters that will need to be configured:\n\n* `name`: choose whatever you want here\n* `type`: leave this as-is\n* `config`: details about the event\n  * `enabled`: whether or not the event is to run\n  * `schedule`: can use either the rate(...) format or a valid cron expression, note this is UTC time so will need to be adjusted depending on what timezone you are in\n  * `input`: the parameters that get passed to the function\n    * `stopStart`: either stop or start depending on which operation is to be performed\n    * `reportOnly`: generates a list of instances that exist for the environment but will not start/stop them or record their details\n    * `environment`: the tag name of the environment that the ASGs/instances belong to, this needs to be set up as tags against these resources prior to deployment of said resources\n    * `tableName`: the DynamoDB table name to use, the function will set up a table if one does not exist\n    * `region`: the region that the function is to target, if more than one region is needed then a function per region will need to be deployed\n\n#### IMPORTANT - the first operation type to be performed in an environment needs to be a stop operation, this ensures that the database records all sizing information prior to making modifications to the ASGs. Do not attempt to perform a start operation first.\n\nThen deploy the events (final step):\n\n`sls event deploy`\n\nNote one can also deploy the function and events together by running the interactive Serverless console:\n\n`sls dash deploy`\n\nOne can also add additional stages by the command:\n\n`sls stage create`\n\nNote however that whenever a different stage is being worked on the Cloudwatch events will need to be reconfigured to suit, there will be an update that caters for this limitation in the future...\n\nAUTHOR\n------\n\nMichael Kempster - initial work - Base2Services\n\nm.kempster@base2services.com\n\nLICENSE\n-------\n\nMIT License\n\nCopyright (c) 2016 Base2Services Pty Ltd\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbase2services%2Fstop-start","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbase2services%2Fstop-start","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbase2services%2Fstop-start/lists"}