-
Notifications
You must be signed in to change notification settings - Fork 10
/
REST_get_shadow.py
48 lines (40 loc) · 2.34 KB
/
REST_get_shadow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#------------------------------------------
#--- Author: Pradeep Singh
#--- Date: 2nd April 2017
#--- Version: 1.0
#--- Python Ver: Python 2.7
#--- Description: This code will fetch (GET) the Device Shadw State Doc(Json) from AWS IoT Platform
#---
#--- Refer to following Doc for AWS Device Shadow REST APIs -
#--- http://docs.aws.amazon.com/iot/latest/developerguide/thing-shadow-rest-api.html
#---
#--- Refer to following Document for information about AWS Sig 4 for REST API Calls
#--- http://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html#sigv4_signing-steps-summary
#------------------------------------------
import requests, datetime, sys
from aws_sig_ver_4 import get_HTTP_Request_Header
# ==================================================================
# CHANGE VALUES FOR FOLLOWING VARIABLES AS PER YOUR SETUP
ACCESS_KEY = "AKIAI24C6YR2W5LRYPYQ" # Create one from AWS IAM Module
SECRET_KEY = "Cc7DU8ij+COJn1xmQ3Z0GIf+aXICYxrpN5gUsW3R" # Create one from AWS IAM Module
IOT_ENDPOINT = "aujd0l630ek9p.iot.eu-central-1.amazonaws.com" # From AWS IoT Dashboard, go to "settings" to find your IoT Endpoint
AWS_REGION = "eu-central-1" # Your AWS Region. Full list at - http://docs.aws.amazon.com/general/latest/gr/rande.html#iot_region
HTTPS_ENDPOINT_URL = "https://aujd0l630ek9p.iot.eu-central-1.amazonaws.com" # Prefix your AWS IoT Endpoint with "https://"
IoT_THING_NAME = "RaspberryPi" # Put your AWS IoT Thing name here.
# ==================================================================
# OPTIONAL VARIABLES - FEEL FREE TO CHANGE IF YOU KNOW WHAT ARE THESE :-)
HTTPS_METHOD ="GET"
SHADOW_URI = "/things/" + IoT_THING_NAME + "/shadow" # Standard URL
HTTPS_REQUEST_PAYLOAD = ""
# ==================================================================
# Construct URL for Post Request
Request_Url = HTTPS_ENDPOINT_URL + SHADOW_URI
# Get HTTP Headers with AWS Signature 4 Signed Authorization Header
Request_Headers = get_HTTP_Request_Header(HTTPS_METHOD, IOT_ENDPOINT, AWS_REGION, SHADOW_URI, ACCESS_KEY, SECRET_KEY, HTTPS_REQUEST_PAYLOAD)
# Make HTTPS Request
HTTP_RESPONSE = requests.request(HTTPS_METHOD, Request_Url, data=HTTPS_REQUEST_PAYLOAD ,headers=Request_Headers)
# Print Response
print "\nHTTP Response Code:" + str(HTTP_RESPONSE.status_code)
print "Response:"
print HTTP_RESPONSE.text
# ==================================================================