Skip to content

Instantly share code, notes, and snippets.

@leadelngalame1611
leadelngalame1611 / [Keycloak] - scriptmapper
Last active November 21, 2022 07:26
[Keycloak] script mapper
/**
* Available variables:
* user - the current user
* realm - the current realm
* token - the current token
* userSession - the current userSession
* keycloakSession - the current keycloakSession
*/
@leadelngalame1611
leadelngalame1611 / install_eksctl_kind.sh
Created November 18, 2021 19:22
Install kubectl, kind, aws-iam-authenticator, eksctl and update aws
# Install kubectl
curl -sLO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
rm -f ./kubectl
# install eksctl
curl -sLO "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz"
tar xz -C /tmp -f "eksctl_$(uname -s)_amd64.tar.gz"
sudo install -o root -g root -m 0755 /tmp/eksctl /usr/local/bin/eksctl
rm -f ./"eksctl_$(uname -s)_amd64.tar.gz"
const appLabel = { app: "hello-kubernetes" };
const deployment = {
apiVersion: "apps/v1",
kind: "Deployment",
metadata: { name: "hello-kubernetes" },
spec: {
replicas: 3,
selector: { matchLabels: appLabel },
template: {
@leadelngalame1611
leadelngalame1611 / ec2_instance.py
Created February 13, 2022 17:26
Create EC2 Instance Boto3
import boto3
from time import sleep
REGION = 'us-east-1'
AMI_IMAGE_ID = 'ami-0fac5486e4cff37f4'
INSTANCE_TYPE = 'c5.xlarge'
DISK_SIZE_GB = 200
DEVICE_NAME = '/dev/xvda'
NAME = 'codeflex-ec2'
OWNER = 'codeflex'
@leadelngalame1611
leadelngalame1611 / cloudwatch_queries
Created February 18, 2022 19:30
Cloudwatch Queries
fields @timestamp, @message, kubernetes.container_name
| filter log_processed.level like "ERROR"
| filter kubernetes.namespace_name like "dromedarv2"
| stats count(*) as container_name by kubernetes.container_name
| limit 2000
@leadelngalame1611
leadelngalame1611 / postman_token.sh
Last active March 6, 2022 05:47
[POSTMAN] Copy Token to environment variable
## This should be placed inside the test section in your postman
# It will provide the Token retrieved as Environment variable
var jsonData = pm.response.json();
token = jsonData.access_token
console.log(token)
pm.environment.set("TOKEN", token);
@leadelngalame1611
leadelngalame1611 / ternary.js
Last active March 13, 2022 04:50
Ternary Operators
# The ternary operator is a for of syntatic sugar for an inline if/else
#Javascript:
const color = "blue"
console.log(color === "blue" ? "Show blue" : "Show red")
//output: Show blue
#Python
color = "blue"

Initialising an sns client

import boto3

AWS_REGION = "us-east-1"

sns_client = boto3.client("sns", region_name=AWS_REGION)

Initialising an sns Resource

@leadelngalame1611
leadelngalame1611 / python-csv-s3.py
Created March 29, 2022 07:35
create data from csv file uploaded to s3 and load to dynamodb
#!/usr/bin/python3
import os
import boto3
import csv
from datetime import datetime, timezone
s3_resource = boto3.resource('s3')
def assume_lookup_role(zone, account_id):
DNS_DELEGATION_READONLY_ROLE = (
f"arn:aws:iam::{account_id}:role/dns-delegation-readonly-role"
)
sts = boto3.client("sts")
credentials = sts.assume_role(
RoleArn=DNS_DELEGATION_READONLY_ROLE,
RoleSessionName=f"DnsDelegationLookup-{zone}",
)["Credentials"]