accessing local shadows from withing lambda

0

I would like to access a local shadow inside a greengrass lambda

my lambda looks like:
import json
import logging
import platform
import sys
import os
from typing import ContextManager
from os.path import exists
import time, threading
import greengrasssdk

# Setup logging to stdout
logger = logging.getLogger(name)
logger.setLevel(logging.INFO)

# Creating a greengrass core sdk client
client = greengrasssdk.client("iot-data")
my_platform = platform.platform()
device = os.environ['AWS_IOT_THING_NAME']
_logger.info("initialising lambda for device:s " _ device)+

def sync_config():
_logger.info("TS> beep boop " _ device)+
try:
the_shadow = client.get_thing_shadow(thingName=device, shadowName="config1")
except BaseException as err:
logger.error(err)
threading.Timer(10, sync_config).start()

def dummy(event, context):
return { "green": "grass" }
sync_config()

everything goes well until I added the
the_shadow = client.get_thing_shadow(thingName=device, shadowName="config1")

i've installed the shadow manager component with the following configuration:

Component Name: aws.greengrass.ShadowManager
Version: 2.0.3
State: RUNNING
Configuration: {"rateLimits":{"maxLocalRequestsPerSecondPerThing":20.0,"maxOutboundSyncUpdatesPerSecond":100.0,"maxTotalLocalRequestsRate":200.0},"shadowDocumentSizeLimitBytes":8192.0,"synchronize":{"coreThing":{"classic":false,"namedShadows":["config1"]},"shadowDocuments":[]}}

config1 is a named shadow on my device
my lambda is installed with permissions like:

Component Name: mtdshadowconfiglambda-dev-sync_remote_config
Version: 1.0.135
State: BROKEN
Configuration: {"accessControl":{"aws.greengrass.ShadowManager":{"mtdshadowconfiglambda-dev-sync_remote_config::1":{"operations":["aws.greengrass#GetThingShadow","aws.greengrass#UpdateThingShadow","aws.greengrass#ListNamedShadowsForThing"],"policyDescription":"allow access to config# shadow","resources":["$aws/things/thingName/shadow/name/config1"]}}},"containerMode":"GreengrassContainer","containerParams":{"devices":{},"memorySize":16000.0,"mountROSysfs":false,"volumes":{}},"inputPayloadEncodingType":"json","lambdaExecutionParameters":{"EnvironmentVariables":{}},"maxIdleTimeInSeconds":60.0,"maxInstancesCount":100.0,"maxQueueSize":1000.0,"pinned":true,"pubsubTopics":{},"statusTimeoutInSeconds":60.0,"timeoutInSeconds":3.0}

what else do i need to do to get access to the shadow ?

when the lambda tries to run the get_thing_shadow function the log output shows (please note that i've removed some lines from the python code above to make it shorter, so the line numbers may not match):

2021-10-08T02:35:28.694Z [INFO] (pool-2-thread-175) mtdshadowconfiglambda-dev-sync_remote_config: handler.py:97,TS> beep boop smartdvr-1423019132001. {serviceInstance=0, serviceName=mtdshadowconfiglambda-dev-sync_remote_config, currentState=RUNNING}

==> greengrass.log <==
2021-10-08T02:35:28.709Z [ERROR] (nioEventLoopGroup-5-4) com.aws.greengrass.lambdamanager.LambdaRequestHandler: {}
com.aws.greengrass.lambdamanager.LambdaNotFoundException: Lambda arn:aws:lambda:::function:GGShadowService does not exist
at com.aws.greengrass.lambdamanager.WorkManager.appendWorkToLambda(WorkManager.java:297)
at com.aws.greengrass.lambdamanager.LambdaRequestHandler.handlePostWorkItem(LambdaRequestHandler.java:268)
at com.aws.greengrass.lambdamanager.LambdaRequestHandler.channelRead(LambdaRequestHandler.java:113)
at com.aws.greengrass.lambdamanager.lib.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at com.aws.greengrass.lambdamanager.lib.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at com.aws.greengrass.lambdamanager.lib.io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at com.aws.greengrass.lambdamanager.lib.io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
at com.aws.greengrass.lambdamanager.lib.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at com.aws.greengrass.lambdamanager.lib.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at com.aws.greengrass.lambdamanager.lib.io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at com.aws.greengrass.lambdamanager.lib.io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436)
at com.aws.greengrass.lambdamanager.lib.io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324)
at com.aws.greengrass.lambdamanager.lib.io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296)
at com.aws.greengrass.lambdamanager.lib.io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251)
at com.aws.greengrass.lambdamanager.lib.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at com.aws.greengrass.lambdamanager.lib.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at com.aws.greengrass.lambdamanager.lib.io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at com.aws.greengrass.lambdamanager.lib.io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
at com.aws.greengrass.lambdamanager.lib.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at com.aws.greengrass.lambdamanager.lib.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at com.aws.greengrass.lambdamanager.lib.io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
at com.aws.greengrass.lambdamanager.lib.io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
at com.aws.greengrass.lambdamanager.lib.io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719)
at com.aws.greengrass.lambdamanager.lib.io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
at com.aws.greengrass.lambdamanager.lib.io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
at com.aws.greengrass.lambdamanager.lib.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
at com.aws.greengrass.lambdamanager.lib.io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
at com.aws.greengrass.lambdamanager.lib.io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at com.aws.greengrass.lambdamanager.lib.io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:829)

==> mtdshadowconfiglambda-dev-sync_remote_config.log <==
2021-10-08T02:35:28.715Z [ERROR] (pool-2-thread-171) mtdshadowconfiglambda-dev-sync_remote_config: ipc_client.py:64,HTTP Error 404:Not Found, b'Lambda arn:aws:lambda:::function:GGShadowService does not exist'. {serviceInstance=0, serviceName=mtdshadowconfiglambda-dev-sync_remote_config, currentState=RUNNING}
2021-10-08T02:35:28.717Z [ERROR] (pool-2-thread-171) mtdshadowconfiglambda-dev-sync_remote_config: Lambda.py:149,HTTP Error 404: Not Found. {serviceInstance=0, serviceName=mtdshadowconfiglambda-dev-sync_remote_config, currentState=RUNNING}
2021-10-08T02:35:28.717Z [ERROR] (pool-2-thread-171) mtdshadowconfiglambda-dev-sync_remote_config: Traceback (most recent call last):. {serviceInstance=0, serviceName=mtdshadowconfiglambda-dev-sync_remote_config, currentState=RUNNING}
2021-10-08T02:35:28.717Z [ERROR] (pool-2-thread-171) mtdshadowconfiglambda-dev-sync_remote_config: File "/runtime/python/greengrass_ipc_python_sdk/ipc_client.py", line 59, in wrapped. {serviceInstance=0, serviceName=mtdshadowconfiglambda-dev-sync_remote_config, currentState=RUNNING}
2021-10-08T02:35:28.717Z [ERROR] (pool-2-thread-171) mtdshadowconfiglambda-dev-sync_remote_config: return func(*args, **kwargs). {serviceInstance=0, serviceName=mtdshadowconfiglambda-dev-sync_remote_config, currentState=RUNNING}
2021-10-08T02:35:28.717Z [ERROR] (pool-2-thread-171) mtdshadowconfiglambda-dev-sync_remote_config: File "/runtime/python/greengrass_ipc_python_sdk/ipc_client.py", line 192, in post_work. {serviceInstance=0, serviceName=mtdshadowconfiglambda-dev-sync_remote_config, currentState=RUNNING}
2021-10-08T02:35:28.718Z [ERROR] (pool-2-thread-171) mtdshadowconfiglambda-dev-sync_remote_config: response = urlopen(request). {serviceInstance=0, serviceName=mtdshadowconfiglambda-dev-sync_remote_config, currentState=RUNNING}
2021-10-08T02:35:28.718Z [ERROR] (pool-2-thread-171) mtdshadowconfiglambda-dev-sync_remote_config: File "/usr/lib/python3.6/urllib/request.py", line 223, in urlopen. {serviceInstance=0, serviceName=mtdshadowconfiglambda-dev-sync_remote_config, currentState=RUNNING}
2021-10-08T02:35:28.718Z [ERROR] (pool-2-thread-171) mtdshadowconfiglambda-dev-sync_remote_config: return opener.open(url, data, timeout). {serviceInstance=0, serviceName=mtdshadowconfiglambda-dev-sync_remote_config, currentState=RUNNING}
2021-10-08T02:35:28.718Z [ERROR] (pool-2-thread-171) mtdshadowconfiglambda-dev-sync_remote_config: File "/usr/lib/python3.6/urllib/request.py", line 532, in open. {serviceInstance=0, serviceName=mtdshadowconfiglambda-dev-sync_remote_config, currentState=RUNNING}
2021-10-08T02:35:28.718Z [ERROR] (pool-2-thread-171) mtdshadowconfiglambda-dev-sync_remote_config: response = meth(req, response). {serviceInstance=0, serviceName=mtdshadowconfiglambda-dev-sync_remote_config, currentState=RUNNING}
2021-10-08T02:35:28.718Z [ERROR] (pool-2-thread-171) mtdshadowconfiglambda-dev-sync_remote_config: File "/usr/lib/python3.6/urllib/request.py", line 642, in http_response. {serviceInstance=0, serviceName=mtdshadowconfiglambda-dev-sync_remote_config, currentState=RUNNING}
2021-10-08T02:35:28.718Z [ERROR] (pool-2-thread-171) mtdshadowconfiglambda-dev-sync_remote_config: 'http', request, response, code, msg, hdrs). {serviceInstance=0, serviceName=mtdshadowconfiglambda-dev-sync_remote_config, currentState=RUNNING}
2021-10-08T02:35:28.718Z [ERROR] (pool-2-thread-171) mtdshadowconfiglambda-dev-sync_remote_config: File "/usr/lib/python3.6/urllib/request.py", line 570, in error. {serviceInstance=0, serviceName=mtdshadowconfiglambda-dev-sync_remote_config, currentState=RUNNING}
2021-10-08T02:35:28.719Z [ERROR] (pool-2-thread-171) mtdshadowconfiglambda-dev-sync_remote_config: return self._call_chain(*args). {serviceInstance=0, serviceName=mtdshadowconfiglambda-dev-sync_remote_config, currentState=RUNNING}
2021-10-08T02:35:28.719Z [ERROR] (pool-2-thread-171) mtdshadowconfiglambda-dev-sync_remote_config: File "/usr/lib/python3.6/urllib/request.py", line 504, in _call_chain. {serviceInstance=0, serviceName=mtdshadowconfiglambda-dev-sync_remote_config, currentState=RUNNING}
2021-10-08T02:35:28.719Z [ERROR] (pool-2-thread-171) mtdshadowconfiglambda-dev-sync_remote_config: result = func(*args). {serviceInstance=0, serviceName=mtdshadowconfiglambda-dev-sync_remote_config, currentState=RUNNING}
2021-10-08T02:35:28.719Z [ERROR] (pool-2-thread-171) mtdshadowconfiglambda-dev-sync_remote_config: File "/usr/lib/python3.6/urllib/request.py", line 650, in http_error_default. {serviceInstance=0, serviceName=mtdshadowconfiglambda-dev-sync_remote_config, currentState=RUNNING}
2021-10-08T02:35:28.719Z [ERROR] (pool-2-thread-171) mtdshadowconfiglambda-dev-sync_remote_config: raise HTTPError(req.full_url, code, msg, hdrs, fp). {serviceInstance=0, serviceName=mtdshadowconfiglambda-dev-sync_remote_config, currentState=RUNNING}
2021-10-08T02:35:28.719Z [ERROR] (pool-2-thread-171) mtdshadowconfiglambda-dev-sync_remote_config: urllib.error.HTTPError: HTTP Error 404: Not Found. {serviceInstance=0, serviceName=mtdshadowconfiglambda-dev-sync_remote_config, currentState=RUNNING}
2021-10-08T02:35:28.719Z [ERROR] (pool-2-thread-171) mtdshadowconfiglambda-dev-sync_remote_config: {serviceInstance=0, serviceName=mtdshadowconfiglambda-dev-sync_remote_config, currentState=RUNNING}
2021-10-08T02:35:28.719Z [ERROR] (pool-2-thread-171) mtdshadowconfiglambda-dev-sync_remote_config: During handling of the above exception, another exception occurred:. {serviceInstance=0, serviceName=mtdshadowconfiglambda-dev-sync_remote_config, currentState=RUNNING}
2021-10-08T02:35:28.719Z [ERROR] (pool-2-thread-171) mtdshadowconfiglambda-dev-sync_remote_config: {serviceInstance=0, serviceName=mtdshadowconfiglambda-dev-sync_remote_config, currentState=RUNNING}
2021-10-08T02:35:28.719Z [ERROR] (pool-2-thread-171) mtdshadowconfiglambda-dev-sync_remote_config: Traceback (most recent call last):. {serviceInstance=0, serviceName=mtdshadowconfiglambda-dev-sync_remote_config, currentState=RUNNING}
2021-10-08T02:35:28.719Z [ERROR] (pool-2-thread-171) mtdshadowconfiglambda-dev-sync_remote_config: File "/lambda/greengrasssdk/Lambda.py", line 131, in _invoke_internal. {serviceInstance=0, serviceName=mtdshadowconfiglambda-dev-sync_remote_config, currentState=RUNNING}
2021-10-08T02:35:28.720Z [ERROR] (pool-2-thread-171) mtdshadowconfiglambda-dev-sync_remote_config: invocation_id = self.ipc.post_work(function_arn, payload, client_context, invocation_type). {serviceInstance=0, serviceName=mtdshadowconfiglambda-dev-sync_remote_config, currentState=RUNNING}
2021-10-08T02:35:28.720Z [ERROR] (pool-2-thread-171) mtdshadowconfiglambda-dev-sync_remote_config: File "/runtime/python/greengrass_ipc_python_sdk/ipc_client.py", line 65, in wrapped. {serviceInstance=0, serviceName=mtdshadowconfiglambda-dev-sync_remote_config, currentState=RUNNING}
2021-10-08T02:35:28.720Z [ERROR] (pool-2-thread-171) mtdshadowconfiglambda-dev-sync_remote_config: raise IPCException(str(httpError)). {serviceInstance=0, serviceName=mtdshadowconfiglambda-dev-sync_remote_config, currentState=RUNNING}
2021-10-08T02:35:28.720Z [ERROR] (pool-2-thread-171) mtdshadowconfiglambda-dev-sync_remote_config: greengrass_ipc_python_sdk.ipc_client.IPCException: HTTP Error 404: Not Foundhandler.py:104,Failed to invoke function due to HTTP Error 404: Not Found. {serviceInstance=0, serviceName=mtdshadowconfiglambda-dev-sync_remote_config, currentState=RUNNING}

clogwog
asked 3 years ago208 views
1 Answer
0

apparently i'm using the v1 api instead of the v2 api ... so i'll try the v2 now..

clogwog
answered 3 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions