我正在尝试学习AWS greengrass,因此我遵循了本教程https://docs.aws.amazon.com/greengrass/latest/developerguide/gg-gs.html,它逐步解释了如何在raspberry pi上设置greengrass,并使用lambda函数发布一些消息。在
一个简单的lambda函数如下:
import greengrasssdk
import platform
from threading import Timer
import time
# Creating a greengrass core sdk client
client = greengrasssdk.client('iot-data')
# Retrieving platform information to send from Greengrass Core
my_platform = platform.platform()
def greengrass_hello_world_run():
if not my_platform:
client.publish(topic='hello/world', payload='hello Sent from Greengrass Core.')
else:
client.publish(topic='hello/world', payload='hello Sent from Greengrass Core running on platform: {}'.format(my_platform))
# Asynchronously schedule this function to be run again in 5 seconds
Timer(5, greengrass_hello_world_run).start()
# Execute the function above
greengrass_hello_world_run()
# This is a dummy handler and will not be invoked
# Instead the code above will be executed in an infinite loop for our example
def function_handler(event, context):
return
在这里这是可行的,但是我试图通过使用lambda函数来做一些额外的工作来更好地理解它,例如打开一个文件并对其进行写入。在
我修改了greengrass_hello_world_run()
函数如下
我希望在部署时,运行在本地pi上的守护进程应该在给定的目录中创建该文件,因为我相信greengrass core试图在本地设备上运行这个lambda函数。但是它不创建任何文件,也不发布任何内容,因为我相信这段代码可能会被破坏。不知道怎么回事,我试着查看cloudwatch,但是我没有看到任何事件或错误被报告。在
如果你能帮上忙,我将不胜感激, 干杯!在
我想我找到了答案,我们必须在lambda环境中创建资源,并确保为访问该资源提供对lambda的读写访问权限。默认情况下,lambda只能访问
/tmp
文件夹。在这是文档的链接
https://docs.aws.amazon.com/greengrass/latest/developerguide/access-local-resources.html
关于这个的一些想法。。。在
如果在GG组设置中打开本地日志,它将开始在PI上本地写入日志。设置为:
日志位于:
/greengrass/ggc/var/log/system
如果
tail
的python_runtime.log
,则可以看到lambda执行中的任何错误。在如果要访问本地资源,则需要在GG组定义中创建一个资源。然后,您可以将此访问权限授予您可以在其中写入文件的卷。在
完成此操作后,您确实需要部署组才能使更改生效。在
相关问题 更多 >
编程相关推荐