Skip to content

Instantly share code, notes, and snippets.

@reisjr
reisjr / start-ec2.sh
Created April 1, 2017 00:09
AWS snippets
INSTANCE_ID=`aws ec2 run-instances --instance-type t2.micro \
--user-data file://user-data.sh \
--security-group-ids sg-569b5555 \
--instance-initiated-shutdown-behavior terminate \
--iam-instance-profile "Name=nonono" \
--image-id ami-0b33d91d \
--count 1 \
--key-name bastion-host \
--region us-east-1 --query "Instances[0].InstanceId" | sed 's/"//g'`
@reisjr
reisjr / prepare-lambda.sh
Created April 5, 2017 22:57
Prepare a lambda function
mkdir SampleLambdaFunction
chmod 644 SampleLambdaFunction.py
cp SampleLambdaFunction.py SampleLambdaFunction
cd SampleLambdaFunction
pip install "elasticsearch>=2.0.0,<3.0.0" -t .
pip install requests_aws4auth -t .
zip -9r ../SampleLambdaFunction.zip .
@reisjr
reisjr / mutiple_ips.sh
Created June 6, 2017 01:50
EC2 Multiple IPS
#Creting network interfaces - ENIs
aws ec2 create-network-interface --subnet-id subnet-002f9xxx
aws ec2 create-network-interface --subnet-id subnet-002f9xxx
#Getting EIPs
aws ec2 allocate-address
aws ec2 allocate-address
#Associating EIPs to ENIs
aws ec2 associate-address --network-interface-id eni-xxxxxxx --allocation-id eipalloc-xxxxxxxx
@reisjr
reisjr / optimistic_lock.py
Created June 26, 2017 13:49
DynamoDB - Optimistic Lock using timestamp
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table(ddb_table)
table.put_item(
Item={
'device_id': event['clientId'],
'timestamp': str(event['timestamp']),
'status': event['eventType']
},
ConditionExpression=':ts >= #ts_old OR attribute_not_exists(#ts_old)',
@reisjr
reisjr / install_parquet_tools.sh
Created July 7, 2017 17:39
Script to install parquet-tools in Amazon EC2
#!/bin/bash
wget http://mirror.nbtelecom.com.br/apache/maven/maven-3/3.5.0/binaries/apache-maven-3.5.0-bin.tar.gz
tar zxvf apache-maven-3.5.0-bin.tar.gz
sudo yum install -y git java-devel
git clone https://github.com/Parquet/parquet-mr.git
cd parquet-mr/parquet-tools/
sed -i 's/1.6.0rc3-SNAPSHOT/1.6.0/g' pom.xml
~/apache-maven-3.5.0/bin/mvn clean package -Plocal
java -jar target/parquet-tools-1.6.0.jar schema ~/000000_0
@reisjr
reisjr / update_sg_ip.sh
Created August 27, 2017 14:40
Update a security group adding a rule for SSH from the current IP.
#!/bin/bash
## Simple script to update the security group to allow ssh access from current IP.
## You can specify the Public DNS name of the instance that you want to access
## and it will update the first SG found. You can also setup a default SG and
## the script will update it and the DNS name is not informed.
SG="sg-xxxxxxxx"
REGION="us-east-1"
@reisjr
reisjr / rekog_det_labels.sh
Created September 23, 2017 01:42
Copy file to S3 and execute rekognition
#!/bin/bash
BUCKET="s3-temp-folder"
FILENAME=`basename $1`
aws s3 cp $1 s3://$BUCKET/
aws rekognition detect-labels --image "{ \"S3Object\" : { \"Bucket\" : \"$BUCKET\", \"Name\": \"$FILENAME\" } }" --min-confidence 80
@reisjr
reisjr / sample_paging.py
Created September 30, 2017 20:29
DynamoDB - Using Paginator
ddb_client = boto3.client("dynamodb", region_name='eu-west-1')
paginator = ddb_client.get_paginator("query")
pages = paginator.paginate(
TableName=TABLE_NAME,
ConsistentRead=False,
KeyConditionExpression="Identifier = :k",
ExpressionAttributeValues={
":k" : { "S" : key }
},
@reisjr
reisjr / setup_thing.sh
Created October 1, 2017 22:01
AWS IoT / Snippets
#!/bin/bash
SCRIPT=`basename "$0"`
if [ $# -eq 0 ]
then
echo "No arguments supplied"
echo "$SCRIPT thing-name"
exit
fi
@reisjr
reisjr / sqs_commands.sh
Last active March 8, 2019 16:20
AWS SQS - Working with message using bash
#!/bin/bash
#Setup
SQS_MAX_NUMBER_OF_MESSAGES=1 # Mensagens extraídas da fila por vez
SQS_WAIT_TIME_SECONDS=20 # Esperar quanto tempo por uma mensagem na fila
#Obtain queue URL
QUEUE_URL=$(aws sqs get-queue-url --queue-name "dreis-rampup-queue" --output text)
#Send message