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 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则