aws-samples / aws-iot-rpi-fleet-provisioning

This CDK stack generates a custom raspbian image which uses AWS IoT Fleet Provisioning to automate onboarding of Raspberry Pi devices to AWS IoT Core.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

aws-iot-rpi-fleet-provisioning

This CDK stack generates a custom raspbian image which automates onboarding of Raspberry Pi devices to AWS IoT Core.

πŸ“‹ Table of content

πŸ”– Features

  • Create a custom raspbian based image which:
    • Enables connection to a WiFi network.
    • Sets a unique hostname for the device based on its Ethernet MAC address. As an example a Ethernet MAC address of dc:a6:32:01:23:45 will result in a hostname of dca632012345.
    • Requests a fully functional identity on first boot with the necessary IoT permissions that the device can use for subsequent communication with AWS IoT Core.

πŸŽ’ Pre-requisites

yarn -v && node -v

πŸš€ Install

1/ Create a secret to store the password for the Wifi network used by your devices

You can do it from the AWS console or from the command line:

aws secretsmanager create-secret --name RPI_WIFI_PASSWORD \
    --description "RaspberryPi Wifi Password" \
    --secret-string 'redacted'

2/ Update the stack configuration

Update the Wifi network SSID/country and public SSH key used to connect to your devices in the lib/utils/constants.ts file.

3/ Deploy the stack

Deploy this stack to your AWS account/region:

yarn && yarn build
yarn cdk deploy '*'

πŸ›  Usage

The CDK stack creates a CodePipeline which builds the custom raspbian image and stores it in S3.

Once the stack is deployed, you can check the progress of the pipeline in the AWS console. Once the pipeline is completed, download the custom raspbian image from S3 (Check the "Artifacts upload location" in the Codebuild project to find the S3 bucket).

Artifacts upload location

Unzip the image and write it on your Raspberry Pi sd card

unzip aws-raspbian.zip
# Find the SD card external disk
diskutil list external
# Write the image (replace /dev/disk123abcd with the name of the SD card external disk)
diskutil unmountDisk /dev/disk123abcd
sudo dd bs=1m if=aws-raspbian.img of=/dev/disk123abcd conv=sync

A Raspberry Pi booting using this image will automatically requests a fully functional identity on first boot with the necessary IoT permissions that the device can use for subsequent communication with AWS IoT Core (see rpi-image-builder/firstboot.bash).

AWS IoT Core console

Assuming you're on the same Wifi network as a device using this image, you can ssh into a device using its unique hostname and the SSH key you specified in the config:

# Replace dca632012345 with your device name
ssh pi@dca632012345.local

πŸ‘€ See also

Security

See CONTRIBUTING for more information.

License

This library is licensed under the Apache-2.0 License. See the LICENSE file.

About

This CDK stack generates a custom raspbian image which uses AWS IoT Fleet Provisioning to automate onboarding of Raspberry Pi devices to AWS IoT Core.

License:Apache License 2.0


Languages

Language:Python 56.0%Language:TypeScript 31.6%Language:Shell 10.7%Language:JavaScript 1.7%