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

已提問 5 年前檢視次數 237 次
2 個答案
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

已回答 5 年前
0

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

已回答 5 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南