Skip to content

Instantly share code, notes, and snippets.

Avatar

Felipe Garcia rhossi

View GitHub Profile
@rhossi
rhossi / ami-backup.py
Created Aug 11, 2016
Lambda function to create AMIs of EC2 instances
View ami-backup.py
import boto3
def lambda_handler(event, context):
client = boto3.client('ec2')
filters = [{'Name':'tag:Backup-AMI', 'Values':['yes']}]
instances = client.describe_instances(Filters=filters)
if instances and instances['Reservations']:
View meli.py
from __future__ import print_function
from datetime import datetime
from urllib2 import urlopen
SITES = ['http://produto.mercadolivre.com.br/MLB-726627332-mini-pc-intel-nuc-i5-16gb-ssd-250-samsung-evo-5i5ryh-_JM', 'http://produto.mercadolivre.com.br/MLB-726629981-surface-4-pro-i5-8gb-ram-256-hd-teclado-e-mouse-_JM', 'http://produto.mercadolivre.com.br/MLB-716571875-iphone-6-plus-com-128gb-na-cor-space-gray-_JM'] # URL of the site to check
def lambda_handler(event, context):
try:
for num in range(1,10):
View local.js
{"message":"One or more parameter values were invalid: Condition parameter type does not match schema type","code":"ValidationException","time":"2015-08-19T12:50:48.382Z","statusCode":400,"retryable":false}
View error.js
[ { [InvalidParameterType: Expected params.ExpressionAttributeValues[':id'] to be a structure]
message: 'Expected params.ExpressionAttributeValues[\':id\'] to be a structure',
code: 'InvalidParameterType',
time: Wed Aug 19 2015 09:49:42 GMT-0300 (BRT) },
{ [UnexpectedParameter: Unexpected key '0' found in params.ExpressionAttributeValues[':id']]
message: 'Unexpected key \'0\' found in params.ExpressionAttributeValues[\':id\']',
code: 'UnexpectedParameter',
time: Wed Aug 19 2015 09:49:42 GMT-0300 (BRT) } ]
View local.js
var AWS = require('aws-sdk');
var dynamodb = new AWS.DynamoDB({apiVersion: '2012-08-10', region: 'us-east-1'});
var params = {
TableName: 'Produtos',
KeyConditionExpression: 'Id = :id',
ExpressionAttributeValues: {
':id' : '1'
}
View remotequery.js
var AWS = require('aws-sdk');
var dynamodb = new AWS.DynamoDB({apiVersion: '2012-08-10', region: 'us-east-1'});
var params = {
TableName: 'Produtos',
ExpressionAttributeValues: {
':id' : { 'S' : '1' }
},
KeyConditionExpression: 'Id = :id'
@rhossi
rhossi / s3upload.sh
Created Jul 30, 2015
Uploading files to S3 validating ContentMD5 using AWS CLI
View s3upload.sh
# (1) aws s3api put-object é padrão, tem a mesma sintaxe para Mac, Linux e Windows
# (2) openssl está disponível no Mac e no Linux, pode ser instalado no Windows com o cygwin
# (3) openssl dgst -md5 -binary demo-diebold.txt vai gerar o MD5 em binário do arquivo informado (ex: demo-diebold.txt)
# (4) openssl enc -base64 vai converter o valor informado para Base64
# (5) o | (pipe) faz a passagem do output da execução do comando 4 para o comando 5, e gera como ouput final o MD5 em Base64
# (6) a chamada $(openssl dgst -md5 -binary demo-diebold.txt | openssl enc -base64) que passamos para o --content-md5 é para primeiro gerar o hash MD5 em Base64 do arquivo, e então passar o output para o aws s3api put-object ser executado
aws s3api put-object --bucket megasenateste --key demo-diebold.txt --body ./demo-diebold.txt --content-md5 $(openssl dgst -md5 -binary demo-diebold.txt | openssl enc -base64)
@rhossi
rhossi / s3upload.js
Created Jul 30, 2015
Uploading files to S3 validating ContentMD5 using AWS SDK for Node.js
View s3upload.js
var aws = require('aws-sdk'),
fs = require('fs'),
crypt = require("crypto");
function getMD5HashFromFile(file){
var hash = crypt.createHash("md5")
.update(file)
.digest("base64");
return hash;
}
View gist:3611a7729b26e0aad4d6
q=(or genres:'Action')&q.parser=structured&fq=(or genres:'Adventure' genres:'Fantasy')
@rhossi
rhossi / resultset
Last active Aug 29, 2015
Resultado Query exemplo IMDB
View resultset
{
"status":{
"rid":"9Z+48u4oJQqVLio=",
"time-ms":15
},
"hits":{
"found":485,
"start":0,
"hit":[
{
You can’t perform that action at this time.