Custom component environment variables in GreengrassV2 for environment variables

0

We are trying to migrate some greengrass v1 services (both lambdas and those running as docker containers, though everything I have tested is with a lambda), and are having problems with some of our environmental variables that include part of a device specific UUID, for example of the form:

some/mqtt/{{DEVICE_UUID}}/topic

In some other environmental variables we are using the component environment variables as described in https://docs.aws.amazon.com/greengrass/v2/developerguide/component-environment-variables.html; so I've been trying to make this DEVICE_UUID also work in the same way, but as far as I can tell neither setenv nor the {configuration:/path} method of doing so works outside of the Lifecycle scripts section.

So far, with configuration similar too the following:

    configuration:
      ...
      DEVICE_UUID: "667788aa-bcde-ffee-1122-333344445555"
      ...

we have tried:

configuration:
	lambdaExecutionParameters:
		EnvironmentVariables:
	                "ATEST": "{configuration/DEVICE_UUID}",
	                "BTEST": "{configuration:/configuration/DEVICE_UUID}",
	                "CTEST": "{configuration:DEVICE_UUID}",
	                "DTEST": "{configuration:configuration/DEVICE_UUID}",
	                "ETEST": "{DEVICE_UUID}"

configuration:
	lambdaExecutionParameters:
		EnvironmentVariables:
        	        "ATEST": "\"{configuration/DEVICE_UUID}\"",
        	        "BTEST": "\"{configuration:/configuration/DEVICE_UUID}\"",
        	        "CTEST": "\"{configuration:DEVICE_UUID}\"",
        	        "DTEST": "\"{configuration:configuration/DEVICE_UUID}\"",
        	        "ETEST": "\"{DEVICE_UUID}\""

configuration:
	lambdaExecutionParameters:
		EnvironmentVariables:
	                "ATEST": "${configuration/DEVICE_UUID}",
	                "BTEST": "${configuration:/configuration/DEVICE_UUID}",
	                "CTEST": "${configuration:DEVICE_UUID}",
	                "DTEST": "${configuration:configuration/DEVICE_UUID}",
	                "ETEST": "${DEVICE_UUID}"

but they are always printed as shown in the first attempt ( '{DEVICE_UUID}' ).

Also, with configuration similar to following:

    configuration:
      ...
      SetEnv:
        DEVICE_UUID: "667788aa-bcde-ffee-1122-333344445555"
      ...

last option with $'s was retried, but same result.

Is there a way to do what we are trying to do without modifying the lambdas to assemble those variable themselves (or source them from a different file or something like that) or changing the variables by using something like ${AWS_IOT_THING_NAME}?

Thanks for any help.

scott
asked 9 months ago345 views
1 Answer
0

Hello,

As suggested by the expert can you kindly check the below documenttaion about recipe variables and set the "interpolateComponentConfiguration" configuration option to true:

[+]. https://docs.aws.amazon.com/greengrass/v2/developerguide/component-recipe-reference.html#recipe-variables

Also, kindly specify what is the issue you are observing while using "Setenv" as it should be under the lifecycle. Please refer the below documentation:

[+]. https://docs.aws.amazon.com/greengrass/v2/developerguide/component-recipe-reference.html#recipe-format

AWS
answered 9 months ago
profile picture
EXPERT
reviewed 4 months ago
  • interpolateComponentConfiguration was already set to true, though I didn't realize it was important for that:

    configuration:
      ...
      interpolateComponentConfiguration: true
    

    About Setenv; I was just trying everything I thought might work, I realized it probably wouldn't work outside the lifecycle section but tried it anyway since we couldn't get the recipe variables to work.

  • From the examples you’ve shown, it looks like you’re trying to place environment variables inside of a lambda’s config. This is a config inside of a config, which does not support interpolateComponentConfiguration. What is it exactly that you're trying to change, and how are you deploying this change? You’ll need to use the “merge” option when deploying to set the configuration you need for the component, with the device UUID.

    Eg:

    "MERGE": {
      "lambdaExecutionParameters": {
        "EnvironmentVariables": {
           "DEVICE_UUID": *the uuid value*
        }
      }
    }
    
  • What is it exactly that you're trying to change, and how are you deploying this change? - As I said trying to migrate lambda to component; we have a cloud side lambda (written by someone not working on the project anymore) which is calling GreengrassV2Client({}).send(new CreateComponentVersionCommand({lambdaFunction}) where lambdaFunction contains all the configuration including this; but this DEVICE_UUID can't be included at this time because it is for the component.

    We have separate code for deployment wihch is already merging configurations; that is how the effectiveconfig got configuration: ... DEVICE_UUID: "667788aa-bcde-ffee-1122-333344445555" ... and configuration: ... SetEnv: DEVICE_UUID: "667788aa-bcde-ffee-1122-333344445555" ... but we didn't want to have to modify the lambda code to account for the new environmental variable (since the topic is already a variable for the component) or do a find and replace on the configuration at deployment time.

    There is different hack we can do running a find and replace on $PREFIX-DEVICE_UUID to change it to the iot thing name, since that is actually what we are using except a few places where we only use the DEVICE_UUID in which case we will need to merge it to the configuration. I was just checking that there wasn't a proper way to add that as a variable that would work in the configuration the same was ${AWS_IOT_THING_NAME} is, but it seems not.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions