Skip to content

Instantly share code, notes, and snippets.

@AMMullan
Last active September 22, 2022 15:00
Show Gist options
  • Save AMMullan/d530ee6e61b2c284eda0666f164eaee5 to your computer and use it in GitHub Desktop.
Save AMMullan/d530ee6e61b2c284eda0666f164eaee5 to your computer and use it in GitHub Desktop.
# Remove all folders called .terraform in this dir
find . -type d -name .terraform -exec rm -rf {} +
# Create zip package from git
git archive --format zip --output [zip_file] --remote [repo_ssh_url] [branch_name]
# List packages and sort by size
rpm -qa --queryformat '%10{size} - %-25{name} \t %{version}\n' | sort -n
# Test VirtualHost
curl --header "Host: mysite.com" "http://10.0.0.1/fullpath"
curl -ivLs "https://mysite.com/fullpath" --resolve "mysite.com:443:10.0.0.1"
# Restore a file from Git
git rev-list -n 1 HEAD -- [file] # this will give you the last commit hash (the delete marker)
git checkout [commit_hash]^ -- [file] # the carat is intentional, it's a Git thing
git add [file]
git commit -m "Restored File" [file]
git push
##
# AWS Specific
##
# Sync S3 buckets !!! IMPORTANT SWITCHES
aws s3 sync --exact-timestamps --acl bucket-owner-full-control [source] [dest]
# Get count of EC2's within each subnet
aws --region us-east-1 ec2 describe-instances --filters Name=vpc-id,Values=vpc-xxx | jq -r "[[.Reservations[].Instances[]|{ state: .State.Name, subnet: .SubnetId }]|group_by(.state)|.[]|{state: .[0].state, subnets: [.[].subnet]|[group_by(.)|.[]|{subnet: .[0], count: ([.[]]|length)}] }]"
# Get a pretty list of EC2 instances
aws --region us-east-1 ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,State.Name,InstanceType,PrivateIpAddress,PublicIpAddress,Tags[?Key==`Name`].Value[]]' --output json | tr -d '\n[] "' | sed 's/i-/\ni-/g' | tr ',' '\t' | sed -e 's/null/None/g' | grep '^i-' | column -t
# Get Task ARN from within ECS Container Instance
curl -s $ECS_CONTAINER_METADATA_URI | jq '.Labels."com.amazonaws.ecs.task-arn"'
# Get List of CloudFormation Stacks where Description contains "My Description"
aws --region eu-west-1 cloudformation list-stacks | jq '.StackSummaries[] | select(.TemplateDescription != null) | select(.TemplateDescription | contains("My Description")) | .StackName'
# Get VPC detail where Name tag = "production"
aws --region us-east-1 ec2 describe-vpcs | jq '.Vpcs[] | select((.Tags[]|select(.Key=="Name")|.Value) == "production")'
# Get volumes where Name tag is present and create a list from this
aws --region us-east-1 ec2 describe-volumes | jq -r '[.Volumes[] | ((.Tags // empty) | from_entries) as $tags | select($tags.Name != null) | {volume_id: .VolumeId, name: $tags.Name }]'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment