在我的lambda执行函数开头连接到必需的AWS资源后,我有一个lambda_handler
函数,如下所示:
def lambda_handler(event, context, dst):
bucket = event['Records'][0]['s3']['bucket']['name']
key = urllib.unquote_plus(event['Records'][0]['s3']['object']['key'].encode('utf8'))
print('Bucket: %s' % bucket)
print('Object key: %s' % key)
crm_file_name = key.split('/')[-1]
crm_query = make_crm_db_query(crm_file_name)
cur = conn.cursor()
status = cur.execute(crm_query)
if status == 1:
details = cur.fetchone()
opportunity_id = details[0]
tmp = dst.get_key('%s/%s' % (opportunity_id, crm_file_name))
print('starting API request...')
s = requests.Session()
r = s.post('http://link/to/endpoint/',\
files={'pdf': tmp}, data={'opportunity_id': opportunity_id})
print(r)
print(r.content)
else:
print('not the right file type')
在我的开发环境中,这会返回以下内容,表明帖子成功了:
starting API request...
<Response [201]>
{"opportunity_id":253,"pdf":"https://s3.storage.asset.com:443/253/253___PDF.pdf?Signature=[CONFIDENTIAL STUFF HERE ;)]"}
在AWS Cloud Watch日志中,尝试执行发布请求时,该过程会挂起。这是一个日志样本:
starting API request...
END RequestId: beedb0c4-ce07-11e6-a715-53b3bd8edccc
REPORT RequestId: beedb0c4-ce07-11e6-a715-53b3bd8edccc Duration: 30002.89 ms Billed Duration: 30000 ms Memory Size: 128 MB Max Memory Used: 22 MB
2016-12-29T20:46:24.356Z beedb0c4-ce07-11e6-a715-53b3bd8edccc Task timed out after 30.00 seconds
S3存储桶,API端点和RDS都属于同一个VPC。该过程在dev中工作,但在生产中挂起。关于如何调试这个的任何指针?
我检查this post表示与外部互联网资源的连接需要NAT网关,但我们的API端点在同一VPC内的EC2实例上运行。 AWS是否认为我们仍在尝试建立外部连接,因为我们正在使用API调用?我该如何调试呢?