Skip to content

Instantly share code, notes, and snippets.

@marcieltorres
marcieltorres / get_all_keys_redis_using_zrange.py
Created January 24, 2024 15:20
Get keys from redis using zrange and generate output csv file
import json
from timeit import default_timer as timer
import csv
from redis import ConnectionPool, Redis
__REDIS_HOST = ''
__PAGE_SIZE = 500
__OUTPUT_FILE_NAME = ''
from typing import List, Dict
from boto3 import resource
class SqsClient:
__slots__ = ['boto_resource', 'max_number_of_messages', 'pool_wait_time_seconds']
boto_resource: resource
max_number_of_messages: int
pool_wait_time_seconds: int
from boto3 import client
class S3Client:
__slots__ = ['boto_client', 'bucket_name', 'default_content_type', 'default_acl_type']
boto_client: client
bucket_name: str
default_content_type: str
default_acl_type: str
from typing import List
from confluent_kafka import Consumer, Message
from app.common.converters import try_convert_bytes_to_a_string
class KafkaConsumerClient:
__slots__ = ['servers',
'client_id',
from typing import Dict
from requests import Session
from requests.exceptions import RequestException
class BaseApiClient:
__slots__ = ['uri', 'timeout', 'headers', 'session']
uri: str
timeout: int
@marcieltorres
marcieltorres / get_address_by_cep.py
Created August 25, 2018 02:18
ViaCEP: AWS Lambda Function para buscar endereço através do CEP
import json
import urllib
import re
def lambda_handler(event, context):
if 'cep' in event and _regex(event['cep']):
return json.loads(urllib.request.urlopen(_get_url_api(event['cep'])).read())
return json.loads("{\"erro\": true, \"mensagem\": \"Formato incorreto\"}")
@marcieltorres
marcieltorres / s3-aws-lambda-function-trigger-object.py
Created August 25, 2018 02:15
AWS Lambda function to trigger objects
import boto3
import re
s3 = boto3.client('s3')
def lambda_handler(event, context):
if 'Records' in event:
bucket_object = event['Records'][0]['s3']['bucket']['name']
@marcieltorres
marcieltorres / aws-lambda-s3-validating-file.js
Created August 25, 2018 02:10
NodeJS: Validating s3 file with the AWS Lambda Function
//Using SDK
var aws = require('aws-sdk');
var s3 = new aws.S3();
//Define quais extensões serão aceitas no bucket
var _extensionsAllowed = ["txt", "csv"];
//Define tamanho máximo e mínimo que serão aceitos (em bytes)
var _minFileSize = 20; var _maxFileSize = (1024*1024*2);
@marcieltorres
marcieltorres / aws-lambda-s3-get-content-object.js
Created August 25, 2018 02:07
NodeJS: Getting the S3 object content with the AWS Lambda Function
var aws = require('aws-sdk');
var s3 = new aws.S3();
exports.handler = (event, context, callback) => {
//Verifica se o objeto existe (chamada através de evento no S3)
if ((event) && (event.Records) && (event.Records[0]) && (event.Records[0].s3) && (event.Records[0].s3.bucket) && (event.Records[0].s3.object)){
//Recupera informações de bucket e do objeto
var _bucket = event.Records[0].s3.bucket.name;
@marcieltorres
marcieltorres / aws-lambda-function-send-mail.js
Created August 25, 2018 02:05
NodeJS: Sending mail with AWS Lambda Function
var aws = require('aws-sdk');
exports.handler = (event, context, callback) => {
var _returnMessage = "";
var _destinationAddress, _sourceAddress = '[email protected]';
var _defaultSubject = '[Subject]';
var _defaultMessageData = '[Empty Message]';
//params SES