Skip to content

Instantly share code, notes, and snippets.

@keithrozario
keithrozario / iam.py
Created September 22, 2021 07:06
Check which users are not in groups
import boto3
iam = boto3.resource('iam')
def list_users() -> list:
"""
List all users in an account
:return: list of usernames
"""
autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab
au! BufNewFile,BufReadPost *.{yaml,yml} set filetype=yaml foldmethod=indent
let g:indentLine_color_term = 100
@keithrozario
keithrozario / paginator.py
Created December 5, 2020 11:14
Paginators for DynamoDB
import boto3
# Create your own session
my_session = boto3.session.Session(region_name="regionA", profile_name="profileA")
client = my_session.client('dynamodb')
paginator = client.get_paginator('scan')
# Option 1, paginate through paginator, a bit clunky, but possibly better performance
response_iterator = paginator.paginate(
TableName="kl.Klayers-prodp38.db"
@keithrozario
keithrozario / remove.md
Created June 22, 2020 14:49
removing old commits

git checkout -b <branch_name> git --set-upstream origin <branch_name> git rebase -i

Squash all commits where necessary

:qw

Change commit message where necessary

git push +

@keithrozario
keithrozario / scrapper.py
Created May 9, 2020 04:39
AWS This is my Architecture Scrapper
import requests
import json
import csv
base_url = "https://aws.amazon.com/api/dirs/items/search"
params = {
"item.directoryId": "this-is-my-architecture",
"sort_by": "item.additionalFields.airDate",
"sort_order": "desc",
@keithrozario
keithrozario / powertools.py
Last active May 30, 2020 01:41
Logging with Powertools
from aws_lambda_powertools.logging import Logger
logger = Logger()
@logger.inject_lambda_context
def handler(event, context):
important_list = [1,2,3]
@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")