Skip to content

Instantly share code, notes, and snippets.

View MrHassanMurtaza's full-sized avatar
🎯
Focusing

Hassan Murtaza MrHassanMurtaza

🎯
Focusing
View GitHub Profile
@MrHassanMurtaza
MrHassanMurtaza / secret-manager-policy.json
Last active October 24, 2019 09:58
Secret manager attribute based access control
{
"Version":"2012-10-17",
"Statement":[
{
"Effect":"Allow",
"Action": "secretsmanager:GetSecretValue",
"Resource": "*",
"Condition": {
"secretsmanager:ResourceTag/Project": "${aws:PrincipalTag/Project}"
}
@MrHassanMurtaza
MrHassanMurtaza / serverless-deploy-iam.json
Created November 21, 2019 13:07
Serverless Deploy Permissions with SQS as a Trigger
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"apigateway:GET",
"apigateway:POST",
"apigateway:PUT",
@MrHassanMurtaza
MrHassanMurtaza / aws-codepipeline-executor.py
Last active January 10, 2020 12:40
AWS CodePipeline Executor Python
import json, os
import boto3
from botocore.exceptions import ClientError
def lambda_handler(event, context):
"""
Lambda Handler
Triggers AWS CodePipeline
:param event: takes event triggered by cloudwatch rule
@MrHassanMurtaza
MrHassanMurtaza / athena_routetable_query
Created January 24, 2020 12:52
Audit Routetable changes using CloudTrail and Athena
SELECT eventname, useridentity.username, sourceIPAddress, eventtime, requestparameters
FROM cloudtrail_logs_athena_table
WHERE (requestparameters like '%rtb-xxxxxxx%') limit 10;
@MrHassanMurtaza
MrHassanMurtaza / athena_routetable_query
Created January 24, 2020 12:52
Audit Routetable changes using CloudTrail and Athena
SELECT eventname, useridentity.username, sourceIPAddress, eventtime, requestparameters
FROM cloudtrail_logs_athena_table
WHERE (requestparameters like '%rtb-xxxxxxx%') limit 10;
@MrHassanMurtaza
MrHassanMurtaza / Deny_If_No_Purpose_Tag.json
Created January 30, 2020 08:47
Deny_If_No_Purpose_Tag
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "NoPurposeTag",
"Effect": "Deny",
"Action": [
"ec2:RunInstances",
"ec2:CreateVolume"
],
@MrHassanMurtaza
MrHassanMurtaza / install_ncdu_amazon_linux.sh
Created February 11, 2020 07:29
Install ncdu on amazon linux 2
#!/bin/bash
# install packages/dependencies for compilation
sudo yum -y install gcc make ncurses-devel
cd /tmp
# the latest version of ncdu is published here: http://dev.yorhel.nl/ncdu
# update the link below if necessary:
wget -nv http://dev.yorhel.nl/download/ncdu-1.10.tar.gz
@MrHassanMurtaza
MrHassanMurtaza / introrx.md
Created February 24, 2020 13:24 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@MrHassanMurtaza
MrHassanMurtaza / ec2-ssh.sh
Last active May 29, 2020 06:54
SSH to ec2 using session manager
#!/bin/bash
# Wrapper around AWS session manager for instance access using public ip and private ip
scriptname=$0
# Defaults
region='us-east-1'
profile=''
################################################################################
@MrHassanMurtaza
MrHassanMurtaza / script.sh
Created May 27, 2020 07:36 — forked from pigri/script.sh
ENI cleaner
@export ENIS=$$(aws ec2 describe-network-interfaces --filters "Name=status,Values=available" | jq ".NetworkInterfaces[] | select(.VpcId == \"$${VPC_ID}\") | .NetworkInterfaceId"); \
if [[ ! -z $${DRY_RUN} ]]; then \
echo "Running in dry run mode! No changes will be made. The following ENIs would be deleted:"; \
echo $${ENIS}; \
exit 0; \
else \
for eni in $$(echo $${ENIS}| tr -d "\""); \
do \
aws ec2 delete-network-interface --network-interface-id $${eni}; \
done; \