0

Can a lambda running on a AWS Greengrass Core device get access to its own "thing" name?

I can see there is thingArn in the config file installed on the device as part of it's installation but I'm not sure how to get access to that via the AWS libraries that are imported into the lambda function.

I can grant the access to the local file system and get it that way but would prefer a more elegant solution.

maksimov
  • 5,792
  • 1
  • 30
  • 38
Remotec
  • 10,304
  • 25
  • 105
  • 147

2 Answers2

2

The answer to this is yes.

The lambda's run time context has a set of environment variables which expose this data.

Remotec
  • 10,304
  • 25
  • 105
  • 147
  • 2
    Care to elaborate? I just dumped the context object vars and there's nothing in there that specifies the thing ARN. – et071385 Oct 29 '19 at 16:08
1

For posterity, the Greengrass runtime sets a number of environment variables which can be accessed just like any other environment variables in your client language of choice. For example, in Python you can do this in your Greengrass component/Lambda function:

import os

thing_name = os.getenv("AWS_IOT_THING_NAME")

https://docs.aws.amazon.com/greengrass/v2/developerguide/component-environment-variables.html

Troy Carlson
  • 2,965
  • 19
  • 26