Skip to content

Instantly share code, notes, and snippets.

View abiydv's full-sized avatar
🏠
@home

abiydv

🏠
@home
View GitHub Profile
@abiydv
abiydv / aws-cli-commands.sh
Last active September 19, 2023 11:34
Useful aws cli commands (and errors)
# List all AWS Org accounts' Id, Name, and Email in a csv format
aws organizations list-accounts --query 'Accounts[].[Id,Name,Email,Status]' | jq -r '["id","name","email","status"], (.[]) | @csv'
# Find all EKS clusters in AWS Org
aws configservice list-aggregate-discovered-resources --resource-type "AWS::EKS::Cluster" --configuration-aggregator-name "aws-config-aggregator-name" --no-paginate --output text
# Find all EKS cluster AWS Org with name like name_pattern
# and only display the source account id, the cluster name, and the cluster region
aws configservice list-aggregate-discovered-resources --resource-type "AWS::EKS::Cluster" --configuration-aggregator-name "aws-config-aggregator-name" --no-paginate --query 'ResourceIdentifiers[?contains(ResourceName,`name_pattern`)].[SourceAccountId,ResourceName,SourceRegion]' --output text
{
"version": "",
"accountId": "",
"configurationItemCaptureTime": "",
"configurationItemStatus": "",
"configurationStateId": "",
"configurationItemMD5Hash": "",
"arn": "",
"resourceType": "",
"resourceId": "",
@abiydv
abiydv / base.auto.tfvars
Last active May 25, 2022 23:37
Terraform pattern for multi-region multi-account deployments
role_arn = {
development = "arn:aws:iam::123456789012:role/TFRole"
production = "arn:aws:iam::123456789013:role/TFRole"
}
@abiydv
abiydv / homebrew.sh
Created November 20, 2021 19:15
Homebrew Error
#
# Error seen when trying to install something with brew or even update formula
#
% brew update
fatal: Could not resolve HEAD to a revision
Already up-to-date.
% git -C $(brew --repo homebrew/core) checkout master
Branch 'master' set up to track remote branch 'master' from 'origin'.
@abiydv
abiydv / bitbucket-pipelines.yml
Created November 14, 2021 17:24
Bitbucket Pipelines workaround for PR target branch checks
# Bitbucket pipelines currently do not offer a way to specify a condition
# to only trigger jobs based on the target branch.
#
# See this - https://jira.atlassian.com/browse/BCLOUD-17859
#
# You need to use '**' filter to trigger the pipeline on every PR, and
# then filter for your specific branch in the pipeline
#
# Another problem with Bitbucket pipelines is there is no ability to "reject"
# a pipeline execution, so a manual trigger step is not very helpful as a
@abiydv
abiydv / promql.sh
Created September 30, 2021 16:11
Pod CPU Usage
# PromQL query to calculate how much CPU a particular pod is consuming on a particular instance
# Labels available after this query - ec2 and pod
#
# Required: node_exporter exposing node_cpu* metrics
# cadvisor exposing container_cpu* metrics
#
sum(label_replace(rate(container_cpu_usage_seconds_total{cluster="k8s"}[1m]),
"ec2", "$1", "instance", "(.+):.+")) by (ec2, pod) / ignoring (pod) group_left
sum(label_replace(rate(node_cpu_seconds_total{cluster="k8s"}[1m]),
@abiydv
abiydv / bitbucket-pipelines.yml
Last active September 30, 2021 09:06
Bitbucket Pipelines for Terraform with OIDC Access to AWS
image: hashicorp/terraform:1.0.7
definitions:
scripts:
- script: &aws-context
export AWS_REGION=REPLACE_WITH_REGION_TO_USE;
export AWS_WEB_IDENTITY_TOKEN_FILE=$(pwd)/web-identity-token;
export AWS_ROLE_SESSION_NAME=build-session;
export AWS_ROLE_ARN=REPLACE_WITH_ROLE_ARN_TO_USE;
echo $BITBUCKET_STEP_OIDC_TOKEN > $(pwd)/web-identity-token
@abiydv
abiydv / blackbox.yaml
Last active September 28, 2021 15:01
Example Blackbox config for POST call monitoring
modules:
http_2xx:
prober: http
timeout: 5s
http:
valid_http_versions: ["HTTP/1.1", "HTTP/2.0"]
valid_status_codes: []
method: GET
preferred_ip_protocol: "ip4"
@abiydv
abiydv / s3-bulk-upload.tf
Last active November 14, 2021 17:45
Terraform for each conditionals
# This is an example to bulk upload files to S3
# A local source directory and sample pattern are provided as variables.
# All matching files are uploaded to S3
locals {
file_list = toset(fileset(var.source_path, var.source_file_pattern))
# If you use terragrunt, use this local block instead to ignore
# the .terragrunt-source-manifest file it adds to each directory.
# This is useful if there is no common pattern to files.
@abiydv
abiydv / file-upload
Created August 30, 2021 01:11
Curl Snippets
curl -F "firstname=John" -F"lastname=Doe" "https://httpbin.org/post" -F"file=@file.txt"
{
"args": {},
"data": "",
"files": {
"file": "This is a test file\n"
},
"form": {
"firstname": "John",
"lastname": "Doe"