Publish your custom component

Publish your component to AWS for deployment to other devices

The previous section demonstrated how to create a local deployment of your component during development for testing. This section will demonstrate how to prepare your component for deployment to your devices in the field once you are happy with a particular version of your component.

Before we can deploy our component from the AWS cloud, we need to extend our recipe files to reference the components artifacts in S3 and then upload the components artifacts to S3. When a deployment is configured the device downloads the artifacts from S3.

  1. Create a bucket and retrieve your bucket name using the following command.
EPOCH_TIME=$(date -d '06/12/2012 07:21:22' +"%s") && S3_BUCKET=ggcv2-workshop-$HOSTNAME-$EPOCH_TIME && aws s3 mb s3://$S3_BUCKET
  1. Update your file: recipes/com.example.HelloWorld-1.0.0.json with the code below. Replace [YOUR BUCKET NAME] with the bucket name retrieved in the step 1. If needed again you can run echo $S3_BUCKET to retrieve it again.
{
   "RecipeFormatVersion": "2020-01-25",
   "ComponentName": "com.example.HelloWorld",
   "ComponentVersion": "1.0.0",
   "ComponentDescription": "My first AWS IoT Greengrass component.",
   "ComponentPublisher": "Amazon",
   "ComponentConfiguration": {
      "DefaultConfiguration": {
         "Message": "world"
      }
   },
"Manifests": [
      {
         "Platform": {
            "os": "linux"
         },
         "Lifecycle": null,
         "Run": "python3 -u {artifacts:path}/hello_world.py '{configuration:/Message}'\n",
         "Artifacts": [
            {
               "URI": "s3://[YOUR BUCKET NAME]/artifacts/com.example.HelloWorld/1.0.0/hello_world.py"
            }
         ]
      }
   ]
}
  1. Upload your component artifacts.
aws s3 cp --recursive /home/ubuntu/environment/GreengrassCore/ s3://$S3_BUCKET/
  1. (Optional) View your artifact upload in S3 Console

  2. Now that the component artifacts have been uploaded we will create the component definition in IoT Greengrass -> Components. To create your component definition run the following command.

Check out Troubleshooting section here If you encounter issues.

cd /home/ubuntu/environment/GreengrassCore/recipes && aws greengrassv2 create-component-version  --inline-recipe fileb://com.example.HelloWorld-1.0.0.json --region $AWS_DEFAULT_REGION

Upon execution you will get following similiar output:

{
    "arn": "arn:aws:greengrass:eu-west-1:xxxxxxxxxxxxxxxxx:components:com.example.HelloWorld:versions:1.0.0",
    "componentName": "com.example.HelloWorld",
    "componentVersion": "1.0.0",
    "creationTimestamp": 1617825194.539,
    "status": {
        "componentState": "REQUESTED",
        "message": "NONE",
        "errors": {}
    }
}

If you encounter An error occurred (AccessDeniedException) when calling the CreateComponentVersion operation: User: arn:aws:iam::123456789012:user/ is not authorized to perform: null. This error indicates that your recipe isn’t valid JSON or YAML. Check the syntax of your recipe, fix any syntax issues, and try again.You can use an online JSON or YAML syntax checker to identify syntax issues in your recipe. More details can be found in official Troubleshooting section here

  1. Component versions follow semantic versioning.

Component Uploaded - List

  • Once component is uploaded successfully to the cloud we will be able to see in Greengrass Console as below:

ScreenshotS9

  • You can also view your list of components using AWS CLI as, to retrieve this you can list use the command below change eu-west-1 if using different region.
aws greengrassv2 list-components --region eu-west-1

Read more about Component uploading here