Skip to content

Instantly share code, notes, and snippets.

@arthuralvim
arthuralvim / use_pfx_with_requests.py
Created April 17, 2019 18:35 — forked from erikbern/use_pfx_with_requests.py
How to use a .pfx file with Python requests – also works with .p12 files
import contextlib
import OpenSSL.crypto
import os
import requests
import ssl
import tempfile
@contextlib.contextmanager
def pfx_to_pem(pfx_path, pfx_password):
''' Decrypts the .pfx file to be used with requests. '''
@arthuralvim
arthuralvim / getting-start-with-AWS-Batch.md
Created May 28, 2019 02:57 — forked from doi-t/getting-start-with-AWS-Batch.md
A log of getting start with AWS Batch.
@arthuralvim
arthuralvim / aws_lambda_cloudwatch_logs_exporter.md
Created May 28, 2019 03:02 — forked from doi-t/aws_lambda_cloudwatch_logs_exporter.md
Export logs from CloudWatch Logs to S3 with AWS Lambda

event example

TASK_NAME=${1:-'export_logs'}
FROM=${2:-'2017-12-24 12:00'}
TO=${3:-'2017-12-24 12:05'}
cat <<-EOF > event.json
{
    "taskName": "$TASK_NAME",
    "fromTime": `gdate --date="$FROM" +%s%3N`,
 "toTime": `gdate --date="$TO" +%s%3N`
@arthuralvim
arthuralvim / example_envattrs.py
Created May 28, 2019 03:05 — forked from doi-t/example_envattrs.py
Simple example of envattrs for aws lambda function
# echo '{}' > event.json; mkdir -p libs; pip install attrs envattrs -t libs; \
# export YOUR_PREFIX_SLACK_CHANNEL=your_project-staging; \
# export YOUR_PREFIX_S3_BUCKET=pyconapac-bucket; \
# export YOUR_PREFIX_THRESHOLD=50; \
# python-lambda-local -l libs/ -f handler -t 5 lambda_pyconapac.py event.json
from typing import Dict
import attr
import envattrs
@arthuralvim
arthuralvim / app.py
Created January 3, 2020 13:06 — forked from imwilsonxu/app.py
[Flask + Wtforms + Select2] #flask
# -*- coding: utf-8 -*-
from flask import Flask, request, render_template, current_app
from flask_wtf import Form
from wtforms.validators import DataRequired
from wtforms import SelectField, SelectMultipleField, SubmitField
app = Flask(__name__)
@arthuralvim
arthuralvim / scroll.py
Created January 22, 2020 13:50 — forked from hmldd/scroll.py
Example of Elasticsearch scrolling using Python client
# coding:utf-8
from elasticsearch import Elasticsearch
import json
# Define config
host = "127.0.0.1"
port = 9200
timeout = 1000
index = "index"
@arthuralvim
arthuralvim / AWS Lambda: Hello World.md
Created January 31, 2020 21:23 — forked from steinwaywhw/AWS Lambda: Hello World.md
An extremely simple AWS Lambda example in Python 3.

Preface

In general, AWS services can be accessed using

  1. AWS web interface,
  2. API libraries in a programming language, such as boto3 for Python 3,
  3. AWS command-line interface, i.e. awscli.

I opted for the API library since it is

@arthuralvim
arthuralvim / Dockerfile
Created February 5, 2020 12:33 — forked from katzefudder/Dockerfile
AWS CLI dockerized with Alpine Linux
FROM alpine:3.7
ENV AWSCLI_VERSION "1.14.10"
RUN apk add --update \
python \
python-dev \
py-pip \
build-base \
&& pip install awscli==$AWSCLI_VERSION --upgrade --user \
@arthuralvim
arthuralvim / ansible-aws-inventory-worker.yml
Created February 13, 2020 14:03 — forked from nivleshc/ansible-aws-inventory-worker.yml
Ansible Inventory Worker file. This is the file which actually carries out all the inventory tasks. It is called by the main file
# Name: ansible-aws-inventory-worker.yml
# Description: this is the worker file that called the main file (ansible-aws-inventory-main.yml) to to create an inventory of all the
# specific aws resources. This file, the worker file and the ansible inventory file must be placed in the same folder
# Prerequisites:
# - the worker file (ansible-aws-inventory-worker.yml) and the ansible hosts file must be present in the same folder as this file (ansible-aws-inventory-main.yml)
# - this script requires read access to all resources it will be querying. An AWS IAM user account must be created with the necessary permissions and with access keys enabled.
# At a minimum, to query all the resources mentioned above, the following permissions are required
# - AmazonVPCReadOnlyAccess
# - AmazonEC2ReadOnlyAccess
# - ElasticLoadBalancingReadOnly
@arthuralvim
arthuralvim / ansible-aws-inventory-main.yml
Created February 13, 2020 14:03 — forked from nivleshc/ansible-aws-inventory-main.yml
The main inventory file - declare variables here. This calls the worker file (which must be prese
---
# Name: ansible-aws-inventory-main.yml
# Description: this is the main file that calls the worker file (ansible-aws-inventory-worker.yml) to create an inventory of all the
# specific aws resources.
# Below are the resources that will be inventoried
# - vpc
# - subnet
# - igw
# - cgw
# - vgw