Skip to content

Instantly share code, notes, and snippets.

@arthuralvim
arthuralvim / aws_create_site.yml
Created Feb 19, 2020 — forked from ruzickap/aws_create_site.yml
Ansible playbook which creates instances and tag volumes
View aws_create_site.yml
---
- name: Create Instance in AWS
hosts: localhost
connection: local
gather_facts: false
vars:
aws_access_key: "xxxxxx"
aws_secret_key: "xxxxxx"
security_token: "xxxxxx"
@arthuralvim
arthuralvim / ansible-aws-inventory-main.yml
Created Feb 13, 2020 — forked from nivleshc/ansible-aws-inventory-main.yml
The main inventory file - declare variables here. This calls the worker file (which must be prese
View ansible-aws-inventory-main.yml
---
# 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
@arthuralvim
arthuralvim / ansible-aws-inventory-worker.yml
Created Feb 13, 2020 — 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
View ansible-aws-inventory-worker.yml
# 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 / Dockerfile
Created Feb 5, 2020 — forked from katzefudder/Dockerfile
AWS CLI dockerized with Alpine Linux
View Dockerfile
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 / AWS Lambda: Hello World.md
Created Jan 31, 2020 — forked from steinwaywhw/AWS Lambda: Hello World.md
An extremely simple AWS Lambda example in Python 3.
View AWS Lambda: Hello World.md

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 / Ec2MetricsPolicy.json
Created Jan 29, 2020
Ec2MetricsPolicy for Cloudwatch monitoring.
View Ec2MetricsPolicy.json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "SendDataCW",
"Effect": "Allow",
"Action": [
"cloudwatch:PutMetricData",
"ec2:DescribeTags",
"cloudwatch:GetMetricStatistics",
@arthuralvim
arthuralvim / scroll.py
Created Jan 22, 2020 — forked from hmldd/scroll.py
Example of Elasticsearch scrolling using Python client
View scroll.py
# coding:utf-8
from elasticsearch import Elasticsearch
import json
# Define config
host = "127.0.0.1"
port = 9200
timeout = 1000
index = "index"
@arthuralvim
arthuralvim / ec2-user-bootstrap.sh
Created Jan 17, 2020
AWS EC2 Setup (Amazon Linux 2)
View ec2-user-bootstrap.sh
#!/bin/bash
sudo yum update
# AWS Monitoring Tool (Matches perfectly with an Instance)
sudo yum install -y perl-Switch perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https perl-Digest-SHA.x86_64
cd /home/ec2-user
curl https://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.2.zip -O
unzip CloudWatchMonitoringScripts-1.2.2.zip
rm CloudWatchMonitoringScripts-1.2.2.zip
(crontab -l 2>/dev/null; echo "*/5 * * * * /home/ec2-user/aws-scripts-mon/mon-put-instance-data.pl --mem-used-incl-cache-buff --mem-util --disk-space-util --disk-path=/ --from-cron") | crontab -
# Docker, Git, Python, Nginx
@arthuralvim
arthuralvim / app.py
Created Jan 3, 2020 — forked from imwilsonxu/app.py
[Flask + Wtforms + Select2] #flask
View app.py
# -*- 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__)
View cowsay-examples.md

sudo apt-get install cowsay fortunes

or

brew install cowsay fortune

cowsay -l
fortune | cowsay