Skip to content

Instantly share code, notes, and snippets.

View psa-jforestier's full-sized avatar

psa-jforestier

  • Stellantis Group
  • Paris, France
View GitHub Profile
@psa-jforestier
psa-jforestier / cw-annotation.sh
Created February 3, 2021 06:53
AWS CloudWatch add vertical annotations to a widget
#!/bin/bash
# From private repo : https://github.com/D4UDigitalPlatform/cloudscripts/blob/master/aws/scripts/cloudwatch/cw-annotation.sh
# Dependencies : aws cli, jq
# This script is used to add vertical annotations (like a timed event) to an existing widget inside a CloudWatch Dashboard.
# It is similar to https://github.com/anaynayak/aws-cloudwatch-annotations
# But do not need NodeJS, only Bash, AWS CLI and jq.
function usage() {
cat << EOF
cw-annotation.sh -d DASHBOARDNAME -w WIDGETNAME -t LABEL
@psa-jforestier
psa-jforestier / lambda_function_ALBS3Logs_to_CloudWatchLogs.py
Created November 5, 2019 13:04
A lambda function to stream Application Load Balancer logs dropped in S3 to CloudWatch Logs
'''
This function send Application Load Balancer logs to CloudWatch Logs. So you can use CloudWatch tools, like Insight or custom metrics.
By default, ALB log its access in gz file in S3, and there is no way yo send the log directly to a Log Group / Log Stream.
This lambda function is triggered on S3 "PUT" action (when ALB write its log file). It then download the file localy, unzip it, sort it, and stream it to a CloudWatch log groups.
Installation
Activate ALB logs, and indicate the S3 bucket and the prefix for the log files. Enable, on the bucket, the deletion of old log files
@psa-jforestier
psa-jforestier / lambda_function_CloudfRontS3Logs_to_CloudWatchLogs.py
Created March 6, 2019 12:49
A lambda function to stream CloudFront logs dropped in S3 to CloudWatch Logs
'''
This function send CloudFront logs to CloudWatch Logs. So you can use CloudWatch tools, like Insight or custom metrics.
By default, CloudFront log its access in gz file in S3, and there is no way yo send the log directly to a Log Group / Log Stream.
This lambda function is triggered on S3 "PUT" action (when CloudFront write its log file). It then download the file localy, unzip it, sort it, and stream it to a CloudWatch log groups.
Installation
Activate CloudWatch logs, and indicate the S3 bucket and the prefix for the log files. Enable, on the bucket, the deletion of old log files
(because log files will be now in Cloudwatch, it is not necessary to keep them in S3).
Install the Lambda function on the region of your S3 bucket. Grant permission of this function to read the S3 and to create Log group and stream.
@psa-jforestier
psa-jforestier / lambda_function.py
Created February 5, 2019 10:13
AWS Lambda function to gzip compress file when upload to S3 (will replace original file with gz version)
###
### This gist contains 2 files : settings.json and lambda_function.py
###
### settings.json
{
"extensions" : ["*.hdr", "*.glb", "*.wasm"]
}
### lambda_function.py
@psa-jforestier
psa-jforestier / purge-cdn.sh
Last active August 27, 2022 01:01
Shell script using AWS Cli to purge a CloudFront distribution, by id or by public aliases CNAME
#!/bin/sh
# Always checkout last version from https://github.com/D4UDigitalPlatform/cloudscripts/tree/master/aws/scripts/cloudfront
show_help() {
cat << EOF
Usage:
${0##*/} [--verbose] [--cloudfrontid CLDFID] [--cname CNAME] [--list]
Purge a CloudFront distribution.
options :
@psa-jforestier
psa-jforestier / lazy_users.py
Last active January 7, 2019 09:53 — forked from morido/lazy_users.py
detect non-contributors in an organization
#!/usr/bin/env python
# you will need http://github3py.readthedocs.org/en/latest/#installation
# I'm not sure if this works on Windows due to the use of strptime()
# Based on https://gist.github.com/morido/9817399
# Improvement : take user, pass and orga from command line + use the new github3 API
from github3 import login
import datetime
import json
import pprint
@psa-jforestier
psa-jforestier / user.py
Last active March 9, 2023 14:44
List all inactive user of a GitHub organization using GitHub API
'''
List all inactive user of a GitHub organization
See user.py --help for usage.
Partially inspired by https://gist.github.com/morido/9817399
'''
import sys # to use sys.stdout
import os
from datetime import datetime
from time import strftime
import datetime