Skip to content

Instantly share code, notes, and snippets.

@youngsoul
youngsoul / secured_cognito_api.txt
Created March 12, 2020 01:30
output from a Cognito User Pool Secured API Gateway
POST https://XXX.execute-api.us-east-1.amazonaws.com/test/add-note
Content-Type: application/json
{"note":"Bring home milk"}
###
POST https://XXX.execute-api.us-east-1.amazonaws.com/test/add-note
HTTP/1.1 401 Unauthorized
@youngsoul
youngsoul / unsecured_cognito_api_output.txt
Created March 12, 2020 00:51
Output from hitting the unsecured Cognito API Endpoint
POST https://XXX.execute-api.us-east-1.amazonaws.com/test/add-note
Content-Type: application/json
{"note":"Bring home milk"}
###
POST https://XXX.execute-api.us-east-1.amazonaws.com/test/add-note
HTTP/1.1 500 Internal Server Error
@youngsoul
youngsoul / cognito_token_lambda.py
Last active March 12, 2020 00:47
Python Lambda function receiving a Cognito token and getting the claims from it
import logging
import json
from jose import jwt
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
def lambda_handler(event, context):
logger.debug("Add Note Lambda")
@youngsoul
youngsoul / cognito_login.py
Created March 11, 2020 22:10
snippet showing how to have a user login into a Cognito User Pool
resp=client.initiate_auth(
ClientId=os.getenv('CLIENT_ID'),
AuthFlow='USER_PASSWORD_AUTH',
AuthParameters={
'USERNAME': email,
'SECRET_HASH': get_secret_hash(email, os.getenv('CLIENT_ID'), os.getenv('CLIENT_SECRET')),
'PASSWORD': password,
})
return resp
@youngsoul
youngsoul / cognito_confirm_sign_up.py
Created March 11, 2020 21:47
snippet showing how to confirm a sign up with Coginto
resp = client.confirm_sign_up(
ClientId = os.getenv('CLIENT_ID'),
SecretHash=get_secret_hash(email, os.getenv('CLIENT_ID'), os.getenv('CLIENT_SECRET')),
Username=email,
ConfirmationCode=code,
ForceAliasCreation=False
)
@youngsoul
youngsoul / cognito_client_sign_up.py
Last active March 11, 2020 21:22
snippet showing how to use the AWS Cognito client to sign_up to a user pool.
resp = client.sign_up(
ClientId = os.getenv('CLIENT_ID'),
SecretHash=get_secret_hash(email, os.getenv('CLIENT_ID'), os.getenv('CLIENT_SECRET')),
Username=email,
Password=password,
UserAttributes=[
{
"Name": "custom:favorite_band",
"Value": favorite_band
},
@youngsoul
youngsoul / automl_bank_client.py
Created March 5, 2020 19:25
Sample Python client for Azure AutoML Model Endpoint
import requests
import json
import pandas as pd
# URL for the web service
scoring_uri = 'http://SOME ID.centralus.azurecontainer.io/score'
# If the service is authenticated, set the key or token
key = 'SOME KEY'
@youngsoul
youngsoul / Install OpenCV 4.1.0 on Buster Raspbian.sh
Created June 27, 2019 03:26
Script / set of instructions for how to install OpenCV 4.1.0 on the Buster version of Raspbian for the Raspberry PI.
# script or instructions to install opencv 4.1.0
# on raspberry pi with buster version of raspbian
sudo apt-get -y update
sudo apt-get -y upgrade
sudo apt-get -y install screen
sudo apt-get -y install htop
# -------------------
# run screen command to put window in background
@youngsoul
youngsoul / Install Python 3.6.6 on Raspberry PI.txt
Created May 1, 2019 17:53
Steps to install Python 3.6.6 on Raspberry PI
# create file on RPI, copy contents to a .sh file and execute
# See Gist
# https://gist.github.com/dschep/24aa61672a2092246eaca2824400d37f
# setup
echo "Update RPI"
sudo apt-get -y update
sudo apt-get -y install build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev
# install python 3.6.6
@youngsoul
youngsoul / run_aws_py36_docker.sh
Created April 28, 2019 18:53
run script to create a docker environment for AWS Python 3.6
docker run --rm -it -e AWS_DEFAULT_REGION="$AWS_DEFAULT_REGION" -e AWS_ACCESS_KEY_ID="$AWS_ACCESS_KEY_ID" -e AWS_SECRET_ACCESS_KEY="$AWS_SECRET_ACCESS_KEY" -v "$PWD":/var/task lambci/lambda:build-python3.6 bash