Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrew Solera asolera

  • Secretaria Municipal de Inovação e Tecnologia de São Paulo
  • São Paulo
View GitHub Profile
@asolera
asolera / docker-debug.sh
Created Apr 16, 2021
Docker swarm debug commands that shows errors on service deploy
View docker-debug.sh
#!/bin/bash
# Credits/thanks to: https://stackoverflow.com/questions/45372848/docker-swarm-how-to-find-out-why-service-cant-start
docker service ps --no-trunc {serviceName}
journalctl -u docker.service | tail -n 50
@asolera
asolera / cloudformation.yml
Created Apr 14, 2021
AWS CloudFormation Template for EC2 (AMI) with Docker
View cloudformation.yml
AWSTemplateFormatVersion: '2010-09-09'
Description: AWS CloudFormation Template for EC2 (AMI) with Docker
Parameters:
EC2AvailabilityZoneParam:
Type: String
Default: us-east-1a
EC2ImageNameParam:
Type: String
Default: ami-0533f2ba8a1995cf9
@asolera
asolera / .env
Last active Apr 12, 2021
Vagrant with dot env without plugins
View .env
EXAMPLE_ENV_A=Hello
EXAMPLE_ENV_B=world
@asolera
asolera / git-fetch-branches.sh
Last active Apr 7, 2021
Git fetch all remote branches to local machine
View git-fetch-branches.sh
#!/bin/bash
git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
@asolera
asolera / tag.sh
Created Mar 25, 2021
Tagging AWS Cloudwatch Alarms via AWS CLI
View tag.sh
#!/bin/bash
aws cloudwatch tag-resource --resource-arn arn:aws:cloudwatch:us-east-1:012345678901:alarm:Alarm-Name --tags Key=Example,Value=OK Key=Another,Value=Okay
@asolera
asolera / lambda_function.py
Created Mar 23, 2021
Stop AWS EC2 Instances with Lambda
View lambda_function.py
import boto3
import time
# Enter the region your instances are in, e.g. 'us-east-1'
region = 'us-east-1'
# Enter your instances here: ex. ['X-XXXXXXXX', 'X-XXXXXXXX']
instances = ['i-03c24cxbd9x10ex51']
def lambda_handler(event, context):
ec2 = boto3.client('ec2', region_name=region)
ec2.stop_instances(InstanceIds=instances)
@asolera
asolera / lambda_function.py
Created Mar 23, 2021
Start AWS EC2 Instances with Lambda
View lambda_function.py
import boto3
import time
# Enter the region your instances are in, e.g. 'us-east-1'
region = 'us-east-1'
# Enter your instances here: ex. ['X-XXXXXXXX', 'X-XXXXXXXX']
instances = ['i-0ab7xdx71x8xeff33']
def lambda_handler(event, context):
ec2 = boto3.client('ec2', region_name=region)
ec2.start_instances(InstanceIds=instances)
@asolera
asolera / docker-ami.md
Created Mar 22, 2021
Docker install on Amazon Linux 2 (AMI)
View docker-ami.md

I've created this document just in case the original one (https://gist.github.com/npearce/6f3c7826c7499587f00957fee62f8ee9) get deleted.

sudo yum update -y
sudo amazon-linux-extras install docker -y
sudo service docker start
sudo usermod -a -G docker ec2-user
sudo chkconfig docker on
sudo yum install -y git
sudo reboot
@asolera
asolera / url_encode.sh
Created Mar 19, 2021
URL Encode with Shell Script
View url_encode.sh
#!/usr/bin/env bash
#
# Credits to Meleu @ https://meleu.sh/urlencode/
# Usage: urlencode "#" => will output "%23"
urlencode() {
local LC_ALL=C
local string="$*"
local length="${#string}"
local char
@asolera
asolera / auth.py
Last active Feb 17, 2021
Generating Cloudtrax API authorization/signature header with Python (client-side)
View auth.py
from time import time
import hmac
import hashlib
import uuid
def get_authorization_header(key: str) -> str:
nonce = 'YOUR_NONCE_PREFIX' + str(uuid.uuid4())
authorization = "key=" + key + ",timestamp=" + str(int(time())) + ",nonce=" + nonce
return authorization