5.3 Creating and Loading Lambda
The Getting Started with AWS IoT Greengrass developer guide needs to be followed to install and prepare the Greengrass core on the Raspberry Pi. The developer guide must be followed up to at least Module 3.
After the Greengrass procedure is completed, continue configuring the Lambda
            following these steps:
- Ensure the Greengrass core is not
                    active yet. To stop the core, open a new terminal window in RPi, go to the
                    location of the core, and perform a Stop command:
- press CTRL + ALT + T to open a new terminal window
 - enter ‘
cd /greengrass/ggc/core’ to open the location of the core - enter ‘
sudo ./greengrassd stop’ to stop the core 
 - The Lambda and its dependencies
                    are provided in the GitHub repository. Open the ‘AWS_Lambda’ folder and open the
                        ‘
lambda_function.py’ file with a text editor. - The ‘DEVICE’ variable represents
                    the MAC address of the RN4870 module and must be changed with the one obtained
                    in Command State. A MAC address has six bytes,
                    and a colon must be added between every byte:
DEVICE = 'D8:80:39:F3:75:59'
 - Archive the entire content of the
                    ‘AWS_Lambda’ folder as 
.zip, not the folder itself. Then, upload the archive to the cloud and deploy it on Raspberry Pi, as described in the AWS Greengrass tutorial Module 3. The topic used when creating the subscription is ‘BLE/data’. - By default, the RN4870 requires a
                    connection with authentication and, encryption and the BLE module from RPi does
                    not implement it by default. The name of the device responsible for BLE in RPi
                    will be ‘
hci0’ and using thehciconfigcommand will show the default state of the module:pi@raspberrypi:~ $ sudo hciconfig hci0 hci0: Type: Primary Bus: UART BD Address: B8:27:EB:09:B1:6A ACL MTU: 1021:8 SCO MTU: 64:1 UP RUNNING RX bytes:813 acl:0 sco:0 events:53 errors:0 TX bytes:2524 acl:0 sco:0 commands:53 errors:0The authentication with encryption must be activated using theencryptargument. Using the same command as above for module status checking, new ‘AUTH’ and ‘ENCRYPT’ functionalities can be observed:pi@raspberrypi:~ $ sudo hciconfig hci0 encrypt pi@raspberrypi:~ $ sudo hciconfig hci0 hci0: Type: Primary Bus: UART BD Address: B8:27:EB:09:B1:6A ACL MTU: 1021:8 SCO MTU: 64:1 UP RUNNING AUTH ENCRYPT RX bytes:827 acl:0 sco:0 events:55 errors:0 TX bytes:2534 acl:0 sco:0 commands:55 errors:0 - All the configurations have been
                    implemented, and the Greengrass core can start.
- press CTRL + ALT + T to open a new terminal window
 - enter ‘
cd /greengrass/ggc/core’ to open the location of the core - enter ‘
sudo ./greengrassd start’ to start the core 
Note: All of the above configurations must be followed only the first time when loading a new Lambda. After performing a Reset on the RPi board, only steps 5 and 6 need to be followed. 
