Skip to content

Instantly share code, notes, and snippets.

View prasanthnarasimha's full-sized avatar

Narasimha Prasanth Chintarlapalli Reddy prasanthnarasimha

View GitHub Profile
@prasanthnarasimha
prasanthnarasimha / gist:df679ae949a84db0eafb58d2ef8c9169
Created September 11, 2017 18:00 — forked from Saeven/gist:7832090
RAW Curl Post to AWS Kinesis with PHP
<?php
/*
POST / HTTP/1.1
Host: kinesis.<region>.<domain>
x-amz-Date: <Date>
Authorization: AWS4-HMAC-SHA256 Credential=<Credential>, SignedHeaders=content-type;date;host;user-agent;x-amz-date;x-amz-target;x-amzn-requestid, Signature=<Signature>
User-Agent: <UserAgentString>
Content-Type: application/x-amz-json-1.1
Content-Length: <PayloadSizeBytes>
"""
Given a dictionary, transform it to a string. Then byte encode that string. Then base64 encode it and since this will go
on a url, use the urlsafe version. Then decode the byte string so that it can be else where.
"""
data = base64.urlsafe_b64encode(json.dumps({'a': 123}).encode()).decode()
# And the decode is just as simple...
data = json.loads(base64.urlsafe_b64decode(query_param.encode()).decode())
# Byte encode the string, base64 decode that, then byte decode, finally transform it to a dictionary