Skip to content

Instantly share code, notes, and snippets.

View joaoferrao's full-sized avatar

João Ferrão joaoferrao

View GitHub Profile
@joaoferrao
joaoferrao / faust.py
Created May 29, 2019 09:39
quick faust code review
import faust
app = faust.App(id="test",broker="kafka://localhost:9092",store="memory://")
# convenience func for launching the app
def main() -> None:
app.main()
# Input topic, NOT managed by Faust. Marked
input_topic = app.topic('input', internal=False, partitions=1, value_type=str)
@joaoferrao
joaoferrao / caws_part_4.go
Created March 11, 2019 23:13
caws_part_4
func main() {
var resources []*SingleResource
for _, region := range TraceableRegions {
// We need to create a new CFG for each region. We
// could actually update the region after the fact
// but let's focus on the purpose, here :)
cfg := aws.Config{Region: aws.String(region)}
s := session.Must(session.NewSessionWithOptions(session.Options{
@joaoferrao
joaoferrao / caws_part_3.go
Created March 11, 2019 23:03
caws_part_3
// awsEC2 type is created for ARNs belonging to the EC2 service
type awsEC2 string
// awsECS type is created for ARNs belonging to the ECS service
type awsECS string
// awsGeneric is a is a generic AWS for services ARNs that don't have
// a dedicated type within our application.
type awsGeneric string
@joaoferrao
joaoferrao / caws_part_2.go
Created March 11, 2019 23:02
caws_part_2
// GetServiceFromArn removes the arn:aws: component string of
// the name and returns the first keyword that appears, svc
func ServiceNameFromARN(arn *string) *string {
shortArn := strings.Replace(*arn, "arn:aws:", "", -1)
sliced := strings.Split(shortArn, ":")
return &sliced[0]
}
// Short ARN removes the unnecessary info from the ARN we already
// know at this point like region, account id and the service name.
@joaoferrao
joaoferrao / caws_part_part_1.go
Last active July 25, 2022 16:33
caws_part_1
// TraceableRegions is a list of AWS regions we want to crawl
var TraceableRegions = [...]string{"us-east-1", "us-east-2", "us-west-1", "us-west-2", "ca-central-1", "eu-central-1", "eu-west-1", "eu-west-2", "eu-west-3", "eu-north-1", "ap-northeast-1", "ap-northeast-2", "ap-northeast-3", "ap-southeast-1", "ap-southeast-2", "ap-south-1", "sa-east-1"}
// SingleResource defines how we want to describe each AWS resource
type SingleResource struct {
Region *string
Service *string
Product *string
Details *string
ID *string
@joaoferrao
joaoferrao / caws.go
Last active February 12, 2023 15:47
AWS Resource Crawler
package main
import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/resourcegroupstaggingapi"
"github.com/olekukonko/tablewriter"
"os"
"strings"
@joaoferrao
joaoferrao / ecs_nlb.tf
Last active September 15, 2018 16:31
Terraform NLB served ECS service
# Following assumes you already have an ECS Cluster in place
resource "aws_lb" "this" {
name = "some-service-nlb"
load_balancer_type = "network"
internal = false
idle_timeout = "150"
subnets = "${var.subnet_list}"
}
@joaoferrao
joaoferrao / tweaked.py
Created September 7, 2018 16:15
etl - Tweaked version of sending message
# replaces _get_json_message()
def _get_json_messages_simulated(json_message):
msg = {}
if json_message is None:
return msg
if os.path.exists(json_message) and os.path.isfile(json_message):
try:
list_of_events = []
with open(json_message, 'r') as f:
@joaoferrao
joaoferrao / original_funcs.py
Last active September 7, 2018 16:13
etl - Original version of sending mensage
# Original Implementation
def _get_json_message(json_message):
msg = {}
if json_message is None:
return msg
if os.path.exists(json_message) and os.path.isfile(json_message):
try:
with open(json_message, "r") as in_file:
# from https://github.com/apache/incubator-airflow/blob/master/airflow/example_dags/tutorial.py
# -*- coding: utf-8 -*-
"""
### Tutorial Documentation
Documentation that goes along with the Airflow tutorial located
[here](https://airflow.incubator.apache.org/tutorial.html)
"""
import airflow
from airflow import DAG