Skip to content

Instantly share code, notes, and snippets.

@keithrozario
keithrozario / get_formatter.py
Created April 30, 2020 10:52
get_formatter
import logging
import json
class FormatterJSON(logging.Formatter):
def format(self, record):
record.message = record.getMessage()
if self.usesTime():
record.asctime = self.formatTime(record, self.datefmt)
@keithrozario
keithrozario / change_log.py
Created April 30, 2020 10:48
Change Logger Setting
logger = logging.getLogger()
logger.setLevel(logging.INFO)
logger.handlers[0].setFormatter(logging.Formatter('{"level": "%(levelname)s", "message": "%(message)s", "time": "%(asctime)s", "name": "%(name)s"}',
"%Y-%m-%dT%H:%M:%S"))
logger.info("Hello")
@keithrozario
keithrozario / lambda_logging.py
Created April 30, 2020 10:43
lambda_logging
import logging
logger = logging.getLogger()
logger.setLevel(logging.INFO)
def main(event, context):
logger.info("This is an info message")
logger.warning("This is a warning message")
logger.debug("This is a debug message")
logger.error("This is an error message")
@keithrozario
keithrozario / Azure.txt
Last active April 23, 2020 01:26
Azure notes
How many tenants can a user in Azure Active Directory belong to?
What are characteristics of Azure Paired Regions?
Azure Information protection == ~Macie
Network Security Group == Security Group
Application Gateway == Application Load Balancer
Azure Support Plans
Service Trust Portal == Artifact
Resource Group == ~Tags
App Services??
Azure Firewall
@keithrozario
keithrozario / memory.py
Last active August 28, 2023 10:43
Read file from s3.download_fileobj into memory
s3 = boto3.client('s3')
## Reading a JSON file in memory
with tempfile.TemporaryFile() as data:
s3.download_fileobj(bucket_name, 'tests/s3/key.json', data)
data.seek(0)
status = json.loads(data.read().decode('utf-8'))['status']
## Reading a CSV file in memory
with tempfile.TemporaryFile() as package_file:
@keithrozario
keithrozario / exe
Last active April 7, 2020 04:33
exe
https://sdadadsazxzxvwr6t3676jnvcxzvcz.s3-ap-southeast-1.amazonaws.com/model.txt
@keithrozario
keithrozario / on_delete.yml
Last active July 26, 2024 21:15
Get branch name on branch delete github actions
name: Serverless Delete example
on:
delete:
branches:
- actions-**
# Specify what jobs to run
jobs:
deploy:
@keithrozario
keithrozario / main.yml
Created February 25, 2020 13:13
Getting the Branch Name from GitHub actions
steps:
- uses: actions/checkout@v1
- name: Set Branch name to $STAGE env var
run: |
BRANCH="$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//_/g')"
echo "BRANCH is $BRANCH"
echo "::set-env name=STAGE::$BRANCH"
@keithrozario
keithrozario / serverless.yml
Created February 23, 2020 23:36
Simple Serverless
name: Simple Serverless
# Triggers
on:
push:
branches:
- master
# Jobs
jobs:
@keithrozario
keithrozario / policy.json
Created February 9, 2020 09:50
VPCe Policy
{
"Version": "2012-10-17",
"Id": "VPCe and SourceIP",
"Statement": [{
"Sid": "VPCe and SourceIP",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": [
"${aws_s3_bucket.test_endpoint.arn}/*"