Skip to content

Instantly share code, notes, and snippets.

View thanakijwanavit's full-sized avatar
🎯
Focusing

Nic Wanavit thanakijwanavit

🎯
Focusing
View GitHub Profile
@thanakijwanavit
thanakijwanavit / buildDeploy.sh
Last active October 7, 2020 02:21
build and deploy sam package using villaaws profile
sam build --profile villaaws &&\
sam deploy --profile villaaws --parameter-overrides BRANCH='dev-manual' STACKNAME='dev-manual'
@thanakijwanavit
thanakijwanavit / lambdaLayer.sh
Last active March 7, 2024 23:11
create a lambda layer package using docker
#!/bin/bash
export PKG_DIR="python"
rm -rf ${PKG_DIR} &&\
rm package.zip &&\
mkdir -p ${PKG_DIR}
docker run --rm -v $(pwd):/foo -w /foo lambci/lambda:build-python3.8 \
pip install -r requirements.txt -t ${PKG_DIR}
@thanakijwanavit
thanakijwanavit / cloudsearch.py
Created September 21, 2020 02:30
search sdk for cloudsearch
import pandas as pd
from pprint import pprint
class Searcher:
''' a search class to return search result'''
def __init__(self, searchTerm:str, key, pw, region = 'ap-southeast-1',
endpoint = 'https://search-villa-cloudsearch-2-4izacsoytzqf6kztcyjhssy2ti.ap-southeast-1.cloudsearch.amazonaws.com'
):
self.searchTerm = searchTerm
self.cloudSearch = boto3.client('cloudsearchdomain' ,
@thanakijwanavit
thanakijwanavit / testStack.sh
Created September 19, 2020 08:41
build test stack with random UUID stack name and parameter override
NEW_UUID=$(openssl rand -hex 12)
STACK_NAME=test-database-dev-test-$NEW_UUID
echo $STACK_NAME
source testrc&&python ./getSetData/app.py &&\
sam build --profile villaaws &&\
sam deploy --profile villaaws --stack-name $STACK_NAME --parameter-overrides BRANCH=${STACK_NAME} ROOTSTACKNAME=${STACK_NAME}&&\
aws --profile villaaws lambda invoke --function-name $STACK_NAME-topup testResult.log &&\
cat testResult.log &&\
read -p "Press enter to continue"
@thanakijwanavit
thanakijwanavit / blockPrint.py
Created September 19, 2020 04:16
block and enable print in python credit (https://bit.ly/33I9fM1)
import sys, os
# Disable
def blockPrint():
sys.stdout = open(os.devnull, 'w')
# Restore
def enablePrint():
sys.stdout = sys.__stdout__
@thanakijwanavit
thanakijwanavit / dfToListDict.py
Created September 19, 2020 03:43
dataframe to its individual column list of dict
df = pd.DataFrame([{'ib_brcode': '9007',
'ib_cf_qty': '24',
'ib_prcode': '0000009',
'new_ib_vs_stock_cv': '24'},
{'ib_brcode': '9007',
'ib_cf_qty': '39',
'ib_prcode': '0000012',
'new_ib_vs_stock_cv': '38'}])
@thanakijwanavit
thanakijwanavit / s3Helper.py
Created September 19, 2020 02:46
interact with s3 using accelerate endpoints and bzip compression
import requests, bz2, boto3
class S3:
@staticmethod
def s3():
'''
create and return s3 client
'''
config = Config(s3={"use_accelerate_endpoint": True,
"addressing_style": "virtual"})
s3 = boto3.client(
@thanakijwanavit
thanakijwanavit / putAccelerate.py
Last active November 27, 2020 06:13
put accelerate status on s3 using python
# create bucket
config = Config(s3={"use_accelerate_endpoint": True,
"addressing_style": "virtual"})
s3 = boto3.client(
's3',
aws_access_key_id= ACCESS_KEY_ID,
aws_secret_access_key= SECRET_ACCESS_KEY,
region_name = REGION,
config = config
)
@thanakijwanavit
thanakijwanavit / secretStore.py
Created September 18, 2020 16:27
load and save secrets using aws secrets manager
def get_secret(secretName = None, accessKey=None, secretKey=None, region = 'ap-southeast-1'):
secretManager = boto3.client(
service_name='secretsmanager',
region_name=region,
aws_access_key_id = accessKey,
aws_secret_access_key = secretKey
)
response = secretManager.get_secret_value(
SecretId=secretName
)
@thanakijwanavit
thanakijwanavit / loadPassword.py
Last active September 22, 2020 08:39
load password and other credentials from file using pickle
import pickle
credLocation = 'drive/My Drive/.pynamodbDax'
user =''
pw = ''
if user and pw:
with open (credLocation , 'wb') as f:
pickle.dump({
'user': user,
'pw': pw
}, f)