Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# LoRaWAN / AWS IoT Demo
# Author: Gary Stafford
# Run AWS CLI commands after CloudFormation stack completes successfully
# variables
mkdir ${thingName}
aws iot create-keys-and-certificate \
--certificate-pem-outfile "${thingName}/${thingName}.cert.pem" \
--public-key-outfile "${thingName}/${thingName}.public.key" \
--private-key-outfile "${thingName}/${thingName}.private.key" \
# assuming you only have one certificate registered
certificate=$(aws iot list-certificates | jq '.[][] | .certificateArn')
## alternately, for a specific certificate if you have more than one
# aws iot list-certificates
## then change the value below
# certificate=arn:aws:iot:us-east-1:123456789012:cert/<certificate>
aws iot attach-policy \
--policy-name $thingPolicy \
--target $certificate
aws iot attach-thing-principal \
--thing-name $thingName \
--principal $certificate
aws iot create-thing-type \
--thing-type-name $thingType \
--thing-type-properties "thingTypeDescription=LoRaWAN IoT Gateway"
aws iot create-thing-group \
--thing-group-name $thingGroup \
--thing-group-properties "thingGroupDescription=\"LoRaWAN IoT Gateway Thing Group\", attributePayload={attributes={Manufacturer=RaspberryPiFoundation}}"
aws iot add-thing-to-thing-group \
--thing-name $thingName \
--thing-group-name $thingGroup
aws iot create-billing-group \
--billing-group-name $thingBillingGroup \
--billing-group-properties "billingGroupDescription=\"Gateway Billing Group\""
aws iot add-thing-to-billing-group \
--thing-name $thingName \
--billing-group-name $thingBillingGroup
aws iot update-thing \
--thing-name $thingName \
--thing-type-name $thingType \
--attribute-payload "{\"attributes\": {\"GatewayMfr\":\"RaspberryPiFoundation\", \"LoRaMfr\":\"REYAX\", \"LoRaModel\":\"RYLR896\"}}"
aws iot describe-thing \
--thing-name $thingName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment