Skip to content

Instantly share code, notes, and snippets.

@garystafford
Last active August 27, 2020 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garystafford/9f83d502a6a2f3d58530d2a59758b35b to your computer and use it in GitHub Desktop.
Save garystafford/9f83d502a6a2f3d58530d2a59758b35b to your computer and use it in GitHub Desktop.
# LoRaWAN / AWS IoT Demo
# Author: Gary Stafford
# Run AWS CLI commands after CloudFormation stack completes successfully
# variables
thingName=lora-iot-gateway-01
thingPolicy=LoRaDevicePolicy
thingType=LoRaIoTGateway
thingGroup=LoRaIoTGateways
thingBillingGroup=LoRaIoTGateways
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" \
--set-as-active
# 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