S3 "shovel"

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_NAME to the thing name of the Greengrass core thing
    • Sets environment variable INPUT_PATH to the S3 resource's path. For example, if the S3 resource's path is /tmp/extract then INPUT_PATH must be /tmp/extract
    • Sets the environment variable OUTPUT_PATH to 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/s3shovel the OUTPUT_PATH could be /roottmp/s3shovel/extracted. The volume resource's destination path and the OUTPUT_PATH can not be the same.
  • Make sure that ggc_user has 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 to OUTPUT_PATH. I used /tmp as my source path so ggc_user needs to have the correct permissions to create /tmp/extracted on the host.
  • Use the shovel code below

S3ShovelPython3.py

Reference files

Test function definition

Test resource definition: