Skip to content

Instantly share code, notes, and snippets.

@suhussai
suhussai / install-k9s.md
Created November 21, 2023 18:29
How to install k9s on Cloud9

Instructions

wget https://github.com/derailed/k9s/releases/download/v0.28.2/k9s_Linux_amd64.tar.gz
tar -xvzf k9s_Linux_amd64.tar.gz 
./k9s
@suhussai
suhussai / how-to-decode-jwts.md
Last active November 19, 2023 18:59
JWT Decoding with Bash

JWT Decoding with Bash

Json Web Tokens (JWTs) are base64 encoded strings. This is an example of JWT pulled from jwt.io

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c

It consists of three parts separated by a period ("."):

@suhussai
suhussai / update-aws-auth.sh
Created October 21, 2023 21:09
Add another role to aws-auth configmap using kubectl and jq
ROLE_ARN="arn:aws:iam::123456789123:role/my-role"
GROUP="system:masters"
# 1. read ".data.mapRoles" from aws-auth
# 2. convert it to json
# 3. add the role as a value to the json array
# 4. convert the json back to a string
MAP_ROLES=$(kubectl get configmap aws-auth -n kube-system -o json \
| jq --arg role "$ROLE_ARN" --arg group "$GROUP" -r '.data.mapRoles | fromjson | . += [{"rolearn": $role,"groups": [$group]} ] | tojson')
@suhussai
suhussai / delete-log-groups.sh
Created October 21, 2023 20:49
Bash script to find and delete auto-generated AWS Lambda, CodeBuild and API Gateway log groups using pagination.
#!/bin/bash
echo "$(date) cleaning up log groups..."
next_token=""
while true; do
if [[ "${next_token}" == "" ]]; then
response=$(aws logs describe-log-groups)
else
response=$(aws logs describe-log-groups --starting-token "$next_token")
fi
@suhussai
suhussai / set-cw-log-group-retention.sh
Last active November 19, 2023 18:35
AWS CLI script that iterates over CloudWatch log groups, and sets the retention policy on log groups that don't have one.
#!/bin/bash
next_token=""
RETENTION_POLICY_IN_DAYS=30
echo "$(date) Starting..."
while true; do
if [[ "${next_token}" == "" ]]; then
echo "$(date) making api call to search for log groups.."
response=$(aws logs describe-log-groups --max-items 50)
@suhussai
suhussai / boto3_cf_example.py
Last active January 11, 2020 22:58
boto3 cloud formation template body (TemplateBody) example using local yml file
import boto3, yaml, json
# file must in the same dir as script
template_file_location = 'example_cloud_formation.yml'
stack_name = 'test_cloud_formation'
# read entire file as yaml
with open(template_file_location, 'r') as content_file:
content = yaml.load(content_file)
@suhussai
suhussai / cert_creator.sh
Created March 7, 2018 17:33
Automatically create an AWS managed certificate via the AWS Certificate Manager (ACM) and print out the certificate's validation emails. (Uses aws-cli/1.14.51)
#!/bin/bash
# Usage
# bash cert_creator.sh *.example.com
#
DOMAIN_NAME=$1
echo "Starting script..."
echo "creating cert for $DOMAIN_NAME. Press enter to continue..."
@suhussai
suhussai / aws_autoscaling_cron.rb
Created October 15, 2017 18:56 — forked from kixorz/aws_autoscaling_cron.rb
Running cron jobs in AWS Auto Scaling group is tricky. When you deploy the same code and configuration to all instances in the group, cron job would run on all of them. You may not want that. This script detects the first instance in the group and allows only this instance to run the job. IAM user used by this script needs to have permissions to…
#!/usr/bin/env ruby
require 'syslog'
require 'net/http'
require 'aws-sdk'
Syslog.open
AWS.config({
:access_key_id => '<iam user key>',
:secret_access_key => '<iam user secret>'