-
Notifications
You must be signed in to change notification settings - Fork 0
/
aws_iot_configure.sh
44 lines (37 loc) · 1.61 KB
/
aws_iot_configure.sh
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
#!/bin/sh
##########################################################################
# EXECUTION CMD:: sh aws_iot_configure.sh #
# PREREQUISITE: aws cli with credential #
# Owner:- Rajesh Pal for Interview with Intelligent B, Dubai #
##########################################################################
#-----------------------------VARIABLE DECLERATIONS--------------------------------------------
TIME_STAMP="date +%Y-%m-%d.%H:%M:%S"
LOG_DIR=./
LOG_FILE=$LOG_DIR/device_provision_logs.log
POLICY_FILE="file://policy.json"
THING_TYPE="iotDevice"
POLICY_NAME="iot-policy"
#----------------------------CREATE THING TYPE AND POLICY --------------------------------------
#Create thing-type iotDevice
create_thing_type(){
aws iot create-thing-type --thing-type-name $THING_TYPE --thing-type-properties "thingTypeDescription=iot device type 1, searchableAttributes=device"
if [ $? -eq 0 ];
then
echo "[`$TIME_STAMP`] Thing type [$THING_TYPE] successfully created." 2>&1 | tee -a $LOG_FILE
else
echo "[`$TIME_STAMP`] Thing type [$THING_TYPE] creation failed" 2>&1 | tee -a $LOG_FILE
fi
}
#Create policy
create_policy(){
aws iot create-policy --policy-name $POLICY_NAME --policy-document $POLICY_FILE
if [ $? -eq 0 ];
then
echo "[`$TIME_STAMP`] Policy [$POLICY_NAME] successfully created" 2>&1 | tee -a $LOG_FILE
else
echo "[`$TIME_STAMP`] Policy [$POLICY_NAME] creation failed" 2>&1 | tee -a $LOG_FILE
fi
}
#-----------------------------------FUNCTION CALLS-------------------------------------
create_thing_type
create_policy