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년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠