Skip to content

Instantly share code, notes, and snippets.

View tfentonz's full-sized avatar

Tom Fenton tfentonz

  • MAGIQ Software
  • Christchurch, New Zealand
  • 21:15 (UTC +12:00)
  • LinkedIn in/tfentonz
View GitHub Profile
@tfentonz
tfentonz / alb-ssl-policy.sh
Created March 28, 2023 20:30
AWS CLI to update Application Load Balance SSL listeners SSL policies
#!/bin/bash
export AWS_DEFAULT_PROFILE='my-profile'
export AWS_DEFAULT_REGION='us-east-1'
# Find all application load balancers
load_balancer_arns=$(aws elbv2 describe-load-balancers --query 'LoadBalancers[?Type==`application`].[LoadBalancerArn]' --output text)
for load_balancer_arn in $load_balancer_arns
do
@tfentonz
tfentonz / ec2-windows-with-sqlserver.sh
Created August 3, 2022 20:53
AWS CLI command to return EC2 instances that have Windows with SQL Server Standard platform
aws ec2 describe-instances \
--filters \
"Name=instance-state-name,Values=running" \
"Name=platform,Values=windows" \
--query 'Reservations[*].Instances[?PlatformDetails==`Windows with SQL Server Standard`].{Name:Tags[?Key==`Name`]|[0].Value,InstanceId:InstanceId,Status:State.Name,InstanceType:InstanceType,ImageId:ImageId,Platform:Platform,PlatformDetails:PlatformDetails}|[]' \
--output json
@tfentonz
tfentonz / cloudwatch-alarms.sh
Created August 1, 2022 01:36
CloudWatch alarms for multiple accounts and regions
#!/bin/bash
profile_prefix="ProfilePrefix"
region="us-east-1"
for i in Account1 Account2 Account3
do
length=$(aws cloudwatch describe-alarms \
--state-value ALARM \
--query "length(MetricAlarms[?starts_with(AlarmActions[0], \`arn:aws:autoscaling\`) == \`false\`])" \
@tfentonz
tfentonz / wafv2_labels.sh
Last active June 30, 2022 04:06
AWS WAF managed rule group available labels
aws wafv2 describe-managed-rule-group \
--vendor-name AWS \
--name AWSManagedRulesCommonRuleSet \
--scope REGIONAL \
--region <REGION> \
--query 'AvailableLabels[].[Name]' \
--output text
@tfentonz
tfentonz / cloudformation_template.sh
Created June 29, 2022 02:07
Get CloudFormation stack template body
aws cloudformation get-template \
--stack-name <STACK_NAME> \
--query 'TemplateBody' \
--output text
@tfentonz
tfentonz / backup-plans.sh
Created March 1, 2022 03:50
AWS Backup Plan list
aws backup list-backup-plans \
--query 'BackupPlansList[].[BackupPlanName]' \
--output text
#!/bin/bash
#
# TIMING AND PERFORMANCE:
# Options which take <time> are in seconds, or append 'ms' (milliseconds),
# 's' (seconds), 'm' (minutes), or 'h' (hours) to the value (e.g. 30m).
# -T<0-5>: Set timing template (higher is faster)
# OUTPUT:
# -oN/-oX/-oS/-oG <file>: Output scan in normal, XML, s|<rIpt kIddi3,
# and Grepable format, respectively, to the given filename.
# -v: Increase verbosity level (use -vv or more for greater effect)
@tfentonz
tfentonz / aws-get-instance-id.sh
Created September 7, 2021 07:56
AWS CLI get instance ID by name
aws ec2 describe-instances \
--filters "Name=tag:Name,Values=some-name" \
--query 'Reservations[].Instances[].[InstanceId]' \
--output text
@tfentonz
tfentonz / aws-ssl-policy-names.sh
Created September 2, 2021 03:47
AWS CLI Elastic Load Balancing SSL Policy Names
aws elbv2 describe-ssl-policies --query 'sort_by(SslPolicies[], &Name)[].{Name:Name}' --output text
@tfentonz
tfentonz / alb-ssl-policies.sh
Created September 2, 2021 03:30
AWS CLI script to list all Application Load Balancer listeners with an SSL policy
#!/bin/bash
# List application load balancers by ARN
load_balancer_arns=$(aws elbv2 describe-load-balancers \
--query 'sort_by(LoadBalancers[?contains(LoadBalancerArn,`:loadbalancer/app/`)],&LoadBalancerArn)[].[LoadBalancerArn]' \
--output text)
# For each ALB describe listeners with an SSL policy