-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
883 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2014 Mike Ryan | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
aws-system-administration-resources | ||
=================================== | ||
aws-system-administration | ||
========================= | ||
|
||
Scripts and resources for the AWS System Administration book | ||
Sample code and examples for AWS System Administration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"AWSTemplateFormatVersion" : "2010-09-09", | ||
"Description" : "A simple stack that launches an instance.", | ||
"Resources" : { | ||
"Ec2Instance" : { | ||
"Type" : "AWS::EC2::Instance", | ||
"Properties" : { | ||
"ImageId" : "ami-c1aaabb5", | ||
"InstanceType": "t1.micro" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
{ | ||
"AWSTemplateFormatVersion" : "2010-09-09", | ||
"Description" : "OpenVPN EC2 Instance and Security Group", | ||
|
||
"Parameters" : { | ||
"KeyName": { | ||
"Description" : "EC2 KeyPair name", | ||
"Type": "String", | ||
"MinLength": "1", | ||
"MaxLength": "255", | ||
"AllowedPattern" : "[\\x20-\\x7E]*", | ||
"ConstraintDescription" : "can contain only ASCII characters." | ||
}, | ||
"AllowedIPRange" : { | ||
"Description" : "IP Range allowed to access OpenVPN via SSH and HTTP(S)", | ||
"Type": "String", | ||
"MinLength": "9", | ||
"MaxLength": "18", | ||
"Default": "0.0.0.0/0", | ||
"AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})", | ||
"ConstraintDescription": "Must be a valid IP CIDR range of the form x.x.x.x/x." | ||
}, | ||
"AMI" : { | ||
"Description" : "OpenVPN AMI ID", | ||
"Type": "String" | ||
} | ||
}, | ||
|
||
"Resources" : { | ||
"OpenVPNInstance" : { | ||
"Type" : "AWS::EC2::Instance", | ||
"Properties" : { | ||
"InstanceType" : "t2.micro", | ||
"SecurityGroups" : [ { "Ref" : "OpenVPNSecurityGroup" } ], | ||
"KeyName" : { "Ref" : "KeyName" }, | ||
"ImageId" : { "Ref" : "AMI"}, | ||
"SourceDestCheck" : "false" | ||
} | ||
}, | ||
|
||
"OpenVPNSecurityGroup" : { | ||
"Type" : "AWS::EC2::SecurityGroup", | ||
"Properties" : { | ||
"GroupDescription" : "Allow SSH, HTTPS and OpenVPN access", | ||
"SecurityGroupIngress" : [ | ||
{ | ||
"IpProtocol" : "tcp", | ||
"FromPort" : "22", | ||
"ToPort" : "22", | ||
"CidrIp" : { "Ref" : "AllowedIPRange"} | ||
}, | ||
{ | ||
"IpProtocol" : "tcp", | ||
"FromPort" : "443", | ||
"ToPort" : "443", | ||
"CidrIp" : { "Ref" : "AllowedIPRange"} | ||
}, | ||
{ | ||
"IpProtocol" : "tcp", | ||
"FromPort" : "943", | ||
"ToPort" : "943", | ||
"CidrIp" : { "Ref" : "AllowedIPRange"} | ||
}, | ||
{ | ||
"IpProtocol" : "udp", | ||
"FromPort" : "1194", | ||
"ToPort" : "1194", | ||
"CidrIp" : { "Ref" : "AllowedIPRange"} | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
|
||
"Outputs" : { | ||
"InstanceId" : { | ||
"Description" : "InstanceId of the OpenVPN EC2 instance", | ||
"Value" : { "Ref" : "OpenVPNInstance" } | ||
}, | ||
"OpenVPNSecurityGroup" : { | ||
"Description" : "ID of the OpenVPN Security Group", | ||
"Value" : { "Fn::GetAtt" : [ "OpenVPNSecurityGroup", "GroupId" ] } | ||
|
||
}, | ||
"PublicIP" : { | ||
"Description" : "Public IP address of the newly created EC2 instance", | ||
"Value" : { "Fn::GetAtt" : [ "OpenVPNInstance", "PublicIp" ] } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
{ | ||
"AWSTemplateFormatVersion" : "2010-09-09", | ||
"Description" : "Example EC2 instance behind an OpenVPN server", | ||
|
||
"Parameters" : { | ||
"KeyName": { | ||
"Description" : "EC2 KeyPair name", | ||
"Type": "String", | ||
"MinLength": "1", | ||
"MaxLength": "255", | ||
"AllowedPattern" : "[\\x20-\\x7E]*", | ||
"ConstraintDescription" : "can contain only ASCII characters." | ||
}, | ||
"AMI" : { | ||
"Description" : "AMI ID", | ||
"Type": "String" | ||
}, | ||
"OpenVPNSecurityGroup" : { | ||
"Description" : "OpenVPN Security Group ID", | ||
"Type": "String" | ||
} | ||
}, | ||
|
||
"Resources" : { | ||
"Ec2Instance" : { | ||
"Type" : "AWS::EC2::Instance", | ||
"Properties" : { | ||
"InstanceType" : "t1.micro", | ||
"SecurityGroups" : [ { "Ref" : "InstanceSecurityGroup" } ], | ||
"KeyName" : { "Ref" : "KeyName" }, | ||
"ImageId" : { "Ref" : "AMI"} | ||
} | ||
}, | ||
|
||
"InstanceSecurityGroup" : { | ||
"Type" : "AWS::EC2::SecurityGroup", | ||
"Properties" : { | ||
"GroupDescription" : "Allows SSH access from the OpenVPN instance", | ||
"SecurityGroupIngress" : [ | ||
{ | ||
"IpProtocol" : "tcp", | ||
"FromPort" : "22", | ||
"ToPort" : "22", | ||
"SourceSecurityGroupId" : { "Ref" : "OpenVPNSecurityGroup"} | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
|
||
"Outputs" : { | ||
"PrivateIP" : { | ||
"Description" : "Private IP address of the EC2 instance", | ||
"Value" : { "Fn::GetAtt" : [ "Ec2Instance", "PrivateIp" ] } | ||
}, | ||
"PublicIP" : { | ||
"Description" : "Public IP address of the EC2 instance", | ||
"Value" : { "Fn::GetAtt" : [ "Ec2Instance", "PublicIp" ] } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/python | ||
|
||
import tempfile | ||
import Image | ||
import shutil | ||
import sys | ||
from boto.s3.connection import S3Connection | ||
from boto.s3.key import Key | ||
|
||
IMAGE_SIZES = [ | ||
(250, 250), | ||
(125, 125) | ||
] | ||
|
||
bucket_name = sys.argv[1] | ||
# Create a temporary directory to store local files | ||
tmpdir = tempfile.mkdtemp() | ||
conn = S3Connection() | ||
bucket = conn.get_bucket(bucket_name) | ||
for key in bucket.list(prefix='incoming/'): | ||
filename = key.key.strip('incoming/') | ||
print 'Resizing %s' % filename | ||
# Copy the file to a local temp file | ||
tmpfile = '%s/%s' % (tmpdir, filename) | ||
key.get_contents_to_filename(tmpfile) | ||
# Resize the image with PIL | ||
orig_image = Image.open(tmpfile) | ||
# Find the file extension and remove it from filename | ||
file_ext = filename.split('.')[-1] | ||
for resolution in IMAGE_SIZES: | ||
resized_name = '%s%sx%s.%s' % (filename.rstrip(file_ext), resolution[0], resolution[1], file_ext) | ||
print 'Creating %s' % resized_name | ||
resized_tmpfile = '%s/%s' % (tmpdir, resized_name) | ||
resized_image = orig_image.resize(resolution) | ||
resized_image.save(resized_tmpfile) | ||
# Copy the resized image to the S3 bucket | ||
resized_key = Key(bucket) | ||
resized_key.key = 'processed/%s' % resized_name | ||
resized_key.set_contents_from_filename(resized_tmpfile) | ||
# Delete the original file from the bucket | ||
key.delete() | ||
|
||
# Delete the temp dir | ||
shutil.rmtree(tmpdir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
{ | ||
"AWSTemplateFormatVersion": "2010-09-09", | ||
"Description": "Example Puppet client stack", | ||
"Parameters" : {<co id="client_parameters_co" /> | ||
"KeyName": { | ||
"Description" : "EC2 KeyPair name", | ||
"Type": "String", | ||
"MinLength": "1", | ||
"MaxLength": "255", | ||
"AllowedPattern" : "[\\x20-\\x7E]*", | ||
"ConstraintDescription" : "can contain only ASCII characters." | ||
}, | ||
"AMI" : { | ||
"Description" : "AMI ID", | ||
"Type": "String" | ||
}, | ||
"PuppetMasterDNS" : { | ||
"Description" : "Private DNS name of the Puppet master instance", | ||
"Type": "String" | ||
}, | ||
"PuppetClientSecurityGroup" : { | ||
"Description" : "Name of the Puppet client Security Group", | ||
"Type": "String" | ||
} | ||
}, | ||
|
||
"Resources": { | ||
"CFNKeys": { | ||
"Type": "AWS::IAM::AccessKey", | ||
"Properties": { | ||
"UserName": { | ||
"Ref": "CFNInitUser" | ||
} | ||
} | ||
}, | ||
"CFNInitUser": { | ||
"Type": "AWS::IAM::User", | ||
"Properties": { | ||
"Policies": [ | ||
{ | ||
"PolicyName": "AccessForCFNInit", | ||
"PolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "cloudformation:DescribeStackResource", | ||
"Resource": "*", | ||
"Effect": "Allow" | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
"PuppetClientInstance": { | ||
"Type": "AWS::EC2::Instance", | ||
"Properties": { | ||
"UserData": {<co id="client_userdata_co" /> | ||
"Fn::Base64": { | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"#!/bin/bash\n", | ||
"/opt/aws/bin/cfn-init --region ", { "Ref": "AWS::Region" }, " -s ", | ||
{ "Ref": "AWS::StackName" }, " -r PuppetClientInstance ", | ||
" --access-key ", { "Ref": "CFNKeys" }, | ||
" --secret-key ", { "Fn::GetAtt": [ "CFNKeys", "SecretAccessKey" ] } | ||
] | ||
] | ||
} | ||
}, | ||
"KeyName": { "Ref" : "KeyName" }, | ||
"SecurityGroups": [ | ||
{ | ||
"Ref": "PuppetClientSecurityGroup" | ||
} | ||
], | ||
"InstanceType": "t1.micro", | ||
"ImageId": { "Ref" : "AMI" } | ||
}, | ||
"Metadata": { | ||
"AWS::CloudFormation::Init": { | ||
"config": { | ||
"files": { | ||
"/etc/puppet/puppet.conf": { | ||
"content": { | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"[main]\n", | ||
" server=", { "Ref": "PuppetMasterDNS" }, "\n", | ||
" logdir=/var/log/puppet\n", | ||
" rundir=/var/run/puppet\n", | ||
" ssldir=$vardir/ssl\n", | ||
" pluginsync=true\n", | ||
"[agent]\n", | ||
" classfile=$vardir/classes.txt\n", | ||
" localconfig=$vardir/localconfig\n" | ||
] | ||
] | ||
}, | ||
"owner": "root", | ||
"group": "root", | ||
"mode": "000644" | ||
} | ||
}, | ||
"packages": {<co id="client_packages_co" /> | ||
"rubygems": { | ||
"json": [] | ||
}, | ||
"yum": { | ||
"gcc": [], | ||
"rubygems": [], | ||
"ruby-devel": [], | ||
"make": [], | ||
"puppet": [] | ||
} | ||
}, | ||
"services": {<co id="client_services_co" /> | ||
"sysvinit": { | ||
"puppet": { | ||
"ensureRunning": "true", | ||
"enabled": "true" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.