Skip to content

Instantly share code, notes, and snippets.

@Bharathkumarraju
Bharathkumarraju / bash_aws_jq_cheatsheet.sh
Created March 7, 2023 03:33 — forked from lukeplausin/bash_aws_jq_cheatsheet.sh
AWS, JQ and bash command cheat sheet. How to query, cut and munge things in JSON generally.
# Count total EBS based storage in AWS
aws ec2 describe-volumes | jq "[.Volumes[].Size] | add"
# Count total EBS storage with a tag filter
aws ec2 describe-volumes --filters "Name=tag:Name,Values=CloudEndure Volume qjenc" | jq "[.Volumes[].Size] | add"
# Describe instances concisely
aws ec2 describe-instances | jq '[.Reservations | .[] | .Instances | .[] | {InstanceId: .InstanceId, State: .State, SubnetId: .SubnetId, VpcId: .VpcId, Name: (.Tags[]|select(.Key=="Name")|.Value)}]'
# Wait until $instance_id is running and then immediately stop it again
aws ec2 wait instance-running --instance-id $instance_id && aws ec2 stop-instances --instance-id $instance_id
# Get 10th instance in the account
variable "firebase_admin_token" {
description = "The token to use to deploy firebase resources."
type = string
}
variable "project" {
description = "The project id to create the app for."
type = string
}
import json
import boto3
def lambda_handler(event, context):
ses = boto3.client('ses')
body = """
Hello and welcome to the SES Lambda Python Demo.
--- # apache_balancer_manager_role do.yml
- name: member_host
debug:
msg: "member_host {{ member_host }}"
- name: "Get the balancer_manager content"
uri:
url: "{{ apache.balancer.url }}"
follow_redirects: yes
return_content: yes
@Bharathkumarraju
Bharathkumarraju / __main__.py
Created July 12, 2021 23:37 — forked from 1oglop1/__main__.py
Pulumi component resources
import pulumi
from pulumi_aws import s3
from pulumi import Output, Input, ResourceOptions, ComponentResource, set, get
import time
import json
from pydantic import BaseModel
async def w2():
"""Awaitable simulating output"""
@Bharathkumarraju
Bharathkumarraju / private-k8s.md
Created June 18, 2021 00:31 — forked from pydevops/private-k8s.md
how to set up kubectl on laptop for private GKE cluster and on prem private cluster

HTTP tunnel

On prem k8s cluster set up with bastion vm

  1. Run the bastion vm in your data center or in cloud with connectivity set up (usually vpn) to the on prem data center.
  2. Install tinyproxy on the bastion vm and pick a random port as it would be too easy for spam bot with default 8888, set up as systemd service according to https://nxnjz.net/2019/10/how-to-setup-a-simple-proxy-server-with-tinyproxy-debian-10-buster/. Make sure it works by validating with curl --proxy http://127.0.0.1:<tinyproxy-port> https://httpbin.org/ip. And I don't use any user authentication for proxy, so I locked down the firewall rules with my laptop IP/32.
  3. Download the kubeconfig file for the k8s cluster to your laptop
  4. From your laptop, run
HTTPS_PROXY=<bastion-external-ip>:<tinyproxy-port> KUBECONFIG=my-kubeconfig kubectl get nodes
@Bharathkumarraju
Bharathkumarraju / delete_docker_images_improved.sh
Created March 7, 2021 16:27
delete docker images improved
#!/usr/bin/env bash
####################################################################################################################################
# Delete docker specific tagged images
# 1. Retain last n images
#
####################################################################################################################################
export TOKEN="YmhhcmF0aGt1bWFycmFqdStyYWp1OjAySDQ5Wlsalgsdgjdsjgldshgoergxzvlzkxvljoigfejsglskzxmvklfdsajpgrjgd"
function retain_last_n() {
app=$1
#!/usr/bin/env bash
####################################################################################################################################
# Delete docker specific tagged images
# 1. Retain last 5 images of helloworldapp
# 2. Retain last 3 images of bharathterraform
# 3. Retain last 2 images of flask_app
#
####################################################################################################################################
export TOKEN="YmhhcmF0aGt1bWFycmFqdStyYWp1OjAySDQ5WFaskldfnsdkfdsmfsdgfnklsnglsdkgsakdgefgerreprogke"
From local machine
Step1: If you are in feature branch ...checkout to master first and pull lastest master code to local
bharathkumarraju@R77-NB193% git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
bharathkumarraju@R77-NB193 % git pull
amazon-ebs: },
amazon-ebs: "os_useradd_create_home": true,
amazon-ebs: "os_useradd_mail_dir": "/var/spool/mail"
amazon-ebs: },
amazon-ebs: "ansible_included_var_files": [
amazon-ebs: "/root/.ansible/roles/dev-sec.os-hardening/vars/RedHat.yml"
amazon-ebs: ],
amazon-ebs: "ansible_loop_var": "item",
amazon-ebs: "changed": false,
amazon-ebs: "item": "/root/.ansible/roles/dev-sec.os-hardening/vars/RedHat.yml"