【问题标题】:Including markdown converter dependency in python AWS Lambda function在 python AWS Lambda 函数中包含降价转换器依赖项
【发布时间】:2017-04-18 04:41:06
【问题描述】:

我正在构建一个包以作为 AWS Lambda 函数上传。在尝试包含对 Markdown 2.6.8 的依赖项时,Markdown 的 python 实现。尝试测试该功能时,我收到错误 Unable to import module 'markdown-convert': No module named markdown。我从其他类似的问题中看到,我可能需要在 Amazon Linux 中编译依赖文件以使它们可用于 Lambda。我对 python 不熟悉,想知道我是否也应该探索将这段代码打包在一个 egg 中的方式,以及这是否会影响依赖项的导入方式。您建议我采取什么措施来尝试解决错误?

这是我的包的文件结构:

    .
    ├── markdown
    │   ├── blockparser.py
    │   ├── blockprocessors.py
    │   ├── extensions
    │   │   ├── abbr.py
    │   │   ├── admonition.py
    │   │   ├── attr_list.py
    │   │   ├── codehilite.py
    │   │   ├── def_list.py
    │   │   ├── extra.py
    │   │   ├── fenced_code.py
    │   │   ├── footnotes.py
    │   │   ├── headerid.py
    │   │   ├── __init__.py
    │   │   ├── meta.py
    │   │   ├── nl2br.py
    │   │   ├── __pycache__
    │   │   │   ├── abbr.cpython-34.pyc
    │   │   │   ├── admonition.cpython-34.pyc
    │   │   │   ├── attr_list.cpython-34.pyc
    │   │   │   ├── codehilite.cpython-34.pyc
    │   │   │   ├── def_list.cpython-34.pyc
    │   │   │   ├── extra.cpython-34.pyc
    │   │   │   ├── fenced_code.cpython-34.pyc
    │   │   │   ├── footnotes.cpython-34.pyc
    │   │   │   ├── headerid.cpython-34.pyc
    │   │   │   ├── __init__.cpython-34.pyc
    │   │   │   ├── meta.cpython-34.pyc
    │   │   │   ├── nl2br.cpython-34.pyc
    │   │   │   ├── sane_lists.cpython-34.pyc
    │   │   │   ├── smart_strong.cpython-34.pyc
    │   │   │   ├── smarty.cpython-34.pyc
    │   │   │   ├── tables.cpython-34.pyc
    │   │   │   ├── toc.cpython-34.pyc
    │   │   │   └── wikilinks.cpython-34.pyc
    │   │   ├── sane_lists.py
    │   │   ├── smart_strong.py
    │   │   ├── smarty.py
    │   │   ├── tables.py
    │   │   ├── toc.py
    │   │   └── wikilinks.py
    │   ├── __init__.py
    │   ├── inlinepatterns.py
    │   ├── __main__.py
    │   ├── odict.py
    │   ├── postprocessors.py
    │   ├── preprocessors.py
    │   ├── __pycache__
    │   │   ├── blockparser.cpython-34.pyc
    │   │   ├── blockprocessors.cpython-34.pyc
    │   │   ├── __init__.cpython-34.pyc
    │   │   ├── inlinepatterns.cpython-34.pyc
    │   │   ├── __main__.cpython-34.pyc
    │   │   ├── odict.cpython-34.pyc
    │   │   ├── postprocessors.cpython-34.pyc
    │   │   ├── preprocessors.cpython-34.pyc
    │   │   ├── serializers.cpython-34.pyc
    │   │   ├── treeprocessors.cpython-34.pyc
    │   │   ├── util.cpython-34.pyc
    │   │   └── __version__.cpython-34.pyc
    │   ├── serializers.py
    │   ├── treeprocessors.py
    │   ├── util.py
    │   └── __version__.py
    ├── Markdown-2.6.8.egg-info
    │   ├── dependency_links.txt
    │   ├── installed-files.txt
    │   ├── PKG-INFO
    │   ├── SOURCES.txt
    │   └── top_level.txt
    └── markdown-convert.py

markdown-convert.py的内容:

import markdown

def lambda_handler(event, context):
    parsedHTML = {}
    parsedHTML[u'text'] = markdown.markdown(event[u'text'])
    return parsedHTML

【问题讨论】:

    标签: python amazon-web-services aws-lambda egg


    【解决方案1】:

    这里的最佳建议是在本地开发机器上使用 virtualenv 并使用 pip 安装软件包。

    然后当你准备好了,通过递归复制<your-virtual-env>/lib/python2.7/site-packages/*的全部内容来制作lambda包。确保将内容放在 zip 包的根目录中。这很重要!

    请在此处找到更多详细信息:

    http://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html

    【讨论】:

      猜你喜欢
      • 2022-01-09
      • 1970-01-01
      • 1970-01-01
      • 2018-09-25
      • 2017-10-28
      • 1970-01-01
      • 1970-01-01
      • 2018-12-15
      • 1970-01-01
      相关资源
      最近更新 更多