What is this?
If you find yourself needing to get files from S3 onto your Greengrass device feel free to use "the shovel".
Notes
This page contains a Greengrass Lambda function that can be used to grab a tar.gz or ZIP file from S3 and will copy it onto the host.
It uses the Greengrass ML Inference feature to accomplish this but it has nothing to do with machine learning. Greengrass ML Inference was designed to deliver large assets, usually related to machine learning, to Greengrass groups in a consistent way.
For reference the resource definitions I used while testing are at the bottom of this document.
What do you need to do?
- tar.gz compress or ZIP your asset
- Upload the asset to S3
- Give the Greengrass service role (not the Greengrass group role) permission to access the asset in S3
- For development purposes you can temporarily grant it read-only access to all S3 assets in your account using the managed policy with ARN
arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess - Create a Greengrass resource definition with two entries:
- The destination entry - this maps a local volume resource into the container with read-write permissions that the Lambda function will copy the assets into once they are downloaded
- The source entry - this is the S3 URI of the asset as well as the path that it should be extracted to inside of the Lambda function container
- Create a Greengrass function definition with these settings:
- Long running/pinned, so it runs immediately
- References both of the resource definition entries above
- Sets environment variable
AWS_IOT_THING_NAMEto the thing name of the Greengrass core thing - Sets environment variable
INPUT_PATHto the S3 resource's path. For example, if the S3 resource's path is/tmp/extractthenINPUT_PATHmust be/tmp/extract - Sets the environment variable
OUTPUT_PATHto the volume resource's destination path with an additional directory name appended to it. For example, if the volume resource's destination path is/roottmp/s3shoveltheOUTPUT_PATHcould be/roottmp/s3shovel/extracted. The volume resource's destination path and theOUTPUT_PATHcan not be the same. - Make sure that
ggc_userhas the correct permissions to create the output directory. The output directory is the source path of the volume resource plus the additional path information added toOUTPUT_PATH. I used/tmpas my source path soggc_userneeds to have the correct permissions to create/tmp/extractedon the host. - Use the shovel code below
S3ShovelPython3.py
Reference files
Test function definition
Test resource definition: