Skip to content

Instantly share code, notes, and snippets.

@pcolazurdo
pcolazurdo / metric-filter.json
Last active November 13, 2019 14:44
Stress Test with bombardier
{
"metricFilters": [
{
"filterName": "result-2xx",
"filterPattern": "{ $.result.req2xx = * }",
"metricTransformations": [
{
"metricName": "bombardier-2xx",
"metricNamespace": "LogMetrics",
"metricValue": "$.result.req2xx",
@pcolazurdo
pcolazurdo / region_config.bash
Created November 13, 2019 13:14
Set AWS REGION from Metadata Service
#!/bin/bash
export AWS_AVAILABILITY_ZONE=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone)
export AWS_REGION=${AWS_AVAILABILITY_ZONE%?}
# From http://tldp.org/LDP/abs/html/string-manipulation.html :
# ${string%substring}
# Deletes shortest match of $substring from back of $string.
@pcolazurdo
pcolazurdo / CloudTrailQueries.sql
Last active November 13, 2019 11:23
Repository for useful queries for CloudTrail
-- Check Frequency of specific API Call
SELECT
useridentity.arn,
useridentity.username,
resources,
eventname,
substr(eventtime,12,5),
sourceipaddress,
count(*)
FROM cloudtrail_logs
@pcolazurdo
pcolazurdo / parse_boto_json.sh
Last active October 29, 2019 10:31
Parse boto json files
cat service-2.json | jq -r ' . | to_entries[] | [.key]| @csv' | more
#list all operations with the specific input shape
cat service-2.json | jq -r ' .operations | to_entries[] | [.key, .value.input.shape] | @csv' | more
#list a specific input shape format
echo RevokeSecurityGroupIngressRequest | \
while read a
do
echo $a | cat service-2.json | \
@pcolazurdo
pcolazurdo / raspi-update.sh
Created June 28, 2019 14:16
apt-get update for Raspbian
apt-get -o Acquire::Check-Valid-Until=false update
apt-get -o Acquire::Check-Valid-Until=false upgrade
@pcolazurdo
pcolazurdo / clean-cwl-goups.sh
Created March 23, 2019 12:14
Help to Maintain CloudWatch Logs Groups clean
filter=example
aws logs describe-log-groups --region us-west-2 | jq -r '.logGroups[].logGroupName' | grep $filter | while read a
do
aws logs delete-log-group --log-group-name $a --region us-west-2
done
@pcolazurdo
pcolazurdo / headless-browsers.md
Created December 1, 2018 18:55
Headless Browser in Lambda

Projects https://github.com/dhamaniasad/HeadlessBrowsers

https://github.com/GoogleChrome/puppeteer https://github.com/prisma-archive/chromeless

For Lambda

Running Puppeteer on AWS Lambda (from: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md) AWS Lambda limits deployment package sizes to ~50MB. This presents challenges for running headless Chrome (and therefore Puppeteer) on Lambda. The community has put together a few resources that work around the issues:

@pcolazurdo
pcolazurdo / lambda_cloudwatch.py
Last active September 18, 2018 16:13
Lambda Cloudwatch Custom Metric
cloudwatch = boto3.client('cloudwatch')
def lambda_handler(event, context):
response = cloudwatch.put_metric_data(
MetricData = [
{
'MetricName': 'QueryStringSize',
'Dimensions': [
{
'Name': 'Version',
@pcolazurdo
pcolazurdo / lambda-logger-setup.py
Last active December 1, 2018 18:56
Lambda Logger Setup Snippet
import logging
import os
import boto3
_log_levels = {
'CRITICAL': logging.CRITICAL,
'ERROR': logging.ERROR,
'WARNING': logging.WARNING,
'INFO': logging.INFO,
'DEBUG': logging.DEBUG
@pcolazurdo
pcolazurdo / stress-strategy.md
Last active September 10, 2018 10:11
Stress Test a machine - some tactics
  • Compile stress-ng
  • Run the following
sudo stress-ng --vm 30 --vm-bytes 29G --timeout 600s
sudo stress-ng --vm 2 --vm-bytes 2G --mmap 2 --mmap-bytes 2G --page-in
sudo fio  --name /mnt/disk1/fio_test_file --direct=1 --rw=randwrite --bs=512k --size=100m --numjobs=96 \
          --time_based --runtime=180 --group_reporting --norandommap