Skip to content

Instantly share code, notes, and snippets.

{
"Effect": "Allow",
"Action": [
"ec2:CreateRoute",
"ec2:DeleteRoute",
"ec2:ModifyInstanceAttribute",
"ec2:ReplaceRoute",
"ec2:DescribeRouteTables"
],
"Resource": "*"
#!/bin/bash
# This script is to set a default route for route tables that need NAT in the same VPC.
MAC_ADDRESS=`curl http://169.254.169.254/latest/meta-data/network/interfaces/macs/`
VPC_ID=`curl http://169.254.169.254/latest/meta-data/network/interfaces/macs/${MAC_ADDRESS:-1}/vpc-id`
INSTANCE_ID=`curl http://169.254.169.254/latest/meta-data/instance-id`
REGION=`curl http://169.254.169.254/latest/dynamic/instance-identity/document|grep region|awk -F\" '{print $4}'`
TAG_KEY="network"
TAG_VALUE="private"
#!/bin/bash
#
# This script goes through each bucket in s3 and prints out the header for each object.
#
for bucket in `aws s3 ls | awk '{print $3}'`
do
for object in `aws s3 ls s3://$bucket --recursive | awk '{print $4}'`
do
printf "OBJECTS\t$bucket\t$object\t"
#!/bin/bash
# This script is to set AWS envrionments with temporary security tokens
# It takes three position arguments that are used by aws sts assume-role:
# The first position: Role ARN
# The second position: External ID
# The third position: Role Session Name
#
# For example: /aws-sts-set-env.sh arn:aws:iam::012345678901:role/my-role my-external-id my-session-name
#
unset AWS_SESSION_TOKEN
#!/bin/bash
#
# This script goes through each bucket in s3. It counts number of objects in a bucket and sum up their size.
# It also prints out the ACLs for the bucket.
#
for bucket in `aws s3 ls | awk '{print $3}'`
do
aws s3 ls s3://$bucket --recursive |
awk -v bucket=$bucket 'BEGIN {total=0}
#!/bin/bash -v
yum install -y python26-pip gcc
pip install croniter
OPERATOR=/home/ec2-user/ec2_operator.py
wget -O $OPERATOR https://raw.githubusercontent.com/schen1628/ec2/master/ec2_operator.py
chown ec2-user:ec2-user $OPERATOR
chmod 644 $OPERATOR
echo "*/5 * * * * ec2-user python $OPERATOR" >> /etc/crontab
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Create and assign an IAM Policy to an existing group to allow users to manage their own credentials and MFA.",
"Parameters": {
"Group": {
"Description": "Assign the IAM policy to an existing group",
"Type": "String"
}
},
"Resources": {
"OperatorInstanceProfile" : {
"Properties": {
"Path": "/",
"Roles": [
{
"Ref": "OperatorRole"
}
]
},
"Type": "AWS::IAM::InstanceProfile"
"WaitHandle" : {
"Type" : "AWS::CloudFormation::WaitConditionHandle"
},
"WaitCondition" : {
"Type" : "AWS::CloudFormation::WaitCondition",
"DependsOn" : "OperatorInstance",
"Properties" : {
"Handle" : {"Ref" : "WaitHandle"},
"Timeout" : "300"
"Outputs" : {
"OperatorInstanceId" : {
"Value" : { "Ref" : "OperatorInstance" },
"Description" : "Instance Id of the ec2 operator instance"
}
}