{"id":486,"date":"2021-09-17T10:51:41","date_gmt":"2021-09-17T15:51:41","guid":{"rendered":"https:\/\/www.highordersolutions.com\/?post_type=project&#038;p=486"},"modified":"2022-12-22T15:32:22","modified_gmt":"2022-12-22T21:32:22","slug":"use-case-how-to-automatically-shut-down-ec2-instances-outside-business-hours","status":"publish","type":"project","link":"https:\/\/www.highordersolutions.com\/index.php\/project\/use-case-how-to-automatically-shut-down-ec2-instances-outside-business-hours\/","title":{"rendered":"Use Case: How to automatically shut down EC2 instances outside business hours"},"content":{"rendered":"<p>[et_pb_section fb_built=&#8221;1&#8243; _builder_version=&#8221;4.16&#8243; _module_preset=&#8221;default&#8221; background_enable_color=&#8221;off&#8221; use_background_color_gradient=&#8221;on&#8221; background_color_gradient_stops=&#8221;#2e3857 0%|#212529 100%&#8221; background_color_gradient_start=&#8221;#2e3857&#8243; background_color_gradient_end=&#8221;#212529&#8243; min_height=&#8221;382px&#8221; custom_padding=&#8221;||2px|||&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_row column_structure=&#8221;1_2,1_2&#8243; _builder_version=&#8221;4.16&#8243; _module_preset=&#8221;default&#8221; background_color=&#8221;#FFFFFF&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_column type=&#8221;1_2&#8243; _builder_version=&#8221;4.16&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_text _builder_version=&#8221;4.16&#8243; _module_preset=&#8221;default&#8221; header_font=&#8221;|800|||||||&#8221; header_letter_spacing=&#8221;4px&#8221; header_2_line_height=&#8221;1.6em&#8221; custom_padding=&#8221;10px|10px|37px|10px|false|false&#8221; header_text_shadow_style=&#8221;preset1&#8243; header_text_shadow_blur_strength=&#8221;0.12em&#8221; global_colors_info=&#8221;{}&#8221;]<\/p>\n<h1>SOLUTION of the MONTH:<\/h1>\n<h2>How to automatically shut down EC2 instances outside business hours<\/h2>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;4.19.4&#8243; _module_preset=&#8221;default&#8221; header_font=&#8221;|800|||||||&#8221; header_letter_spacing=&#8221;4px&#8221; header_2_line_height=&#8221;1.6em&#8221; min_height=&#8221;37px&#8221; custom_margin=&#8221;-34px|||||&#8221; custom_padding=&#8221;10px|10px|10px|10px|false|false&#8221; hover_enabled=&#8221;0&#8243; header_text_shadow_style=&#8221;preset1&#8243; header_text_shadow_blur_strength=&#8221;0.12em&#8221; global_colors_info=&#8221;{}&#8221; sticky_enabled=&#8221;0&#8243;]<\/p>\n<p>by High Order Solutions<\/p>\n<p>[\/et_pb_text][\/et_pb_column][et_pb_column type=&#8221;1_2&#8243; _builder_version=&#8221;4.16&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_image src=&#8221;https:\/\/www.highordersolutions.com\/wp-content\/uploads\/2021\/09\/Lambda-CloudWatch-EC2.png&#8221; title_text=&#8221;Lambda-CloudWatch-EC2&#8243; align=&#8221;center&#8221; _builder_version=&#8221;4.16&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][\/et_pb_image][\/et_pb_column][\/et_pb_row][\/et_pb_section][et_pb_section fb_built=&#8221;1&#8243; _builder_version=&#8221;4.16&#8243; _module_preset=&#8221;default&#8221; background_color=&#8221;#212529&#8243; custom_padding=&#8221;0px|||||&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_row _builder_version=&#8221;4.16&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_column type=&#8221;4_4&#8243; _builder_version=&#8221;4.16&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_text _builder_version=&#8221;4.16&#8243; _module_preset=&#8221;default&#8221; text_text_color=&#8221;#FFFFFF&#8221; header_text_color=&#8221;#FFFFFF&#8221; header_2_text_color=&#8221;#FFFFFF&#8221; header_3_text_color=&#8221;#FFFFFF&#8221; header_4_text_color=&#8221;#FFFFFF&#8221; header_5_text_color=&#8221;#FFFFFF&#8221; header_6_text_color=&#8221;#FFFFFF&#8221; global_colors_info=&#8221;{}&#8221;]<\/p>\n<h2>Problem:<\/h2>\n<p>Our AWS account budget started small but over the years has grown into something quite substantial. In the beginning it was just our mail server, our public website, and our Atlassian Suite server.\u00a0 Easy peasy. But since then, we&#8217;ve added a sand box Atlassian server for testing, the occasional Dev Atlassian server for development projects, our CRM server, our MarCom Contact Mgmt server, a database instance, a DevOps instance, an Ansible automation server and all the load balancers, S3 buckets, and monitoring tools to manage it all.\u00a0 And this wasn&#8217;t cheap. It just sort of creeped up on us.<\/p>\n<p>If only we could remember to turn off the instances we didn&#8217;t always need and just create instances on demand from previously designed AMI&#8217;s.\u00a0<\/p>\n<p>Today&#8217;s solution is just about the turning stuff off.\u00a0<\/p>\n<h2><\/h2>\n<h2>Considerations:<\/h2>\n<p>You&#8217;ll need knowledge in these areas as well:<\/p>\n<ul>\n<li>Setting up IAM accounts with very limited, but powerful, permissions<\/li>\n<li>How to use CloudWatch to setup the events that will trigger your Lambda Functions<\/li>\n<li>A thorough understanding of CRON (jobs) Expressions<\/li>\n<\/ul>\n<h2><\/h2>\n<h2>Solutions:<\/h2>\n<p>&nbsp;<\/p>\n<p><span style=\"font-size: x-large;\"><strong><span style=\"color: #e02b20;\">AWS Lambda to the Rescue!<\/span><\/strong><\/span><\/p>\n<p>Aside from our website and application servers we seldom have need for many of our other EC2 instances outside business hours. Especially our testing environments like those use for User Acceptance Testing, Sandboxing, or Dev.\u00a0 If we could automate turning off &amp; on these instances from 7pm to 7am during the work week PLUS the entire weekend we could save a ton. Given we only need them running Monday thru Friday 7a to 7p, 12 hours each day, we could save approximately 108 hours of the 168 hour calendar week. 168 &#8211; 60 = 108.\u00a0 <span style=\"text-decoration: underline;\"><strong>That&#8217;s a 64% savings!<\/strong><\/span><\/p>\n<p style=\"text-align: center;\"><span style=\"font-size: x-large;\"><strong><span style=\"color: #e02b20;\"><\/span><\/strong><\/span><\/p>\n<p><strong><span style=\"color: #e02b20;\"><\/span><\/strong><\/p>\n<h4>Why this solution?<\/h4>\n<ul>\n<li>No servers to manage &#8211; Like a separate Ansible Server<\/li>\n<li>Continuous scaling &#8211; We can keep adding to it&#8217;s capabilities<\/li>\n<li>Cost optimized with millisecond metering &#8211; Only costs us money when it&#8217;s running<\/li>\n<li>Consistent performance at any scale<\/li>\n<\/ul>\n<p>For more information on these reasons, check out <a href=\"https:\/\/aws.amazon.com\/lambda\/\">https:\/\/aws.amazon.com\/lambda\/<\/a>\u00a0<\/p>\n<p>&nbsp;<\/p>\n<div class=\"lb-rtxt\"><\/div>\n<p><span style=\"font-size: 26px;\"><\/span><\/p>\n<p><span style=\"font-size: 26px;\">Challenges:<\/span><\/p>\n<p>Don&#8217;t forget that you&#8217;re working in GMT time, so make your conversions carefully.<\/p>\n<h2><\/h2>\n<h2>Take-Aways &amp; Lessons Learned:<\/h2>\n<p>If managed properly, an organization can automate many repetitive AWS tasks for consistency and to help you stay within budget.<\/p>\n<h2><\/h2>\n<h2>How Does it Work?<\/h2>\n<p>&nbsp;<\/p>\n<p>[\/et_pb_text][et_pb_image src=&#8221;https:\/\/www.highordersolutions.com\/wp-content\/uploads\/2021\/09\/product-page-diagram_Lambda-HowItWorks.68a0bcacfcf46fccf04b97f16b686ea44494303f.png&#8221; title_text=&#8221;product-page-diagram_Lambda-HowItWorks.68a0bcacfcf46fccf04b97f16b686ea44494303f&#8221; align=&#8221;center&#8221; _builder_version=&#8221;4.16&#8243; _module_preset=&#8221;default&#8221; custom_margin=&#8221;-37px|||||&#8221; global_colors_info=&#8221;{}&#8221;][\/et_pb_image][\/et_pb_column][\/et_pb_row][et_pb_row _builder_version=&#8221;4.16&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_column type=&#8221;4_4&#8243; _builder_version=&#8221;4.16&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_cta title=&#8221;Download Complete Instructions Here&#8221; button_text=&#8221;Download&#8221; _builder_version=&#8221;4.16&#8243; _dynamic_attributes=&#8221;link_option_url&#8221; _module_preset=&#8221;default&#8221; link_option_url=&#8221;@ET-DC@eyJkeW5hbWljIjp0cnVlLCJjb250ZW50IjoicG9zdF9saW5rX3VybF9hdHRhY2htZW50Iiwic2V0dGluZ3MiOnsicG9zdF9pZCI6IjUwMSJ9fQ==@&#8221; link_option_url_new_window=&#8221;on&#8221; global_colors_info=&#8221;{}&#8221;]<\/p>\n<p>Don&#8217;t worry, we&#8217;re not going to ask for your personal information or trick you into talking to a salesperson first. We REALLY hate that too.<\/p>\n<p>NOTE: THESE INSTRUCTIONS ARE PROVIDED AS GUIDANCE FOR TRAINING PURPOSES ONLY. DO YOUR OWN RESEARCH AND TESTING.<\/p>\n<p>IN NO EVENT SHALL THE COMPANY OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER (INCLUDING WITHOUT LIMITATION, SPECIAL, INCIDENTAL, CONSEQUENTIAL, OR INDIRECT DAMAGES FOR PERSONAL INJURY, LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, OR ANY PECUNIARY LOSS) ARISING OUT OF THE USE OF THIS PRODUCT OR THESE MATERIALS, EVEN IF THE COMPANY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.<\/p>\n<p>[\/et_pb_cta][et_pb_button button_url=&#8221;@ET-DC@eyJkeW5hbWljIjp0cnVlLCJjb250ZW50IjoicG9zdF9saW5rX3VybF9hdHRhY2htZW50Iiwic2V0dGluZ3MiOnsicG9zdF9pZCI6IjUwMSJ9fQ==@&#8221; button_text=&#8221;Download&#8221; button_alignment=&#8221;center&#8221; _builder_version=&#8221;4.16&#8243; _dynamic_attributes=&#8221;button_url&#8221; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][\/et_pb_button][\/et_pb_column][\/et_pb_row][\/et_pb_section]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SOLUTION of the MONTH: How to automatically shut down EC2 instances outside business hoursby High Order SolutionsProblem: Our AWS account budget started small but over the years has grown into something quite substantial. In the beginning it was just our mail server, our public website, and our Atlassian Suite server.\u00a0 Easy peasy. But since then, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":979,"comment_status":"open","ping_status":"closed","template":"","meta":{"_et_pb_use_builder":"on","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"project_category":[],"project_tag":[25,24],"class_list":["post-486","project","type-project","status-publish","has-post-thumbnail","hentry","project_tag-automate","project_tag-ec2"],"_links":{"self":[{"href":"https:\/\/www.highordersolutions.com\/index.php\/wp-json\/wp\/v2\/project\/486","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.highordersolutions.com\/index.php\/wp-json\/wp\/v2\/project"}],"about":[{"href":"https:\/\/www.highordersolutions.com\/index.php\/wp-json\/wp\/v2\/types\/project"}],"author":[{"embeddable":true,"href":"https:\/\/www.highordersolutions.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.highordersolutions.com\/index.php\/wp-json\/wp\/v2\/comments?post=486"}],"version-history":[{"count":15,"href":"https:\/\/www.highordersolutions.com\/index.php\/wp-json\/wp\/v2\/project\/486\/revisions"}],"predecessor-version":[{"id":1488,"href":"https:\/\/www.highordersolutions.com\/index.php\/wp-json\/wp\/v2\/project\/486\/revisions\/1488"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.highordersolutions.com\/index.php\/wp-json\/wp\/v2\/media\/979"}],"wp:attachment":[{"href":"https:\/\/www.highordersolutions.com\/index.php\/wp-json\/wp\/v2\/media?parent=486"}],"wp:term":[{"taxonomy":"project_category","embeddable":true,"href":"https:\/\/www.highordersolutions.com\/index.php\/wp-json\/wp\/v2\/project_category?post=486"},{"taxonomy":"project_tag","embeddable":true,"href":"https:\/\/www.highordersolutions.com\/index.php\/wp-json\/wp\/v2\/project_tag?post=486"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}