RuntimeWarning:处理绝对导入时找不到父模块'src' - AWS Lambda

时间:2018-01-26 22:45:39

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

我遇到一个简单的Python Lambda函数问题。 Lambda(由Zapier调用)函数基本上创建了一个Confluence页面并召回另一个Zapier Webhook。我在我的S3中上传了一个.zip文件,其中包含了所有软件包的所有文件夹,然后是一个带有我的处理函数的Python文件的 src 文件夹。

.zip - > src / lambda_function.py然后我称之为处理函数。

在我的lambda_function.py的顶部,我有以下内容:

import string
import json
import pyconfluence as pyco
import requests
import os
import time

def create_page(name, content, label):
    data = {}
    data["type"] = "page"
    data["title"] = name
    data["ancestors"] = [{"id": str(12345678)}] #172949526 is the Parent
    data["space"] = {"key": "PK"}
    data["body"] = {"storage": {"value": content, "representation": "storage"}}
    data["metadata"] = {"labels": [{"name": label}]}
    return pyco.api.rest("/", "POST", json.dumps(data))

def lambda_handler(event, context):
    # Page 12345678 that is in fact a representation of the template
    content = pyco.get_page_content(12345678)
    page_title = event['issue_key'] + ": " + event['issue_title']
    content = string.replace(content, "PK-200", event['issue_key'])  
    create_page(page_title, content, "active-product-requirement")
    api_url = "https://acmein.atlassian.net/rest/api/2/issue/"+event['issue_key']+"/remotelink/"

    webhook = 'https://hooks.zapier.com/hooks/catch/123456/8v6fde/'

    requisite_headers = {'Accept': 'application/json',
                         'Content-Type': 'application/json'}
    auth = (os.environ["PYCONFLUENCE_USER"], os.environ["PYCONFLUENCE_TOKEN"])
    result = requests.get(api_url, headers=requisite_headers, auth=auth).json()

    if len(result) > 0:
        confluence_url = result[0]["object"]["url"]
    else:
        confluence_url = "Error getting the page"
    callback = requests.post(webhook, data={'issue_key': event['issue_key'], 'confluence_url': confluence_url })
    return ["Success"]

然后在我的CloudWatch日志中出现以下错误:

enter image description here

1 个答案:

答案 0 :(得分:0)

您必须压缩src文件夹的内容,而不是src文件夹本身。你的python模块(lambda_function.py)应该是你zip的第一级。 见documentation

  

压缩目录内容,而不是目录。 Zip文件的内容可用作Lambda函数的当前工作目录。

相关问题