【发布时间】:2018-01-30 05:41:41
【问题描述】:
我在使用简单的 Python Lambda 函数时遇到问题。 Lambda(由 Zapier 调用)函数基本上创建了一个 Confluence 页面并调用另一个 Zapier Webhook。我在我的 S3 中上传了一个 .zip 文件,其中包含所需包的所有文件夹,然后是一个 src 文件夹,其中包含我的 Python 文件,该文件具有我的处理程序函数。
.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 日志中出现以下错误:
【问题讨论】:
-
如果您需要帮助解决代码中的问题,您需要向我们展示代码。你是在让我们猜测你写了什么,然后告诉你应该写什么。
标签: python amazon-web-services aws-lambda