Thursday, December 22, 2016

AWS IoT and BeagleBone Green Wireless

This post demonstrates how to configure a BeagleBone Green Wireless for Amazon Web Services "Internet of Things" using the AWS CLI.

The ingredients:
  • AWS Account
  • BeagleBone Green Wireless (BBGW)
    • Working WiFi
    • Flashed w/image bone-debian-8.6-seeed-iot-armhf-2016-11-06-4gb.img
    • apt-get update
    • apt-get upgrade
Install AWS CLI on BBGW.  Perform the following steps:
  • Create a IAM user for the BeagleBone
    • download the access key ID/secret access key
  • Install AWS CLI
    • pip install awscli
  • Configure AWS CLI (using the access key ID/secret access key from above)
    • aws configure
  • Verify AWS CLI installation by performing simple command
    • aws s3 ls (s3 directories are returned)
Generate security certificates:
  • mkdir aws_certs
  • cd aws_certs
  • openssl genrsa -out privateKey.pem 2048
  • openssl req -new -key privateKey.pem -out cert.csr
  • aws iot create-certificate-from-csr --certificate-signing-request file://cert.csr --set-as-active > certOutput.txt
  • grep certificateId certOutput.txt
  • aws iot describe-certificate --certificate-id <certificateId from last step> --output text --query certificateDescription.certificatePem > cert.pem
Create a policy and attach generated certificate:
  • Create policy document (policy.doc)
    {
    "Version": "2012-10-17",
    "Statement": [{
    "Effect": "Allow",
    "Action":["iot:*"],
    "Resource": ["*"]
    }]
    }
  • aws iot create-policy --policy-name PubSubToAnyTopic --policy-document file://policy.doc
  • grep certificateArn certOutput.txt
  • aws iot attach-principal-policy --principal <certifcateArn from last step> --policy-name "PubSubToAnyTopic" 
At this point, you should be able to see the certificates/policy in the AWS console.  From the AWS IoT page, select "certificates" or "policies".
Alternatively, ask for certificates using AWS CLI:
  • aws iot list-certificates
Register your BeagleBone (thing) and attach to Principal (policy):
  • aws iot create-thing --thing-name bbgw
  • aws iot attach-thing-principal --thing-name bbgw --principal  <certifcateArn from previous step>
At this point you should be able to see the thing in the AWS console.  From the AWS IoT page, select "Registry/Things"
Alternatively, ask for things using AWS CLI:
  • aws iot list-things
Update BBGW status:
  • aws iot update-thing --thing-name bbgw --attribute-payload attributes={key1=value1}
Verify update:
  • aws iot list-things

No comments:

Post a Comment