Getting group ID from inside a Lambda

0

I want to fetch certain metadata about my Greengrass group inside a (python) lambda running on the Greengrass Core. I see that the Core thing name is accessible from env var 'AWS_IOT_THING_NAME'. Whats the simplest and best way to get the Greengrass group ID of which it belongs?

I see there is a Greengrass Discovery HTTP API [1], is that the best approach? How would I construct requests to that API, do I need to add authorization headers etc?

I also see that there is an {'AWS_GG_MQTT_ENDPOINT': 'greengrass.iot.eu-central-1.amazonaws.com:8883'}, is that an MQTT variant of the above HTTP API or something different entirely?

[1] https://docs.aws.amazon.com/greengrass/latest/developerguide/gg-discover-api.html

Edit: Formatting
Edited by: andersgb on Jan 17, 2019 2:02 AM

Edited by: andersgb on Jan 17, 2019 2:04 AM

asked 5 years ago228 views
2 Answers
0

The Greengrass team do need to work on information given to local Lambda.

For now, as the group ID will never change, the simplest way would be to add the known Group ID to the Lambda Environmental Variables when setting up the function resource definition, such as the following:

response = greengrass_client.create_function_definition_version(
        FunctionDefinitionId=definition_id,
        Functions=[
            {
                'Id': 'somearn',
                'FunctionArn': 'somearn',
                'FunctionConfiguration': {
                    'Environment': {
                        'AccessSysfs': False,
                        'Variables': {
                            'GG_GROUP_ID': gg_group_id,
                            'LOG_LEVEL': 'debug'
                        },
                        'ResourceAccessPolicies': resource_access_policies,
                    },
                    'MemorySize': 512000,
                    'Pinned': True,
                    'Timeout': 30
                },
            }
        ]
    )

I assume it is is also possible to define environmental variables from the Greengrass console also,

Hope this helps,
Marty

answered 5 years ago
0

Thanks, that'll work. It will create some overhead in the group creation, but I guess I can live with that.

answered 5 years ago

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