Skip to content

Instantly share code, notes, and snippets.

aws ec2 describe-images --owners 136693071363 --filters 'Name=root-device-type,Values=ebs' 'Name=architecture,Values=x86_64' 'Name=name,Values=debian-11-amd64-20**' | jq -r '[ .Images[] | {ImageId,CreationDate} ] | sort_by(.CreationDate) | reverse | first | .ImageId'
vim /usr/bin/cloud-init
less /var/log/cloud-init.log
curl -s 169.254.169.254/1.0/meta-data/instance-id
curl -s 169.254.169.254/1.0/meta-data/public-ipv4
S3_USERID=$(aws s3api list-buckets --query Owner.ID --output text)
aws ce get-cost-and-usage --time-period Start=2022-12-01,End=2022-12-31 --granularity MONTHLY --metrics UsageQuantity --group-by Type=DIMENSION,Key=SERVICE | jq '.ResultsByTime[].Groups[] | select(.Metrics.UsageQuantity.Amount > 0) | .Keys[0]'
terraform show tfplan.out | jq >tfplan.json
jq '.terraform_version, .format_version' tfplan.json
find . -d -type d -name '.terraform' -exec rm -r {} \;
find . -d -type f -name '.terraform*' -exec rm -r {} \;
find . -d -type f -name '*tfstate*' -exec rm -r {} \;
find . -d -type f -name 'tfplan.out' -exec rm -r {} \;
# Verify distro
cat /etc/os-release
# Amazon Linux 2
sudo amazon-linux-extras install epel -y
# RHEL 8
sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm -y
# RHEL 7
sudo amazon-linux-extras install epel -y
sudo yum install stress -y
sudo stress --cpu 8 --vm-bytes $(awk '/MemAvailable/{printf "%d\n", $2 * 0.9;}' < /proc/meminfo)k --vm-keep -m 1
# –cpu spawn 8 CPU workers spinning on a square root task (sqrt(x))
# –vm-bytes use 90% of the available memory from /proc/meminfo
# –vm-keep re-dirty memory instead of freeing and reallocating.
# -m 1 spawn 1 worker spinning on malloc()/free()