<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>automation Archives | Cloudar</title>
	<atom:link href="https://cloudar.be/tag/automation/feed/" rel="self" type="application/rss+xml" />
	<link>https://cloudar.be/tag/automation/</link>
	<description>100% Focus On AWS // 100% Customer Obsession</description>
	<lastBuildDate>Wed, 08 Jan 2020 08:03:21 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Validate ACM certificates in Cloudformation</title>
		<link>https://cloudar.be/awsblog/validate-acm-certificates-in-cloudformation/</link>
		
		<dc:creator><![CDATA[Michiel Vanderlinden]]></dc:creator>
		<pubDate>Wed, 08 Jan 2020 08:03:21 +0000</pubDate>
				<category><![CDATA[AWS Blog]]></category>
		<category><![CDATA[acm]]></category>
		<category><![CDATA[Amazon Web Services]]></category>
		<category><![CDATA[automatically validate acm]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[AWS]]></category>
		<category><![CDATA[cloudformation]]></category>
		<category><![CDATA[custom resource]]></category>
		<category><![CDATA[DevOps]]></category>
		<category><![CDATA[python]]></category>
		<guid isPermaLink="false">https://www.cloudar.be/?p=16482</guid>

					<description><![CDATA[<p>Intro: We will use a custom resource written in Python that will be able to create ACM certificates with DNS validation. The custom resource will also automatically validate this certificate if the validation domain is managed by a Route53 hosted zone. We will also be able to specify an AWS region to create the certificate [&#8230;]</p>
<p>The post <a href="https://cloudar.be/awsblog/validate-acm-certificates-in-cloudformation/">Validate ACM certificates in Cloudformation</a> appeared first on <a href="https://cloudar.be">Cloudar</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h3>Intro:</h3>
<p>We will use a custom resource written in Python that will be able to create ACM certificates with DNS validation. The custom resource will also automatically validate this certificate if the validation domain is managed by a Route53 hosted zone. We will also be able to specify an AWS region to create the certificate in, this region is independent of the Cloudformation stack region which for example makes it possible to deploy a certificate in region us-east-1 (to use with cloudfront) while deploying the stack in region eu-west-1. The resource will also provide the certificate arn as an output parameter so it can be used by other resources in the stack. Lastly when you delete the custom resource it will cleanup all validation records and the certificate itself.</p>
<h3>Requirements:</h3>
<ul>
<li>Python3</li>
<li>Pip</li>
<li>Bash</li>
<li>Zip</li>
<li>An S3 bucket to deploy the custom resource package on</li>
<li>A hosted zone for the validation record</li>
</ul>
<h3>Implementation:</h3>
<p>Let&#8217;s get started by downloading all the required code from our <a href="https://github.com/WeAreCloudar/cloudar_acm_plus">GitHub repository.</a></p>
<h4>Step1: Uploading the custom resource package</h4>
<p>In this step we are going to prepare the custom resource package and upload it to an S3 bucket.</p>
<p>First we go into the custom resource directory.<br />
<code>cd cloudar-acm-plus-custom-resource</code></p>
<p>Next we execute a script to install all required dependencies.<br />
<code>sh install_dependencies</code></p>
<p>Now we are ready to create the package.<br />
<code>sh pack_custom_resource</code></p>
<p><img fetchpriority="high" decoding="async" class="alignnone wp-image-16487 " src="https://cloudar.be/wp-content/uploads/2020/01/auto_validate_acm_package_commands.png" alt="package commands" width="595" height="378" srcset="https://cloudar.be/wp-content/uploads/2020/01/auto_validate_acm_package_commands.png 1120w, https://cloudar.be/wp-content/uploads/2020/01/auto_validate_acm_package_commands-768x488.png 768w" sizes="(max-width: 595px) 100vw, 595px" /></p>
<p>You will now find the zipfile &#8216;cloudar-acm-plus-custom-resource.zip&#8217; in &#8216;cloudar-acm-plus-custom-resource/packed&#8217;, upload this zip file to your S3 bucket.</p>
<h4>Step2: Creating a Cloudformation template</h4>
<p>Now we can create a Cloudformation template in which we use this custom resource to create an ACM certificate.<br />
You can use the template &#8216;cfn.yaml&#8217; as an example.</p>
<p>First create a Lambda resource as following<br />
<img decoding="async" class="alignnone wp-image-16492 " src="https://cloudar.be/wp-content/uploads/2020/01/auto_validate_acm_cfn_lambda.png" alt="auto validate lambda" width="520" height="475" srcset="https://cloudar.be/wp-content/uploads/2020/01/auto_validate_acm_cfn_lambda.png 1042w, https://cloudar.be/wp-content/uploads/2020/01/auto_validate_acm_cfn_lambda-768x702.png 768w, https://cloudar.be/wp-content/uploads/2020/01/auto_validate_acm_cfn_lambda-788x720.png 788w" sizes="(max-width: 520px) 100vw, 520px" /></p>
<p>Use the name of your bucket for the property &#8216;S3Bucket&#8217; .</p>
<p>Next we create the custom resource.<br />
<img decoding="async" class="alignnone wp-image-16493 " src="https://cloudar.be/wp-content/uploads/2020/01/auto_validate_cfn_cr.png" alt="auto validate cfn cr" width="454" height="287" srcset="https://cloudar.be/wp-content/uploads/2020/01/auto_validate_cfn_cr.png 832w, https://cloudar.be/wp-content/uploads/2020/01/auto_validate_cfn_cr-768x486.png 768w" sizes="(max-width: 454px) 100vw, 454px" /></p>
<p>We can set the following properties here:</p>
<ul>
<li>DomainName: (REQUIRED type:String) The domain name for the acm certificate.</li>
<li>AdditionalDomains: (OPTIONAL type:List) Additional domains for the acm certificate</li>
<li>ValidationDomain: (REQUIRED type:string) The domain name for the validation domain of the acm certificate</li>
<li>HostedZoneId: (REQUIRED type:string) The hosted zone id for the validation domain of the acm certificate</li>
<li>CertificateRegion: (REQUIRED type:string) The region to deploy the acm certificate in</li>
<li>IdempotencyToken: (REQUIRED type:string pattern: \w+) The idempotency token for the create call of the acm certificate doc: <a href="https://docs.aws.amazon.com/acm/latest/APIReference/API_RequestCertificate.html#ACM-RequestCertificate-request-IdempotencyToken" rel="nofollow">https://docs.aws.amazon.com/acm/latest/APIReference/API_RequestCertificate.html#ACM-RequestCertificate-request-IdempotencyToken</a></li>
<li>CertificateTags: (OPTIONAL type:list) The tags for the acm certificate</li>
</ul>
<p>In order for the DNS record cleanup and delete certificate functionality to work when you delete the Cloudformation stack it is important to set the following output.<br />
<img loading="lazy" decoding="async" class="alignnone wp-image-16495 " src="https://cloudar.be/wp-content/uploads/2020/01/auto_validate_cfn_output.png" alt="auto validate cfn output" width="666" height="98" srcset="https://cloudar.be/wp-content/uploads/2020/01/auto_validate_cfn_output.png 1238w, https://cloudar.be/wp-content/uploads/2020/01/auto_validate_cfn_output-768x113.png 768w" sizes="auto, (max-width: 666px) 100vw, 666px" /></p>
<p>As you can see we can access the arn of the certifcate created by the custom resource with the GetAtt function on the resource.<br />
<code>!GetAtt CreateCertificateCustomResource.certificate_arn</code></p>
<h4>Step3: Deploy the cloudformation</h4>
<p>Finally the only thing left to do is deploy the Cloudformation template.<br />
Once the deploy is started Cloudformation will create the Lambda containing the code from step1 and start a custom resource which will create the certificate and validation records. Once the status of the certificate becomes &#8216;ISSUED&#8217; the custom resource will finish successfully and report the arn of the certificate back to Cloudformation. We can now further use this arn in other resources in the Cloudformation template.<br />
When you delete the Cloudformation stack, the custom resource will cleanup the validation records in the hosted zone and delete the certificate.</p>
<p>CREATE_COMPLETE</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-16496 size-full" src="https://cloudar.be/wp-content/uploads/2020/01/auto_validate_acm_icon.png" alt="auto validate acm icon" width="300" height="259" /></p>
<p>The post <a href="https://cloudar.be/awsblog/validate-acm-certificates-in-cloudformation/">Validate ACM certificates in Cloudformation</a> appeared first on <a href="https://cloudar.be">Cloudar</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Windows servers patching with AWS EC2 Systems Manager</title>
		<link>https://cloudar.be/awsblog/windows-servers-patching-with-aws-ec2-systems-manager/</link>
					<comments>https://cloudar.be/awsblog/windows-servers-patching-with-aws-ec2-systems-manager/#comments</comments>
		
		<dc:creator><![CDATA[Rutger Beyen]]></dc:creator>
		<pubDate>Mon, 29 May 2017 11:39:09 +0000</pubDate>
				<category><![CDATA[AWS Blog]]></category>
		<category><![CDATA[Amazon]]></category>
		<category><![CDATA[Amazon Web Services]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[AWS]]></category>
		<category><![CDATA[EC2]]></category>
		<category><![CDATA[Run Command]]></category>
		<category><![CDATA[Systems Manager Services]]></category>
		<category><![CDATA[Windows Updates]]></category>
		<guid isPermaLink="false">https://cloudar.be/?p=3733</guid>

					<description><![CDATA[<p>&#160; Amazon EC2 Systems Manager is a collection of capabilities that helps you automate management tasks such as collecting system inventory, applying operating system patches, automating the creation of Amazon Machine Images (AMIs), and configuring operating systems and applications at scale. It is available at no cost to manage both your EC2 and on-premises resources! [&#8230;]</p>
<p>The post <a href="https://cloudar.be/awsblog/windows-servers-patching-with-aws-ec2-systems-manager/">Windows servers patching with AWS EC2 Systems Manager</a> appeared first on <a href="https://cloudar.be">Cloudar</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>&nbsp;</p>
<p>Amazon EC2 Systems Manager is a collection of capabilities that helps you automate management tasks such as collecting system inventory, applying operating system patches, automating the creation of Amazon Machine Images (AMIs), and configuring operating systems and applications at scale. It is available at no cost to manage both your EC2 and on-premises resources!</p>
<p>Amazon EC2 Systems Manager relies on the Amazon Simple Systems Management Service (SSM) agent being installed on the guests. The SSM agent is pre-installed on Windows Server 2016 instances or Windows Server 2003-2012 R2 instances created from AMI’s published after November 2016. You need at least SSM agent version 2.0.599.0 installed on the target EC2 instance.</p>
<p>In this article we will focus on using Systems Manager to apply Windows Updates to EC2 instances. Patch Management is always an operational pain point so its welcome that AWS offers a solution.</p>
<p>You start by creating groups of instances by applying a tag called &#8216;Patch Group&#8217;. Then you create a group of patches by forming a patch baseline containing and excluding the patches you require (or use the AWS default patch baseline). At last you create a maintenance window to have your patch baseline attached and applied to a patch group. The actual &#8216;Patch Now&#8217; run-command is nothing more than an API call, so there&#8217;s no obligation to use Maintenance Windows. Personally I&#8217;m a fan of Rundeck, so I&#8217;ll show you how to have the patches applied to the instances using both methods.</p>
<h2 id="WindowsServerspactchingwithAWSEC2SystemsManager-Configureyourinstances">Configure your instances</h2>
<p>The guest SSM agent setting inside with Windows OS requires permissions to connect to AWS EC2 Systems Manager. We grant these rights by creating an EC2 Service Role with the policy document ‘AmazonEC2RoleforSSM’ attached. Then you can attach this role to your instances. The instance also needs outbound internet connection to be able to connect to SSM. This can be either through an Internet Gateway or a NAT Gateway (or NAT Instance).</p>
<p>If you have this done right, your instance(s) should pop-up under &#8216;Managed Instances&#8217; in the EC2 console:</p>
<p><a href="https://cloudar.be/wp-content/uploads/2017/05/managed_instance-1.jpg"><img loading="lazy" decoding="async" class="alignnone wp-image-3735" src="https://cloudar.be/wp-content/uploads/2017/05/managed_instance-1.jpg" alt="" width="882" height="130" /></a></p>
<p>Take note of the SSM Agent Version. As said earlier it must be at least version 2.0.599.0. The Systems Manager Service also requires a &#8220;Patch Group&#8221;-tag on the EC2 instance. The key for a patch group tag must be <strong>Patch Group</strong>. Note that the key is case sensitive. The value can be anything you want to specify, but the key must be <strong>Patch Group.</strong></p>
<p><a href="https://cloudar.be/wp-content/uploads/2017/05/tags.jpg"><img loading="lazy" decoding="async" class="alignnone wp-image-3736" src="https://cloudar.be/wp-content/uploads/2017/05/tags.jpg" alt="" width="796" height="148" /></a></p>
<p>If done correctly, your tag will be picked up by SSM. You can confirm this on the &#8216;Managed Instances&#8217; page:</p>
<p><a href="https://cloudar.be/wp-content/uploads/2017/05/ssm_status.jpg"><img loading="lazy" decoding="async" class="alignnone wp-image-3737" src="https://cloudar.be/wp-content/uploads/2017/05/ssm_status.jpg" alt="" width="792" height="263" /></a></p>
<p>&nbsp;</p>
<h2 id="WindowsServerspactchingwithAWSEC2SystemsManager-PatchBaselines">Patch Baselines</h2>
<p>AWS provides a default Patch Baseline called &#8216;AWS-DefaultPatchBaseline&#8217;. It auto-approves all critical and security updates with a &#8216;critical&#8217; or &#8216;important&#8217; classification seven days after they have been released by Microsoft. If you&#8217;re happy with that you can use this baseline. If you&#8217;re not, you can simply create your own according to your requirements: set approval for specific products and patch classifications, exclude a specific KB etc</p>
<p><a href="https://cloudar.be/wp-content/uploads/2017/05/baseline.png"><img loading="lazy" decoding="async" class="alignnone wp-image-3738" src="https://cloudar.be/wp-content/uploads/2017/05/baseline.png" alt="" width="704" height="396" /></a></p>
<p>Once your happy with your baseline, you can hit &#8216;Create&#8217;. Now assign it to one or more Patch Groups (or make it the default baseline and throw away the AWS one). Hit the &#8216;actions&#8217; menu and chose &#8216;Modify Patch Groups&#8217;</p>
<p><a href="https://cloudar.be/wp-content/uploads/2017/05/patchbaseline.jpg"><img loading="lazy" decoding="async" class="alignnone wp-image-3739" src="https://cloudar.be/wp-content/uploads/2017/05/patchbaseline.jpg" alt="" width="463" height="152" /></a></p>
<p>Type the names of the Patch Groups you defined when tagging your instances</p>
<p><a href="https://cloudar.be/wp-content/uploads/2017/05/modifyPatchGroup.jpg"><img loading="lazy" decoding="async" class="alignnone wp-image-3740" src="https://cloudar.be/wp-content/uploads/2017/05/modifyPatchGroup.jpg" alt="" width="486" height="254" /></a></p>
<p>Your baseline is now attached to the specified patch groups. You can now start evaluating your instances against the baseline, and update them accordingly.</p>
<h2 id="WindowsServerspactchingwithAWSEC2SystemsManager-Patching">Patching</h2>
<p>Applying the patch baseline to a specific instance or to a patch group is nothing more than executing an AWS SSM run command. You can schedule this run command through AWS SSM &#8216;Maintenance Windows&#8217;, a cron job on a server (like Rundeck) or manual through the AWS Console.</p>
<p>Let&#8217;s first check everything manually. In the AWS EC2 console, go to &#8216;Run Commands&#8217; and create a new Run Command. Select the &#8216;AWS-ApplyPatchBaseline&#8217; command document and pick an instance run this on. For the &#8216;operation&#8217;, choose &#8216;Scan&#8217;. This will evaluate the instance against the baseline without installing anything yet.</p>
<p><a href="https://cloudar.be/wp-content/uploads/2017/05/ApplyPB.png"><img loading="lazy" decoding="async" class="alignnone wp-image-3741" src="https://cloudar.be/wp-content/uploads/2017/05/ApplyPB.png" alt="" width="609" height="381" /></a></p>
<p>Once the run command finishes, you can go back to the &#8216;Managed Instances&#8217; page. Highlight the instance(s) on which the run command was executed and click on the &#8216;Patch&#8217; tab. Here you can see the result of the scan:</p>
<p><a href="https://cloudar.be/wp-content/uploads/2017/05/patch_status.jpg"><img loading="lazy" decoding="async" class="alignnone wp-image-3742" src="https://cloudar.be/wp-content/uploads/2017/05/patch_status.jpg" alt="" width="719" height="212" /></a></p>
<p>To actually install the missing updates, execute the same run command document, but now with the &#8216;Install&#8217; operation. This will install the missing KBs to the instances and reboot them if needed.</p>
<p>Or execute the following aws cli command to accomplish the same:</p>
<pre class="lang:sh decode:true">aws ssm send-command --targets "Key=tag:Patch Group,Values=&lt;PatchGroupName&gt;" --document-name "AWS-ApplyPatchBaseline" --comment "Install|Check Windows Updates" --parameters Operation="&lt;Install|Scan&gt;"</pre>
<h2>Maintenance Windows</h2>
<p>In stead of manually starting a run command or cron job, we can also use the AWS provided Maintenance Windows feature. Systems Manager Maintenance Windows let you define a schedule for when to perform actions on your instances such as patching the operating system. Each Maintenance Window has a schedule, a duration, a set of registered targets, and a set of registered tasks.</p>
<p>Before actually creating a Maintenance Window, we must configure a Maintenance Window role. We need this so Systems Manager can execute tasks in Maintenance Windows on our behalf. So we go to the IAM page and create a new role. We pick an &#8220;EC2 service role&#8221; type and make sure to attach the &#8220;AmazonSSMMaintenanceWindowRole&#8221; policy to it. Once the role is created, we must modify it. Click &#8220;edit Trust Relationships&#8221;. Add a comma after &#8220;ec2.amazonaws.com&#8221;<b>,</b> and then add &#8220;Service&#8221;: &#8220;ssm.amazonaws.com&#8221; to the existing policy:</p>
<pre class="lang:default decode:true">{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "ec2.amazonaws.com",
        "Service": "ssm.amazonaws.com"
      },
      "Action": "sts:AssumeRole"
    }
  ]
}</pre>
<p>Back to SSM now to actually create the Maintenance Window. Give it a useful name and specify your preferred schedule. I&#8217;m setting &#8216;every 30 minutes&#8217; just for demonstration purposes, but in a real setup you would most probably choose something like &#8216;Every  Sunday&#8217;. You can also configure your own Cron expression.</p>
<p><a href="https://cloudar.be/wp-content/uploads/2017/05/createMX.jpg"><img loading="lazy" decoding="async" class="alignnone wp-image-3744" src="https://cloudar.be/wp-content/uploads/2017/05/createMX.jpg" alt="" width="490" height="415" /></a></p>
<p>This leaves us now with an empty Maintenance Window: there are no tasks nor targets associated yet.</p>
<p>To assign targets to the Maintenance Window, click on the &#8220;Register new targets&#8221; button on the &#8220;Targets&#8221; tab. We dynamically select the targets by using the &#8220;Patch Group&#8221; tag.</p>
<p><a href="https://cloudar.be/wp-content/uploads/2017/05/register_target.jpg"><img loading="lazy" decoding="async" class="alignnone wp-image-3745" src="https://cloudar.be/wp-content/uploads/2017/05/register_target.jpg" alt="" width="615" height="281" /></a></p>
<p>We will now have an ID linked to our &#8220;dev&#8221; Patch Group. This &#8220;Window Target ID&#8221; is used in the next step.</p>
<p><a href="https://cloudar.be/wp-content/uploads/2017/05/targets.jpg"><img loading="lazy" decoding="async" class="alignnone wp-image-3747" src="https://cloudar.be/wp-content/uploads/2017/05/targets.jpg" alt="" width="481" height="183" /></a></p>
<p>From the &#8220;tasks&#8221; tab of the Maintenance Window, click on &#8220;Schedule new task&#8221;. Pick the &#8220;AWS-ApplyPatchBaseline&#8221; document. Under &#8220;Registered Targets&#8221;, select the correct Window Target ID. For the operation, select &#8220;Install&#8221;. For the &#8220;Role&#8221;, select the IAM role with the AmazonSSMMaintenanceWindowRole attached to it (the one we created earlier). Set your preferred concurrency level and register the task by clicking on the blue button. The end result should look like this:</p>
<p><a href="https://cloudar.be/wp-content/uploads/2017/05/task.jpg"><img loading="lazy" decoding="async" class="alignnone wp-image-3748" src="https://cloudar.be/wp-content/uploads/2017/05/task.jpg" alt="" width="636" height="539" /></a></p>
<p>Now we have to wait for the schedule of the Maintenance Window. In this example we specified &#8216;every 30 minutes&#8217; as a schedule, so the waiting shouldn&#8217;t take too long. Under the &#8216;History&#8217; tab of the Maintenance Window you can follow all actions. The Maintenance Window will simply launch a Run Command, so you could go to that console screen too. If you enabled logging to S3, you could find the output of the Run Command over there. If not, you can view a (truncated) output via the Run Command itself:</p>
<p><a href="https://cloudar.be/wp-content/uploads/2017/05/output.jpg"><img loading="lazy" decoding="async" class="alignnone wp-image-3750" src="https://cloudar.be/wp-content/uploads/2017/05/output.jpg" alt="" width="692" height="329" /></a></p>
<pre class="lang:default decode:true">Patch Summary for i-07ca5621af38f256d
PatchGroup          : dev
BaselineId          : pb-06101e06cf8506be6
SnapshotId          : 317f2b72-2612-4740-95af-c7b3d8fb6d1e
OwnerInformation    : 
OperationType       : Install
OperationStartTime  : 2017-05-29T11:00:14.0000000Z
OperationEndTime    : 2017-05-29T11:03:18.7164313Z
InstalledCount      : 1
InstalledOtherCount : 6
FailedCount         : 0
MissingCount        : 0
NotApplicableCount  : 3

EC2AMAZ-EA5SH8I - PatchBaselineOperations Installation Results - 2017-05-29T11:03:19.537

KbArticleId Installed   Message
----------- ----------- -----------
KB890830    Yes         Success</pre>
<p>If we now go back to the &#8220;Managed Instances&#8221; page and look at the &#8220;Patch&#8221; tab of our test instance, we will see it is not missing any updates anymore!</p>
<p><a href="https://cloudar.be/wp-content/uploads/2017/05/final_status.jpg"><img loading="lazy" decoding="async" class="alignnone wp-image-3751" src="https://cloudar.be/wp-content/uploads/2017/05/final_status.jpg" alt="" width="847" height="264" /></a></p>
<p>&nbsp;</p>
<p>Success! Another <a href="https://cloudar.be/wp-content/uploads/2017/05/images.jpg"><img loading="lazy" decoding="async" class="wp-image-3752 alignnone" src="https://cloudar.be/wp-content/uploads/2017/05/images.jpg" alt="" width="26" height="26" /></a> on the Automation checklist!</p>
<p>&nbsp;</p>
<p>Rutger</p>
<p>The post <a href="https://cloudar.be/awsblog/windows-servers-patching-with-aws-ec2-systems-manager/">Windows servers patching with AWS EC2 Systems Manager</a> appeared first on <a href="https://cloudar.be">Cloudar</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://cloudar.be/awsblog/windows-servers-patching-with-aws-ec2-systems-manager/feed/</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
		<item>
		<title>Flexible Instance and Snapshot management with Ansible</title>
		<link>https://cloudar.be/awsblog/instance-and-snapshot-management-with-ansible/</link>
					<comments>https://cloudar.be/awsblog/instance-and-snapshot-management-with-ansible/#comments</comments>
		
		<dc:creator><![CDATA[Ben Bridts]]></dc:creator>
		<pubDate>Fri, 03 Apr 2015 16:14:45 +0000</pubDate>
				<category><![CDATA[AWS Blog]]></category>
		<category><![CDATA[Ansible]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[Continous Delivery]]></category>
		<category><![CDATA[DevOps]]></category>
		<category><![CDATA[GitHub]]></category>
		<category><![CDATA[JSON]]></category>
		<guid isPermaLink="false">https://cloudar.be/?p=563</guid>

					<description><![CDATA[<p>Here at Cloudar we&#8217;re using Ansible to automate deployments. We quickly realised its potential to orchestrate custom and more complicated automation Recently we were looking for a way to automate the following actions. Creating snapshots Starting and stopping instances Removing old snapshots We already had a script and cronjob to take regular snapshots, but we [&#8230;]</p>
<p>The post <a href="https://cloudar.be/awsblog/instance-and-snapshot-management-with-ansible/">Flexible Instance and Snapshot management with Ansible</a> appeared first on <a href="https://cloudar.be">Cloudar</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p></br><br />
Here at Cloudar we&#8217;re using <a title="Ansible" href="http://www.ansible.com" target="_blank" rel="noopener noreferrer">Ansible</a> to automate deployments. We quickly realised its potential to orchestrate custom and more complicated automation</p>
<p>Recently we were looking for a way to automate the following actions.</p>
<ul>
<li>Creating snapshots</li>
<li>Starting and stopping instances</li>
<li>Removing old snapshots</li>
</ul>
<p>We already had a <a title="Automating snapshots of EC2 EBS volumes" href="https://cloudar.be/awsblog/automating-snapshotsbackups-of-ec2-ebs-volumes/">script and cronjob to take regular snapshots</a>, but we wanted to centralise our automation to improve visibility and logging.</p>
<p>While this is possible using the existing Ansible modules, we needed a way to specify multiple parameters on a per instance basis. Specifically we needed it to be possible to:</p>
<ul>
<li>Change the start and stop times from within the AWS Console</li>
<li>Allow users without access to (or knowledge of) Ansible to prevent the automatic shutdown of a machine</li>
</ul>
<p>We quickly decided to use tags to specify these parameters. Because there&#8217;s a limit of ten tags per instance, and we wanted to store other information (like Environment and Project) too, it wasn&#8217;t possible to store each parameter in a separate tag.</p>
<p>We solved this by writing our own Ansible modules. Each module reads the same tag, where we store a JSON dictionary with all the needed variables. This way we keep room for other tags, while allowing everyone with the right to create tags to change things if they need to.</p>
<p>The source code is <a title="Cloudar Ansible Modules on GitHub" href="https://github.com/WeAreCloudar/ansible_modules" target="_blank" rel="noopener noreferrer">available on GitHub</a>. You can install it by <a href="http://docs.ansible.com/developing_modules.html#module-paths" target="_blank" rel="noopener noreferrer">adding the path to your Ansible Library</a>. Complete usage instructions and examples are included in <a href="http://docs.ansible.com/developing_modules.html">the repository</a>.</br></br></br></p>
<p>The post <a href="https://cloudar.be/awsblog/instance-and-snapshot-management-with-ansible/">Flexible Instance and Snapshot management with Ansible</a> appeared first on <a href="https://cloudar.be">Cloudar</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://cloudar.be/awsblog/instance-and-snapshot-management-with-ansible/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
		<item>
		<title>Automating snapshots of EC2 EBS volumes</title>
		<link>https://cloudar.be/awsblog/automating-snapshotsbackups-of-ec2-ebs-volumes/</link>
					<comments>https://cloudar.be/awsblog/automating-snapshotsbackups-of-ec2-ebs-volumes/#comments</comments>
		
		<dc:creator><![CDATA[Bart Van Hecke]]></dc:creator>
		<pubDate>Mon, 08 Sep 2014 12:28:11 +0000</pubDate>
				<category><![CDATA[AWS Blog]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[AWS]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[ebs]]></category>
		<category><![CDATA[EC2]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[snapshots]]></category>
		<category><![CDATA[tagging]]></category>
		<category><![CDATA[Tags]]></category>
		<guid isPermaLink="false">https://cloudar.be/?p=399</guid>

					<description><![CDATA[<p>Note: We stopped using this script, and started using Ansible to create snapshots. You can read more about that here. Recently we were looking for a way to have our EC2 EBS volumes snapshotted on a daily basis. Although AWS makes it easy to take snapshots of your EBS volumes, this requires some manual intervention [&#8230;]</p>
<p>The post <a href="https://cloudar.be/awsblog/automating-snapshotsbackups-of-ec2-ebs-volumes/">Automating snapshots of EC2 EBS volumes</a> appeared first on <a href="https://cloudar.be">Cloudar</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><strong>Note: We stopped using this script, and started using Ansible to create snapshots. You can read more about that <a href="https://cloudar.be/awsblog/instance-and-snapshot-management-with-ansible/">here</a>.</strong></p>
<p>Recently we were looking for a way to have our EC2 EBS volumes snapshotted on a daily basis. Although AWS makes it easy to take snapshots of your EBS volumes, this requires some manual intervention and thus prone to human error.<br />
As we love to automate as much as possible (we firmly believe in the &#8216;set &amp; forget&#8217; principle), we were looking for a way to script the AWS snapshotting mechanism. A quick Google search showed us that there already many solutions available that can handle this. However, one of these really drew our attention: The <strong><a href="https://github.com/colinbjohnson/aws-missing-tools/tree/master/ec2-automate-backup" target="_blank" rel="noopener noreferrer">ec2-automate-backup script</a></strong> by Collin Johnson. The script has it all:</p>
<ul>
<li>snapshot one specific volume or all volumes</li>
<li>Choose which volumes to backup</li>
<li>Backup volumes for as specific region</li>
<li>Snapshot retention: delete snapshots older than x days</li>
<li>&#8230;</li>
</ul>
<p>To handle automated snapshots on a daily basis of all our EBS volumes, we&#8217;ve setup a t1.micro EC2 instance (running CentOS 6.5) on which we created a cron job that runs daily, inventarises all volumes and snapshots only those volumes that have a Backup TAG value set to TRUE. Snapshots are being retained for 7 days by default. If the script detects snapshots older than 7 days, they will be deleted.</p>
<p>This is how we&#8217;ve set this up:</p>
<h2>Prerequisites</h2>
<h3>Java</h3>
<p>The Amazon EC2 CLI tools require Java. If you don&#8217;t have Java 1.7 or later installed, download and install Java as shown below:</p>
<pre>yum install java-1.7.0-openjdk</pre>
<p>Run the file command recursively to find the binary:</p>
<pre>file $(which java)</pre>
<p>→ example output: <em>/usr/bin/java: symbolic link to &#8216;/etc/alternatives/java&#8217;</em></p>
<p>The <em>&#8216;/usr/bin/java location&#8217;</em> is actually a link to <em>&#8216;/etc/alternatives/java&#8217;</em>, so you need to run the file command on that location to see whether that is the real binary:</p>
<pre>file /etc/alternatives/java</pre>
<p>→ example output: <em>/etc/alternatives/java: symbolic link to `/usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java&#8217;</em></p>
<p>This returns a new location, which is the actual binary. Verify this by running the file command on this location:</p>
<pre>file /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java</pre>
<p>→ example output: <em>/usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped</em><br />
This location is the actual binary. The Java home directory is where bin/java lives; in this example, the Java home directory is <em>&#8216;/usr/lib/jvm/jre-1.7.0-openjdk.x86_64&#8217;</em>.</p>
<p>You will now have to set the JAVA_HOME variable to the full path of the Java home directory:</p>
<pre>export JAVA_HOME=/usr/lib/jvm/jre-1.7.0-openjdk.x86_64</pre>
<p>You can verify your JAVA_HOME setting using this command:</p>
<pre>$JAVA_HOME/bin/java -version</pre>
<p>That&#8217;s it. We can now continue installing the AWS EC2 CLI tools.</p>
<p>&nbsp;</p>
<h3>Amazon EC2 CLI Tools</h3>
<h4>Download EC2 API tools</h4>
<pre>#Go to temp directory
cd /tmp

#Download the latest version of the EC2 CLI tools
wget http://s3.amazonaws.com/ec2-downloads/ec2-api-tools.zip

#Unzip the downloaded file
unzip ec2-api-tools.zip
</pre>
<p>&nbsp;</p>
<h4>Install EC2 API tools</h4>
<pre>#Create directory to install the EC2 CLI tools
mkdir /usr/local/ec2/apitools

#Move the downloaded tools to custom directory (replace version with your own version if other)
mv ec2-api-tools-1.7.1.1/* /usr/local/ec2/apitools
</pre>
<p>&nbsp;</p>
<h4>Set variables</h4>
<pre>#Set the EC2_HOME environment variable:
export EC2_HOME=/usr/local/ec2/apitools

#Update the PATH environment variable
export PATH=$PATH:$EC2_HOME/bin
</pre>
<p>&nbsp;</p>
<h4>Add variables to startup script, so they are widely available (Optional)</h4>
<pre>#Go to profile.d directory
cd etc/profile.d

#Create a new bash script
vi aws.sh
</pre>
<p>You can now add the variables into the script (we use vi as default editor):</p>
<pre>export JAVA_HOME=/usr/lib/jvm/jre-1.7.0-openjdk.x86_64
export EC2_HOME=/usr/local/ec2/apitools
export PATH=$PATH:$EC2_HOME/bin
</pre>
<p>Save and close the file</p>
<h3>Create IAM Backup User</h3>
<p>It&#8217;s a common best practice to create a separate account with limited access rights for these kind of purpose.</p>
<ul>
<li>Go to the IAM Console</li>
<li>Create a user &#8220;backup-ebs-user&#8221; (or a name of your own choice)</li>
</ul>
<p>→ Follow the <a href="http://docs.aws.amazon.com/IAM/latest/UserGuide/Using_SettingUpUser.html" target="_blank" rel="noopener noreferrer">AWS instructions</a> for adding a new IAM User<br />
→ Take a note of the user and security credentials for future usage</p>
<ul>
<li>Assign policy to the backup user, so only required access rights are assigned to the user</li>
</ul>
<p>→ Follow <a href="http://docs.aws.amazon.com/IAM/latest/UserGuide/Using_SettingUpUser.html" target="_blank" rel="noopener noreferrer">AWS instructions</a> for an overview of the IAM user polices</p>
<ul>
<li>Below is a sample policy that contains the IAM permissions required to run ec2-automate-backup.sh</li>
</ul>
<pre>{
	"Statement": [
		{
			"Action": [
				"ec2:DescribeVolumes",
				"ec2:CreateSnapshot",
				"ec2:DescribeSnapshots",
				"ec2:DeleteSnapshot",
				"ec2:CreateTags",
				"ec2:DescribeTags"
			],
			"Effect": "Allow",
			"Resource": [
				"*"
			]
		}
	]
}
</pre>
<p>&nbsp;</p>
<h2>Install the ec2-automate-backup script</h2>
<pre>#Go to EC2 directory
cd /usr/local/ec2

#Create script directory
Mkdir scripts

#Go to script directory
Cd scripts

# Download the script
wget https://raw.githubusercontent.com/colinbjohnson/aws-missing-tools/master/ec2-automate-backup/ec2-automate-backup.sh

#Make the downloaded file executable by everyone
chmod +x ec2-automate-backup.sh
</pre>
<p>The ec2-automate-backup script allows you to specify a source file for environmental configuration. This is interesting for running the script as a cronjob. An example cron primer file is located at <a href="https://github.com/colinbjohnson/aws-missing-tools/tree/master/ec2-automate-backup/Resources" target="_blank" rel="noopener noreferrer">https://github.com/colinbjohnson/aws-missing-tools/tree/master/ec2-automate-backup/Resources</a>.<br />
Let&#8217;s download the file and modify it according to our specific needs:</p>
<pre>#Download the cron-primer.sh example file
wget https://raw.githubusercontent.com/colinbjohnson/aws-missing-tools/master/ec2-automate-backup/Resources/cron-primer.sh

#Make the downloaded file executable by everyone
chmod +x cron-primer.sh
</pre>
<p>Now edit the cron-primer.sh script so custom variables are available to cron<br />
→ (don&#8217;t forget to add your Access/Secret key)<br />
Our edited cron-primer.sh file:</p>
<pre>#!/bin/bash -
# EC2_HOME required for EC2 API Tools
export EC2_HOME=/usr/local/ec2/apitools
# JAVA_HOME required for EC2 API Tools
export JAVA_HOME=/usr/lib/jvm/jre-1.7.0-openjdk.x86_64
# export PATH=/bin is required for cut, date, grep
# export PATH=/opt/aws/bin/ is required for EC2 API Tools
export PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/ec2/apitools/bin/
export AWS_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxxx
export AWS_SECRET_KEY=xxxxxxxxxxxxxxxxxxxxxxxxx
</pre>
<p>&nbsp;</p>
<h2>Add custom Backup TAG to your EBS Volumes</h2>
<p>Because we only want to backup the volumes that have a Backup Tag value set to &#8216;true&#8217;, we need to add these tags to our EBS volumes. This has the advantage of leaving the scripts untouched and it enables us to manage the volumes we want snapshot through the AWS console.<br />
Just add the Backup TAG and set its value to &#8216;true&#8217; as shown in the example below:</p>
<p><a href="https://cloudar.be/wp-content/uploads/2015/05/Screen-Shot-2014-09-08-at-17.28.50.png"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-657" src="https://cloudar.be/wp-content/uploads/2015/05/Screen-Shot-2014-09-08-at-17.28.50.png" alt="Backup Tags" width="1002" height="440" /></a></p>
<p>&nbsp;</p>
<h2>Create Cron job</h2>
<p>In the example below, we created a cron job that runs daily at 03:00AM.</p>
<pre>0 03 * * * /usr/local/ec2/scripts/ec2-automate-backup.sh -r eu-west-1 -s tag -t 'Backup=true' -k 7 -p -n -c /usr/local/ec2/scripts/cron-primer.sh
</pre>
<p>This cron job creates a snapshot of all EBS volumes which reside in the &#8216;eu-west-1&#8217; region and that have the Backup Tag value set to &#8216;true&#8217;. Snapshots are being retained for 7 days.</p>
<p>We hope this blogpost can be of some assistance in helping you to automate some manual tasks. Feel free to comment or modify the script for your own purposes.</p>
<h4>References we used</h4>
<p>→ <a title="EC2 Automatic Backup Script by Collin Johnson" href="https://github.com/colinbjohnson/aws-missing-tools/tree/master/ec2-automate-backup" target="_blank" rel="noopener noreferrer">https://github.com/colinbjohnson/aws-missing-tools/tree/master/ec2-automate-backup</a></p>
<p>→ <a title="Amazon EC2 Command Line Interface Tools Documentation" href="http://docs.aws.amazon.com/AWSEC2/latest/CommandLineReference/set-up-ec2-cli-linux.html" target="_blank" rel="noopener noreferrer">http://docs.aws.amazon.com/AWSEC2/latest/CommandLineReference/set-up-ec2-cli-linux.html</a></p>
<p>The post <a href="https://cloudar.be/awsblog/automating-snapshotsbackups-of-ec2-ebs-volumes/">Automating snapshots of EC2 EBS volumes</a> appeared first on <a href="https://cloudar.be">Cloudar</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://cloudar.be/awsblog/automating-snapshotsbackups-of-ec2-ebs-volumes/feed/</wfw:commentRss>
			<slash:comments>9</slash:comments>
		
		
			</item>
	</channel>
</rss>
