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 / dataclasses_json.py
Last active January 28, 2021 07:23
example for dataclasses_json
from dataclasses import dataclass
from dataclasses_json import dataclass_json, Undefined
from dataclasses_json.undefined import UndefinedParameterError
from dataclasses_jsonschema import JsonSchemaMixin
from typing import Optional
@dataclass_json(undefined=Undefined.RAISE)
@dataclass
class Info(JsonSchemaMixin):
conf_one: float
@thanakijwanavit
thanakijwanavit / lambdaCronEvent.yaml
Created November 28, 2020 15:28
set run periodically for lambda function cron event periodic hourly daily
Resources:
Type: AWS::Serverless::Function
Properties:
Events:
RunHourly:
Type: Schedule
Properties:
Schedule: rate(10 minutes)
@thanakijwanavit
thanakijwanavit / s3CorsSam.yml
Created November 24, 2020 04:11
cors configuration for sam and cloudformation
AWSTemplateFormatVersion: "2010-09-09"
Description: CORS example
Resources:
S3Bucket:
Type: "AWS::S3::Bucket"
Properties:
CorsConfiguration:
CorsRules:
@thanakijwanavit
thanakijwanavit / authSdk.py
Last active November 18, 2020 06:07
used to add user and login
from nicHelper.wrappers import add_method
from lambdasdk.lambdasdk import Lambda
from awsSchema.apigateway import Event, Response
from nicHelper.dictUtil import printDict
from nicHelper.exception import errorString
# Cell
class AuthSdk:
def __init__(
self,
@thanakijwanavit
thanakijwanavit / dynamodbCloudformationTemplate.yaml
Created November 18, 2020 00:59
dynamodb specifiction in cloudformation or sam
MainDatabase:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: ib_prcode
AttributeType: S
- AttributeName: needUpdate
AttributeType: S
BillingMode: PAY_PER_REQUEST
GlobalSecondaryIndexes:
class Cognito:
'''sdk to interact with cognito as a client'''
def __init__(
self,
identityPoolId,
userPoolId,
accountId,
clientId,
clientSecret,
region = 'ap-southeast-1'
@thanakijwanavit
thanakijwanavit / classWrapper.py
Created November 4, 2020 06:55
wrap function to add method to a class
#export
from functools import wraps # This convenience func preserves name and docstring
def add_method(cls):
def decorator(func):
@wraps(func)
def wrapper(self, *args, **kwargs):
return func(self, *args, **kwargs)
setattr(cls, func.__name__, wrapper)
aws s3api \
--profile villaaws \
put-bucket-accelerate-configuration \
--bucket chatterbot-data \
--accelerate-configuration Status=Enabled
@thanakijwanavit
thanakijwanavit / pynamodbSample.ipynb
Created October 24, 2020 16:11
pynamodbSample.py
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from villaWalletDatabase.database import getMember, setMember, addMember, removeMember, test