我有一个 AWS Lambda函数作为" Get-All-Project-Sessions
"使用API Getaway。如果我从API Rest客户端尝试,则返回响应。
Dev-Test-Lambda-Invoke
",代码:
import boto3
import json
def get_all_projects_session():
print("In function...")
client = boto3.client('lambda')
res = client.invoke(
FunctionName='cbr-all-projects-sessions',
InvocationType='RequestResponse',
Payload=json.dumps({'httpMethod': 'GET'})
)
print(res)
print("HTTPStatusCode: {}".format(res["ResponseMetadata"]["HTTPStatusCode"]))
print(res['Payload'])
response_pauload = res['Payload'].read()
return response_pauload
def lambda_handler(event, context):
try:
print("In Lambda Handler")
response = get_all_projects_session()
print(response)
return response
except Exception as err:
print("Exception1: {}".format(err))
return("Exception: {}".format(err))
return 'Hello from Lambda'
运行代码后,我将Time Out作为响应,因为Lambda函数在300 sec
之后超时,即5 minutes
。
我检查了Cloud Watch Log" Dev-Test-Lambda-Invoke
" Lambda函数只显示我在代码中打印的两个语句"In Lambda Handler" and "In function..."
我查看了Cloud Watch Log" Get-All-Project-Sessions" Lambda函数在代码之后在无限循环中运行,然后再次启动。但是当我从RESTClient调用API然后" Get-All-Project-Sessions"返回正确的答案。
任何想法?
答案 0 :(得分:-1)
对于调用lambda的boto3客户端,您应提及区域名称:
client = boto3.client('lambda', 'us-east-1')
然后继续您的代码。