Skip to content

Instantly share code, notes, and snippets.

@gwincr11
Created June 29, 2016 21:55
Show Gist options
  • Save gwincr11/4770616e6bf66ad91db79e0d39eea36f to your computer and use it in GitHub Desktop.
Save gwincr11/4770616e6bf66ad91db79e0d39eea36f to your computer and use it in GitHub Desktop.
#!/bin/bash
# Create and configure a AWS IOT
#
set -e
echo -e "What is the device name? \c"
read NAME
# Create the IOT device
aws iot create-thing --thing-name $NAME
# setup IOT policy
# get device certificate
curl https://www.symantec.com/content/en/us/enterprise/verisign/roots/VeriSign-Class%203-Public-Primary-Certification-Authority-G5.pem > root.pem
# get AWS certificates
ARN=$(aws iot create-keys-and-certificate --set-as-active --certificate-pem-outfile cert.pem --public-key-outfile publicKey.pem --private-key-outfile privateKey.pem | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["certificateArn"]')
echo $ARN
# setup policy
aws iot attach-principal-policy --principal $ARN --policy-name "PubSubToAnyTopic"
# attach certificate to thing
aws iot attach-thing-principal --thing-name $NAME --principal $ARN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment