Skip to content

Instantly share code, notes, and snippets.

import json
import boto3
def clone_iam_role(original_role_name,
new_role_name):
iam = boto3.client("iam")
@eidosam
eidosam / clone_instance_profile.py
Created April 5, 2024 21:16
Clone AWS IAM instance profile
import json
import boto3
original_instance_profile_name = 'original-role'
new_instance_profile_name = 'new-role'
def clone_instance_profile(original_instance_profile_name,
new_instance_profile_name):
@eidosam
eidosam / BigQuery_re2_udfs
Created January 23, 2023 12:05
BigQuery RegExp functions in Spark
https://cloud.google.com/bigquery/docs/reference/standard-sql/string_functions#regexp_contains
https://cloud.google.com/bigquery/docs/reference/standard-sql/string_functions#regexp_extract
https://cloud.google.com/bigquery/docs/reference/standard-sql/string_functions#regexp_replace
import copy
def merge_dict_deep(dest, src):
merged_dict = copy.deepcopy(dest)
for key in src:
if key not in dest:
merged_dict[key] = src[key]
elif isinstance(dest[key], dict) and isinstance(src[key], dict):
from boto3.session import Session
import base64
from botocore.exceptions import ClientError
def get_secret(secret_name, region_name='us-west-2'):
secret_value_response = {}
try:
secret_value_response = (
function newlineDelimitedKeyValue(obj, parentKey = '') {
return Object.entries(obj)
.map(([k, v]) => {
if (typeof v === 'object') {
return newlineDelimitedKeyValue(v, `${parentKey}${k}_`);
}
const kUpper = `${parentKey}${k}`.toUpperCase();
return `${kUpper}=${v}`;
@eidosam
eidosam / scala.Makefile
Created November 2, 2020 13:05
Default lifecycle phases of Maven build as Makefile
# https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
# Validate the project is correct and all necessary information is available.
validate:
mvn validate
# Compile the source code of the project.
compile:
mvn compile
# Test the compiled source code using a suitable unit testing framework.
@eidosam
eidosam / aws_list_secrets.py
Created June 24, 2020 11:53
List all secrets in AWS Secret Manager
import json
from boto3.session import Session
session = Session()
for region_name in session.get_available_regions('secretsmanager'):
endpoint_url = f'https://secretsmanager.{region_name}.amazonaws.com'
@eidosam
eidosam / BigQuery-UDF-StandardSQL-WebAssembly.sql
Created October 24, 2019 11:20
WebAssembly C-program in BigQuery Standard SQL UDF
CREATE TEMP FUNCTION
sum_asm(x INT64, y INT64)
RETURNS INT64
LANGUAGE js AS """
const sourceBuffer = new Uint8Array([
0, 97, 115, 109, 1, 0, 0, 0, 1, 139, 128, 128, 128, 0, 2, 96, 1, 127, 0, 96, 2, 127, 127, 1,
127, 2, 254, 128, 128, 128, 0, 7, 3, 101, 110, 118, 8, 83, 84, 65, 67, 75, 84, 79, 80, 3, 127,
0, 3, 101, 110, 118, 9, 83, 84, 65, 67, 75, 95, 77, 65, 88, 3, 127, 0, 3, 101, 110, 118, 18,
97, 98, 111, 114, 116, 83, 116, 97, 99, 107, 79, 118, 101, 114, 102, 108, 111, 119, 0, 0, 3,
101, 110, 118, 6, 109, 101, 109, 111, 114, 121, 2, 1, 128, 2, 128, 2, 3, 101, 110, 118, 5, 116,
@eidosam
eidosam / create-transfer-job.sh
Created March 7, 2019 14:03
Start a Google Cloud Storage Transfer job from command-line
#!/usr/bin/env bash
### ------ Preparation ------ ###
# Acquire new user credentials to use for Application Default Credentials
# Run: gcloud auth application-default login
### ------ -------------- --- ###
function printUsage() {
echo -e "
\rUsage: bash ./create-transfer-job.sh [options] <s3-source-data> <gcs-bucket-name>