Loading repository data…
Loading repository data…
aws-samples / repository
A step-by-step demonstration of how to automate an AWS IoT Greengrass setup with an AWS SDK for Python (Boto3). Supports a dive dive into a concept of a Greengrass Group and the AWS SDK calls to manage it.
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
This repository demonstrates how to build and deploy an IoT solution based on AWS IoT Greengrass by using AWS SDK for Python (Boto3).
Please note that the following guidelines assume that readers have previous experience with AWS IoT Greengrass.
When using this code sample, please also consider viewing a recording of a webinar "Create and Manage AWS IoT Greengrass Deployments with AWS SDK for Python (Boto3)" that introduces the related concepts. To request a webinar recording, please use this link.
The sample is intended for users who already have experience with AWS IoT Greengrass and want to deepen their knowledge in the management of AWS IoT Greengrass groups and deployments. Typical roles targeted by this workshop are Solution Architects and Software Developers.
Please consider this sample if you are interested in programmatically executing one or more of the following tasks:
By executing steps in a Jupyter notebook notebooks/build_and_deploy_coffee_monitoring_solution.ipynb, you will set up following resources in your AWS account:
The following figure provides an additional level of detail regarding the resources related to authentication (i.e. X.509 certificates and keys). Please consider the webinar recording for an explanation:
* Please use secure storage for private keys in any non-prototyping environment, considering the following documentation:
Above mentioned solution architecture will result in a solution with the following functions:
This sample consists of the following parts:
A Jupyter notebook in notebooks/build_and_deploy_coffee_monitoring_solution.ipynb allows a step-wise execution of the AWS SDK API calls to set up the architecture illustrated above. Please note: the explanations below assume the usage of Amazon SageMaker notebook instance as a runtime environment for the Jupyter notebook. However, you can also use your own Jupyter runtime for the execution of a code in the Jupyter notebook.
An AWS Lambda function to be deployed on a Greengrass device. You will find a source code of that AWS Lambda function in a coffeemachine_telemetryprocessor directory. The code for deployment of that AWS Lambda function is included in the Jupyter notebook mentioned above.
A script coffeemachine_devicesimulator/coffemachine_simulator.py to simulate data ingestion from the coffee machines.
Please follow the steps listed below
Please follow the AWS IoT Greengrass developer guide to install an AWS IoT Greengrass Core software on a supported environment, e.g.:
Please ensure that your environment fulfills the following preconditions:
Note: you can change the port number by adjusting a parameter HTTP_PORT in a file coffeemachine_telemetryprocessor/src/lambda.py
A configuration file, certificate, and private key necessary to start the AWS IoT Greengrass Core will be generated in Step 2 and installed in step 3.
Please note: storing private keys on a local file system is generally an insecure practice and is done in this code sample only for demonstrational purposes assuming prototypic usage. It should be only used in prototyping environments after a detailed risk analysis. The usage of that approach in any production environment is discouraged. Please use a secure storage for private keys in any non-prototyping environment, considering the following documentation:
A sample policy with is available under ARN arn:aws:iam::aws:policy/AmazonSageMakerFullAccessin AWS IAM. It provides full access to Amazon SageMaker via the AWS Management Console and SDK. It also provides select access to related services (e.g., S3, ECR, CloudWatch Logs). Please review and adjust your policy as necessary.
You may find further information on execution roles for Amazon SageMaker notebooks here
notebooks/build_and_deploy_coffee_monitoring_solution.ipynbAfter completion of Parts 1-12 of Jupyter notebook notebooks/build_and_deploy_coffee_monitoring_solution.ipynb please verify your deployment by
git clone https://github.com/aws-samples/aws-iot-greengrass-boto3
coffeemachine_devicesimulatorcd coffeemachine_devicesimulator
The following example assumes Ubuntu/Debian Linux, you may need to adjust it for other Linux distributions:
python3 -m pip install AWSIoTPythonSDK
sudo apt-get install jq
mkdir -p certs
wget -O certs/AmazonRootCA1.pem https://www.amazontrust.com/repository/AmazonRootCA1.pem
coffeemachine_devicesimulator directory.tar xzvf <Number>-devices_config.tgz
As a result of this command the following files should be places in the certsdirectory :
certs/CoffeeMachine_1.key
certs/CoffeeMachine_2.public.key
certs/CoffeeMachine_1.public.key
certs/CoffeeMachine_2.key
certs/CoffeeMachine_1.pem
certs/CoffeeMachine_2.pem
Please note: storing private keys on a local file system is generally an insecure practice and is done in this code sample only for demonstrational purposes assuming prototypic usage. It should be only used in prototyping environments after a detailed risk analysis. The usage of that approach in production environments is urgently discouraged. Please use a secure storage for private keys in any non-prototyping environment, considering the following documentation:
./coffemachine_simulator.sh CoffeeMachine1 certs/CoffeeMachine_1.pem certs/CoffeeMachine_1.key 1
./coffemachine_simulator.sh CoffeeMachine2 certs/CoffeeMachine_2.pem certs/CoffeeMachine_2.key 2
This library is licensed under the MIT-0 License. See the LICENSE file.