Skip to content

Instantly share code, notes, and snippets.

@reisjr
reisjr / IoTFactory.java
Created December 4, 2018 20:09
Provisioning an IoT Thing in Java
package org.reisjr.iot;
import java.util.Random;
import com.amazonaws.services.iot.AWSIot;
import com.amazonaws.services.iot.model.AttachPolicyRequest;
import com.amazonaws.services.iot.model.AttachThingPrincipalRequest;
import com.amazonaws.services.iot.model.CreateKeysAndCertificateRequest;
import com.amazonaws.services.iot.model.CreateKeysAndCertificateResult;
import com.amazonaws.services.iot.model.CreatePolicyRequest;
@reisjr
reisjr / create_attach_ebs.sh
Created June 1, 2018 22:01
Collection of EC2 snippets
#!/bin/bash
INSTANCE_ID=`curl http://169.254.169.254/latest/meta-data/instance-id` #para pegar o id da instância
VOL_ID=`aws ec2 create-volume --availability-zone us-east-1a --output text --query "VolumeId" --snapshot-id xxxxxxx --region us-east-1`
aws ec2 attach-volume --volume-id $VOL_ID --instance-id $INSTANCE_ID --device /dev/sdf --region us-east-1
@reisjr
reisjr / append_element_to_list.py
Last active May 29, 2018 23:57
DynamoDB - Collection of not "trivial" operations
#Append time to a list using face_id as key. Create list if it doesn't exist.
def log_event(face_id, similarity):
now = datetime.datetime.now()
create_dynamodb = dynamodb_events_table.update_item(
Key={
'FaceId': face_id,
'Timestamp': str(now.date())
},
@reisjr
reisjr / download_so_dump.sh
Last active December 22, 2021 21:57
Download stackoverflow dump
#!/bin/bash
DEST="dreis-datasets"
# Download files from https://archive.org/download/stackexchange
wget https://archive.org/download/stackexchange/stackoverflow.com-Badges.7z &
wget https://archive.org/download/stackexchange/stackoverflow.com-Comments.7z &
wget https://archive.org/download/stackexchange/stackoverflow.com-PostHistory.7z &
wget https://archive.org/download/stackexchange/stackoverflow.com-PostLinks.7z &
@reisjr
reisjr / Teste
Created October 6, 2017 13:21
URL Lab
https://s3.amazonaws.com/dreis-iot/immersion-day/IoT+ID+-+HOL+-+FIrst+Lab+-+Connecting+a+Device.pdf
@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
@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 / 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 / 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 / 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"