AWS EC2 Instance Resize Script

If you’re in a world with legacy code that doesn’t lend itself well to autoscaling you may find yourself in need of scaling servers up and down on a semi-regular basis. This gets annoying rather quickly through the AWS Web console. I’ve created a script to handle this task, it simply requires that you have Python installed, the AWS CLI installed and configured with your API keys, pip install of boto3 client if not already installed, and updating the web servers dictionary with your server names and instance-ids. Clone from here

 

 



import boto3
import time

client = boto3.client('ec2')

def stop_instances(my_instance):
    client.stop_instances(InstanceIds=[my_instance])
    waiter=client.get_waiter('instance_stopped')
    waiter.wait(InstanceIds=[my_instance])

def change_size(my_instance,targetsize):
    client.modify_instance_attribute(InstanceId=my_instance, Attribute='instanceType', Value=targetsize)

def start_instances(my_instance):
    client.start_instances(InstanceIds=[my_instance])

def main ():
    webservers = {'server1' : 'i-xxxxxxxxxxx','server2' : 'i-xxxxxxxxxx','server3' : 'i-xxxxxxxxx'}
    for k, v in webservers.iteritems():
        my_instance = (v)
        instance_name = (k)
        targetsize = 'c4.2xlarge'
        print (instance_name + " is stopping")
        stop_instances(my_instance)
        print (instance_name + " resizing to " + targetsize)
        change_size(my_instance,targetsize)
        print (instance_name + " is starting")
        start_instances(my_instance)
        time.sleep(60) 

main()

Updating NTFS Permissions in Powershell

I recently encountered a situation on a 4TB drive that needed permissions added recursively to a large directory with many folders. To save time I created a powershell script that would do this for me. Below is the script:

 

 

$path = "C:\yourpath\"
$user = "domain\username"
$permission = "Modify"
$acl = Get-Acl $path
$inherit = [system.security.accesscontrol.InheritanceFlags]"ObjectInherit",[system.security.accesscontrol.InheritanceFlags]"ContainerInherit"
$propagation = [system.security.accesscontrol.PropagationFlags]"None"
$accessRule = New-Object system.security.AccessControl.FileSystemAccessRule($user, $permission, $inherit, $propagation, "Allow")
$acl.SetAccessRule($accessRule)
$acl | Set-Acl $path

Passed AWS Solutions Architect Professional!

Greetings! Apologies the blog hasn’t been more active recently, but it’s been a pretty busy time at work and I just finished a long few months of studying and practicing for the AWS Solutions Architect Professional Exam. I sat the exam on April 06, 2018 and passed with a 70%. This was hands down one of the most difficult tests I have ever taken for a certification. I think the trickiest bit is to pay attention to what is being asked rather than what the best technical answer is, as some questions are looking for the most cost effective solution rather than the most technically accurate or resilient solution.

 

Resources:

When I sat my first AWS test back in 2016 it was for the Solutions Architect Associate. As I prepare for that I had gone through the Linux Academy course as well as the A Cloud Guru course. For the professional I went back to A Cloud Guru as I found their training to be through. Training can be found at their site here.

I also found the WhizLab practice exams to be very close to what you can expect to see on the test. They have 5 exams and each provides answer remediation with links to whitepapers. This was helpful in identifying areas where additional study is needed, as well as linking directly to the resources to study with. You can find a link to their page here.

 

Other Info:

That’s all I have on the test. Stick around for some posts in the next few months where I’ll be talking about some interesting Azure Infrastructure as Code with ARM templates, service fabric, and Windows containers.