Passing Default Arguments in GreenGrass recipe, fails to do so on IoT Edge device

0

Problem passing arguments with non alpha chars, being 'ignored'

When I configure a component with an argument, as below "ComponentConfiguration": { "DefaultConfiguration": { "Slot": "1-2-3-4" } },

At the end, when the pythonscript is being launched using that argument, say: "Run": "python {artifacts:decompressedPath}/program/myscript.py "{configuration:/Slot}""

At the Edge device it is being passed as myscript 1 <------------missing -2-3-4

It seems documentation is missing, I need more arguments being passed into 'Slot' but not filtered by some unknown mechanism. How to solve it? Spaces and comma's have been tried already.

THANKS

enierop
demandé il y a 2 ans349 vues
2 réponses
1

Hi enierop,

First, can you check your <greengrass-install-dir>/config/config.tlog? This is a transaction log that contains all the configuration that has been applied.

By checking the config.tlog for Slot and your component lifecycle, you can see what Greengrass thinks is the value and what it will run:

e.g.

#  grep Slot /greengrass/v2/config/config.tlog
{"TS":1647492231773,"TP":["services","com.example.HelloWorld","configuration","Slot"],"W":"changed","V":"1-2-3-4"}
# grep Run /greengrass/v2/config/config.tlog
{"TS":1647492236124,"TP":["services","com.example.HelloWorld","lifecycle","Run"],"W":"changed","V":"python3 /greengrass/v2/packages/artifacts/com.example.HelloWorld/1.1.2/hello_world.py \"1-2-3-4\""}

Is it possible that you deployed an earlier version of your component that contained the "DefaultConfiguration" value of "1" for the Slot parameter?

Greengrass does not do any interpretation of the data when it replaces the values in the recipe. However, if you had previously set the default configuration to a value, like 1, then that value would be used unless the configuration is reset via a deployment.

If you change the DefaultConfiguration value from one version of a recipe to another, and you want that new default to be applied, in the deployment you must also add configuration to reset the config. For instance, in your deployment, if you configure the component with:

  "reset": [
    ""
  ]

it will reset all the applied configuration back to the defaults.


The following is my attempt to replicate your issue. I have installed Greengrass v2.5.3 and python3.8.10. I created a python3 script hello_world.py which contains the following:

import sys

message = "Hello, %s!" % sys.argv[1]
print(message)

I created a recipe that looks like:

{
  "RecipeFormatVersion": "2020-01-25",
  "ComponentName": "com.example.HelloWorld",
  "ComponentVersion": "1.1.2",
  "ComponentType": "aws.greengrass.generic",
  "ComponentDescription": "Hello world",
  "ComponentPublisher": "Me",
  "ComponentConfiguration": {
    "DefaultConfiguration": {
      "Slot": "1-2-3-4"
    }
  },
  "Manifests": [
    {
      "Platform": {
        "os": "linux"
      },
      "Name": "Linux",
      "Lifecycle": {
        "Run": "python3 {artifacts:path}/hello_world.py \"{configuration:/Slot}\""
      },
      "Artifacts": [
        {
          "Uri": "s3://<my_bucket_name>/hello_world.py",
          "Unarchive": "NONE",
          "Permission": {
            "Read": "OWNER",
            "Execute": "NONE"
          }
        }
      ]
    }
  ]
}

It prints out "Hello, 1-2-3-4!" when it runs:

2022-03-17T04:43:56.347Z [INFO] (Copier) com.example.HelloWorld: stdout. Hello, 1-2-3-4!. {scriptName=services.com.example.HelloWorld.lifecycle.Run, serviceName=com.example.HelloWorld, currentState=RUNNING}

When I change the value of "Slot" in the DefaultConfiguration and update the recipe and component version, using reset: [""] always makes it print the expected response.

AWS
Rob
répondu il y a 2 ans
0

Thanks, It once was "1" indeed. In the tlog it shows first as one {"TS":1646767501143,"TP":["services","com.mystuff","configuration","Slot"],"W":"changed","V":"1"}

Later it becomes {"TS":1646927815345,"TP":["services","com.mystuff","configuration","Slot"],"W":"timestampUpdated","V":null}

Unfortunately, the argument in Python, I used it the same as you, but it stays "1".

I will try your suggestions, though I must say, it does not make any sense to me that it does not detect argument changes. I will (need to) be doing this more often.

enierop
répondu il y a 2 ans
  • The configuration interpolation happens when the device receives the deployment. The "default" value is only applied to a component running on a device if that device does not have a configuration value applied to it already.

    Once a "default" value has been applied - it is stored in the configuration as the value for that configuration key - just as if you set that configuration value in a deployment. When you change the default value in the recipe, that won't change the value on your device as it still has the old value applied and no longer needs to lookup the value.

    You would need to deploy the new version along with the reset configuration.

    If the argument needs to change frequently without changing the code artifact - you may be better just deploying the change as a configuration via:

    merge: { 
    "Slot": "1-2-3-4'
    }
    

    Here's the documentation for merge and reset for more info: https://docs.aws.amazon.com/greengrass/v2/developerguide/update-component-configurations.html#merge-configuration-update

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions