Skip to content

Instantly share code, notes, and snippets.

View mgla's full-sized avatar
🎯
Focusing

Maik Glatki mgla

🎯
Focusing
View GitHub Profile
@mgla
mgla / awsbrokensubscriptions.sh
Last active November 23, 2016 12:53
Find AWS SNS subscription that can be cancelled without authentication.
AWS_PROFILE=aws-profile; for id in `aws --profile $AWS_PROFILE sns list-subscriptions | jq -r '.Subscriptions |.[] | .SubscriptionArn '`; do aws --profile $AWS_PROFILE sns get-subscription-attributes --subscription-arn $id | jq '.Attributes | select(.ConfirmationWasAuthenticated == "false") | { Endpoint: .Endpoint, ConfirmationWasAuthenticated: .ConfirmationWasAuthenticated, Protocol: .Protocol}'; done
@mgla
mgla / json2yaml.sh
Last active June 7, 2018 12:22
json 2 yaml oneline
python -c 'import sys, yaml, json; yaml.safe_dump(json.load(sys.stdin), sys.stdout, default_flow_style=False)' < input.json > output.yaml
@mgla
mgla / get_iam_role_from_ec2.sh
Last active June 7, 2018 12:22
Get AWS IAM instance role
# Get and print IAM instance role
ROLE=$(curl http://169.254.169.254/latest/meta-data/iam/security-credentials/ -s); echo $ROLE
@mgla
mgla / AWS.md
Last active September 11, 2018 13:21
So, you want start with AWS CloudFormation

So, you want start with AWS CloudFormation

About this document

These are some unsorted notes I am taking along my journey with AWS CloudFormation (CFN). I plan to collect some good practices here

Things to think of beforehand

While AWS can be used cost for cost-saving, it is not for the weak of wallet at first. If you just want to run a VM with a public IP, you probably won't benefit from AWS at all.

VPCs (subnetting)

--- /etc/init.d/varnish 2017-02-09 13:25:38.000000000 +0000
+++ /etc/init.d/varnish.new 2017-03-29 09:49:56.898745740 +0000
@@ -137,12 +137,6 @@
status_varnishd
;;
restart|force-reload)
- if status_of_proc -p "${PIDFILE}" "${DAEMON}" "${SERVICE}" 1>/dev/null; then
- if ! configtest; then
- log_failure_msg "Syntax check failed, not restarting"
- exit 1
#
<Directory />
#Example..
SetEnvIF X-Forwarded-For "(,| |^)192\.168\.1\.1(,| |$)" DenyIP
SetEnvIF X-Forwarded-For "(,| |^)10\.1\.1\.1(,| |$)" DenyIP
Order allow,deny
Deny from env=DenyIP
Allow from all
</Directory>

Keybase proof

I hereby claim:

  • I am mgla on github.
  • I am mgla (https://keybase.io/mgla) on keybase.
  • I have a public key ASD9aSmbO-OX8Nm0nxdb5FQoVuNMKDtLSwyxjrESrjRLMwo

To claim this, I am signing this object:

Random useful Athena queries

CloudTrail

Find out who modified a IAM user policy

SELECT eventname,
         useridentity.arn,
         sourceIPAddress,

eventtime,

@mgla
mgla / aws-boto-session.py
Last active June 7, 2018 12:20
AWS boto don't ask for token every time
#!/usr/bin/env python3
# Don't ask for MFA token every time
from botocore import credentials
import botocore.session
import boto3
import os
# Boto3 MFA session magic
working_dir = os.path.join(os.path.expanduser('~'),'.aws/cli/cache')
from pprint import pprint
import boto3
def lambda_handler(event, context):
client = boto3.client('glue')
for endpoint in (client.get_dev_endpoints()['DevEndpoints']):
pprint(client.delete_dev_endpoint(
EndpointName= endpoint["EndpointName"]
))
return "Dev endpoints deleted"