Skip to content

Instantly share code, notes, and snippets.

@coisme
Last active February 14, 2022 04:01
Show Gist options
  • Save coisme/cab0daa6cd7abe5d45abfa492d815caa to your computer and use it in GitHub Desktop.
Save coisme/cab0daa6cd7abe5d45abfa492d815caa to your computer and use it in GitHub Desktop.
Set up Greengrass to Raspberry Pi Zero W

Basically, follows this document: https://docs.aws.amazon.com/greengrass/latest/developerguide/quick-start.html

Set up Raspberry Pi

Install Raspberry Pi OS

Download Raspberry Pi Imager and write Raspberry Pi OS (32-bit) image to your SD card. https://www.raspberrypi.org/software/

Enable ssh

Add empty file with filename ssh under the /boot.

$ touch /Volumes/boot/ssh

Set up Wi-Fi

Add wpa_supplicant.conf to /boot with this contents:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=JP

network={
	ssid="YOUR_SSID"
	psk="YOUR_PASSWORD"
}

Boot

Set SD card to your Rapberry Pi Zero W and power it up. Connect to your raspberry pi with ssh.

ssh pi@raspberrypi.local

Update

Run this command to update.

$ sudo apt update
$ sudo apt upgrade

Prepare AWS

Create IAM user

Create an IAM user for Greengrass in IAM user service with Programmatic access Access type, and then attach AdministratorAccess policy to it.

You'll get its Access Key ID and Secret access key.

Download and start the script

Set Access Key ID and Secret access key to your environment variables.

$ export AWS_ACCESS_KEY_ID=AKxxxxxxxxxxxxxxxx
$ export AWS_SECRET_ACCESS_KEY=Ci+5yyyyyyyyyyyyyyyyyyyyyyyyyy

Run this command:

$ curl https://d1onfpft10uf5o.cloudfront.net/greengrass-device-setup/downloads/gg-device-setup-latest.sh > gg-device-setup-latest.sh && chmod +x ./gg-device-setup-latest.sh && sudo -E ./gg-device-setup-latest.sh bootstrap-greengrass-interactive 

In the middle, you'll be prompted to reboot. Then reboot.

$ sudo reboot -h now

After reboot, set your credential again:

$ export AWS_ACCESS_KEY_ID=AKxxxxxxxxxxxxxxxx
$ export AWS_SECRET_ACCESS_KEY=Ci+5yyyyyyyyyyyyyyyyyyyyyyyyyy

Restart the script.

$ sudo -E ./gg-device-setup-latest.sh bootstrap-greengrass-interactive

After setup done, you'll see these messages in the end:

You can now use the AWS IoT Console to subscribe 
to the 'hello/world' topic to receive messages published from your 
Greengrass core.

=======================================================================================

Verify

You can verify the Lambda function by following this guide: https://docs.aws.amazon.com/greengrass/latest/developerguide/lambda-check.html

Note that you need to choose the right region which you entered in your setup process.

To check what region is set up for your Raspberry Pi, run this command on your pi:

$ sudo cat /greengrass/config/config.json | grep Host
        "iotHost": "XXXXXXXXXXXX-ats.iot.us-west-2.amazonaws.com",
        "ggHost": "greengrass-ats.iot.us-west-2.amazonaws.com",
@dfquicazanr
Copy link

If you are using raspbian bullseye, install pip before you run the curl command. That command is not able to install pip and the whole installation fails because of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment