{"id":25609532,"url":"https://github.com/dave-carter-uk/aws-automation","last_synced_at":"2026-06-15T01:37:37.111Z","repository":{"id":277573632,"uuid":"932839347","full_name":"dave-carter-uk/AWS-Automation","owner":"dave-carter-uk","description":"Automate start / stop of instances and applications","archived":false,"fork":false,"pushed_at":"2025-02-16T21:10:45.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-21T21:39:46.710Z","etag":null,"topics":["automation","aws","ec2-instance","maintenance-window","runbook","sap","start","stop"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dave-carter-uk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2025-02-14T16:05:21.000Z","updated_at":"2025-02-16T21:10:48.000Z","dependencies_parsed_at":"2025-02-14T17:47:36.573Z","dependency_job_id":null,"html_url":"https://github.com/dave-carter-uk/AWS-Automation","commit_stats":null,"previous_names":["dave-carter-uk/aws-automation"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dave-carter-uk%2FAWS-Automation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dave-carter-uk%2FAWS-Automation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dave-carter-uk%2FAWS-Automation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dave-carter-uk%2FAWS-Automation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dave-carter-uk","download_url":"https://codeload.github.com/dave-carter-uk/AWS-Automation/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240091007,"owners_count":19746477,"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":["automation","aws","ec2-instance","maintenance-window","runbook","sap","start","stop"],"created_at":"2025-02-21T21:40:07.285Z","updated_at":"2026-05-05T17:30:17.785Z","avatar_url":"https://github.com/dave-carter-uk.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# AWS EC2 Start Stop Automation\n## Overview\nThe objective of this framework is to provide an Automation process to start and start EC2 instances and instance applications on an automated schedule. Primarily to reduce infrastructure costs on out of hours compute.\u003cbr/\u003e\nThe framework provides 3 SSM Runbooks:\n* **Start-AutoGroup** – Starts VM’s and applications in groups\n* **Stop-AutoGroup** – Stops VM’s and applications in groups\n* **Run-AutoCommand** – Called by the start and stop Runbooks to call a command on the VM to facilitate the start or stop of applications on that host\n\nEC2 Instances are tagged as follows:\n* AutoGroup \u003cStringList\u003e - Group this instance belongs to\n* AutoCommand \u003cString\u003e - An optional host command that is called with either parameter ‘start’ or ‘stop’ during execution of Runbook\n\nThis framework was designed to automated the start and stop of SAP hosts and instances but can be adapted to none SAP systems\n\n## Tag EC2 Instances\nIn this example the following test EC2 instances have been created:\n![image](https://github.com/user-attachments/assets/54fa9671-a441-42cf-87a7-36ec4291b2d7)\n\nThe instances are given the following tags:\n|Server|AutoGroup|AutoCommand|\n|------|---------|-----------|\n|MYDBSERVER|DBGroup|/usr/sap/awscontrol.sh|\n|MYAPPSERVER1|APPGroup||\n|MYAPPSERVER2|APPGroup|C:\\usr\\sap\\awscontrol.ps1|\n\n*In this example MYAPPSERVER1 doesn't have any apps that need starting as part of the process so the AutoCommand tag is not specified*\n\nFor Example:\n\n![image](https://github.com/user-attachments/assets/cbf17110-3ed7-4c2d-b0e8-0ab15874b528)\n\n## VM Prioritisation\nVM's are grouped by tag AutoGroup we provide the start and stop group order when calling the Start/Stop-AutoGroup runbook.\n\n**Example 1**\u003cbr/\u003e\nA three tier BW SAP system can be defined as follows:\n\n|VM|Usage|AutoGroup|\n|--|-----|---------|\n|BWDBHOST|BW Database Host|DBGroup|\n|BWASCSHOST|BW ASCS Host|DBGroup|\n|BWAPPHOST1|BW Instance|APPGroup1|\n|BWAPPHOST2|BW Instance|APPGroup1|\n|BWAPPHOST3|BW Instance|AppGroup1|\n\nWe can use Start-AutoGroup with groups: DBGroup,APPGroup1 to start the VM's in order. The DB and ASCS hosts are started first simultaneously followed by the 3 app instances\n\nWe use Stop-AutoGroup with groups: APPGroup1, DBGroup to stop the VM's in order. The 3 app instances are stopped first simultaneously followed by the DB and ASCS instances\n\n\n**Example 2**\u003cbr/\u003e\nExpanding on Example 1, a Business Objects and Business Objects Data Services systems are added to the landscape, these system are dependent on the BW system\nWe have also added an AutoCommand to be called as part of the start or stop process\n\n|VM|Usage|AutoGroup|AutoCommand|\n|--|-----|---------|-----------|\n|BWDBHOST|BW Database Host|DBGroup|/usr/sap/azcontrol.sh|\n|BODBHOST|BO Database Host|DBGroup|C:\\usr\\sap\\azcontrol.ps1|\n|DSDBHOST|DS Database Host|DBGroup|C:\\usr\\sap\\azcontrol.ps1|\n|BWASCSHOST|BW ASCS Host|DBGroup|C:\\usr\\sap\\azcontrol.ps1|\n|BWDAPPHOST1|BW Instance Host|APPGroup1|C:\\usr\\sap\\azcontrol.ps1|\n|BWDAPPHOST2|BW Instance Host|APPGroup1|C:\\usr\\sap\\azcontrol.ps1|\n|BWDAPPHOST2|BW Instance Host|APPGroup1|C:\\usr\\sap\\azcontrol.ps1|\n|BOAPPHOST|BO SIA+WEB|APPGroup2||\n|DSAPPHOST|DS SIA+WEB|APPGroup2||\n\n*No AutoCommand is set for BOAPPHOST and DSAPPHOST because the BO services are configured to auto start*\n\nStart-AutoGroup: DBGroup,APPGroup1,APPGroup2\n\nStop-AutoGroup: APPGroup2, APPGroup1, DBGroup\n\n## AutoCommand\nRunbook calls the command identified by tag:AutoCommand and provides parameter start,stop or check.\n\nThe command can be any script to be ran on the host VM to perform the required action.\n\nScripts are ran as NT/SYSTEM user for Windows and root user for Linux.\n\n\n**Example:**\n- Windows\tTag:autoCommand = C:\\azscripts\\azcontrol.ps1\n- Linux\t\tTag:autoCommand = /azscripts/azcontrol.sh\n\nRunbook will add parameter start, stop or check.\n\nhttps://github.com/dave-carter-uk/Apps-Stop-Start-Control provides some example scripts\n\n\n## Create Automation Runbooks\nUse AWS Systems Manager to create the 3 Automation Runbooks\n![image](https://github.com/user-attachments/assets/a677dd5a-0c81-438f-be95-d31826a26430)\n\n## Test Runbook\nIn this example run the Stop-AutoGroup Runbook to test the stopping of the EC2 instances\n![image](https://github.com/user-attachments/assets/6e2391d6-30e0-44f2-85fe-bb3a7ea50c06)\nWe want to stop the APPGroup servers first and then the DBGroup server.\n\nWe are not including app processing because the application control script are not setup on each server yet\n\nDuring execution if we look at EC2 instances we can see that the two app servers are stopping first\n![image](https://github.com/user-attachments/assets/1527984d-631e-4ba9-91bc-44a92187a934)\n\nAfter the two app servers are stopped the database instance then stops:\n![image](https://github.com/user-attachments/assets/0e3e10b9-e975-4145-b5c3-2e21a640081e)\n\nRun the Start-AutoGroup Runbook to start up the EC2 instances\n\n## Setup Application Control Scripts\nThe start and stop Runbooks can call a local host command specified by tag:AutoCommand with parameter either ‘start’ or ‘stop’ to control the start and stop of applications and services on that VM.\n\nThe command is called either as a PowerShell script or as a shell script depending on platform type\n\nExample host application control scripts can be found at https://github.com/dave-carter-uk/Apps-Stop-Start-Control\n\nFor this example we are just using simple scripts that don’t do anything:\n\n**MYDBSERVER (Linux)**\u003cbr/\u003e\n![image](https://github.com/user-attachments/assets/faf2228c-6918-45da-b285-0498372ca931)\n\n**MYAPPSERVER1/2 (Windows)**\u003cbr/\u003e\n![image](https://github.com/user-attachments/assets/8492bb14-f28c-42f0-ae07-455b9670ad79)\n\nAs the EC2 instances are currently running we can run the Start-AutoGroup Runbook with the option to just run the app startup\n![image](https://github.com/user-attachments/assets/e03e869b-46db-4afe-8489-70af39c91abb)\n\nAfter the Runbook completes drill down into the execution steps to see the output from the RunShellScript and RunPowerShellScript steps:\n![image](https://github.com/user-attachments/assets/9df3cfa2-f9e1-4dd3-b9b7-036e1178286a)\n\nSo far we are running Runbooks to start and stop EC2 instances and applications by groups manually, next step is to get the process to run on a schedule.\n\nThere are a number of ways of scheduling a Runbook to run at a specific time in the Examples below SSM Maintenance Window is used\n\n## Create Maintenance Role\nFirst create a role to be used by the Maintenance Window\u003cbr/\u003e\nIAM -\u003e Roles -\u003e Create Role\u003cbr/\u003e\n**Trusted Identity Type**: AWS Service\u003cbr/\u003e\n**Use Case**: Systems Manager\u003cbr/\u003e\nAdd Permissions:\u003cbr/\u003e\n* AmazonEC2FullAccess\u003cbr/\u003e\n*\tAmazonSSMAutomationRole\u003cbr/\u003e\n* AmazonSSMMaintenanceWindowRole\u003cbr/\u003e\n\nProvide Role a name and create. We will use this role later in our Maintenance Window\n\n## Create Mainenance Window\nSSM -\u003e Maintenance Window -\u003e Create Maintenance Window\n\n**Name:** StartNoneProdSystems (example)\u003cbr/\u003e\n**CRON/Rate expression:** cron(0 8 ? * 2-6 *)\u003cbr/\u003e\n*The CRON definition specifies to run this Maintenance Window at 8am on Days Monday - Friday*.\u003cbr/\u003e\n\nAdd a Task to the new Maintenance Window of type Register Automation Task\u003cbr/\u003e\nProvide a task name\u003cbr/\u003e\n**Add document:** Start-AutoGroup\u003cbr/\u003e\n**Use Default version**\u003cbr/\u003e\n**Targets:** not required\u003cbr/\u003e\nProvide Runbook parameters:\u003cbr/\u003e\n![image](https://github.com/user-attachments/assets/dcd2b58b-97f7-4af6-8a29-882655b48ba5)\n\nThis task will run the Start-AutoGroup runbook at 8am (Mon-Fri) and start both VM Instances and Apps on our select Instances.\u003cbr/\u003e\nInstances tagged with AutoGroup:DBGroup will be processed first, followed by Instances tagged with AutoGroup:APPGroup.\n\nProvide our new role\n![image](https://github.com/user-attachments/assets/16dcb5a7-40ce-4805-b066-a40a322d60f1)\n\nSave and wait for the Maintenance Window to run\n\n## Evaluate Maintenance Window\nAfter the Maintenance Window has completed we can drill into the task details to see the steps ran and their status:\n![image](https://github.com/user-attachments/assets/1e1c1565-7669-4c50-a7e8-30e70442680c)\n\nStep name: ProcessVMandApp was ran, steps: ProcessVMOnly and ProcessAppOnly where not ran – because we defined this task to include both VM’s and Apps\n\nTwo StartVMGroup and StartAppGroup steps where ran because we defined this task for 2 AutoGroup’s\n\nDrill down further into each processed step to view the output, for example from the AutoCommand ran on the DBGroup server:\n![image](https://github.com/user-attachments/assets/eed72d2f-371d-4211-bd08-6a982c4640ec)\n\nWe can now set up a similar Maintenance Window and Task to stop our applications and instances at a given schedule.\n\nUsing a Stop and Start schedule we can elect to run our Instances only between a specified number of hours on required days.\n\n\n\n\n\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdave-carter-uk%2Faws-automation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdave-carter-uk%2Faws-automation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdave-carter-uk%2Faws-automation/lists"}