Skip to content

Instantly share code, notes, and snippets.

Avatar

Alfredo Cambera alfredocambera

View GitHub Profile
@alfredocambera
alfredocambera / main-bash.sh
Created November 20, 2021 14:30
main-bash.sh
View main-bash.sh
cd /home/ec2-user/environment/curso-devsecops/terraform-docker
cat << EOF > main.tf
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
version = "~> 2.13.0"
}
}
@alfredocambera
alfredocambera / certbot-cloudflare.md
Last active March 19, 2022 07:20
Certbot commands to work with Cloudflare's plugin
View certbot-cloudflare.md

Certbot and CloudFlare

Example usage of Certbot's CloudFlare plugin:

Create certificates

$ sudo certbot certonly \
  --non-interactive \
 --agree-tos \
@alfredocambera
alfredocambera / ec2_credentials.sh
Last active May 10, 2021 23:01
How to get instance role creddentials using assigned EC2's IAM role using IMDSv2
View ec2_credentials.sh
#!/usr/bin/env bash
TOKEN_TTL=900 # 15 minutes
ROLE="$(curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/)"
TOKEN="$(curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: ${TOKEN_TTL}")"
CREDS="$(curl -s -H "X-aws-ec2-metadata-token: ${TOKEN}" "http://169.254.169.254/latest/meta-data/iam/security-credentials/${ROLE}")"
REGION=$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r .region)
AWS_ACCESS_KEY_ID="$(echo "${CREDS}" | jq -r .AccessKeyId)"
AWS_SECRET_ACCESS_KEY="$(echo "${CREDS}" | jq -r .SecretAccessKey)"
@alfredocambera
alfredocambera / requirements.py
Created March 8, 2019 00:00
generates a list of installed packages using the same format as the output generated by "pip3 freeze"
View requirements.py
#!/usr/bin/env python3
import pkg_resources
dists = [str(d).replace(" ","==") for d in pkg_resources.working_set]
for i in dists:
print(i)