AWS Cloud9: Referencing Lambda Layer Locally

好久不见. 提交于 2020-02-21 10:49:08

问题


I have set-up a Cloud9 environment to develop and test lambda functions. To make the environment "cleaner" I have opted to use lambda layers to specify the function's dependencies. By doing this, I have removed the dependency folders from the environment, but I am now unable to test locally.

For example, I have a lambda layer for Stripe's python library. I am able to write a lambda function in Cloud9 referencing stripe, deploy the function, and successfully test the function remotely. But i am unable to run that function locally, as I get "unable to import stripe"

Is there a way to test a lambda function, that depends on a lambda layer, locally by specifying the layer ARN in Cloud9?


回答1:


Unfortunately, AWS Cloud9 does not support Lambda layers at the moment.




回答2:


AWS Cloud9 documentation says that is not supported to execute functions with layers from the AWS Resources window. But you can use sam local invoke or aws lambda on the Cloud9 terminal window. For instance

sam local invoke --event input.json --template ../template.yml <function_name>

will create a new docker image with the layer(s) dependencies that will be used to execute the lambda function. The TAG name is explained here

master:~/environment/ahdv (master) $ docker images
REPOSITORY          TAG                                    IMAGE ID            CREATED             SIZE
samcli/lambda       nodejs8.10-03eb754e9966a1a2f789d500d   6b52bcffdc2e        About an hour ago   968MB
lambci/lambda       python3.6                              420212d009b3        3 weeks ago         1.03GB
lambci/lambda       python2.7                              7a436931435e        3 weeks ago         901MB
lambci/lambda       nodejs4.3                              c0914066d9a8        3 weeks ago         931MB
lambci/lambda       nodejs6.10                             74b405a65ed4        3 weeks ago         946MB
lambci/lambda       nodejs8.10                             edf1f613772c        3 weeks ago         960MB


来源:https://stackoverflow.com/questions/54976291/aws-cloud9-referencing-lambda-layer-locally

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!