2016-12-12 105 views
1

我正嘗試使用其Python API寫入AWS Lambda中的SQS消息,但是我嘗試超時(我已經運行了一分鐘但沒有成功)。我擁有爲角色配置的SQS完全訪問權限。我可以看到功能日誌得到正確的地方,但最後一行說使用AWS Lambda Python API向AWS SQS隊列發送消息時間戳

Starting new HTTPS connection (1): eu-west-1.queue.amazonaws.com 

它超時。我正在使用AWS控制檯中的測試客戶端進行測試。

的處理程序代碼是:

import boto3 
import logging 
import os 

logger = logging.getLogger() 
logger.setLevel(logging.DEBUG) 

QUEUE_NAME = os.getenv("QUEUE_NAME") 
SQS = boto3.client("sqs") 

def getQueueURL(): 
    """Retrieve the URL for the configured queue name""" 
    q = SQS.get_queue_url(QueueName=QUEUE_NAME).get('QueueUrl') 
    logger.debug("Queue URL is %s", QUEUE_URL) 
    return q 

def record(event, context): 
    """The lambda handler""" 
    logger.debug("Recording with event %s", event) 
    data = event.get('data') 
    try: 
     logger.debug("Recording %s", data) 
     u = getQueueURL() 
     logging.debug("Got queue URL %s", u) 
     resp = SQS.send_message(QueueUrl=u, MessageBody=data) 
     logger.debug("Send result: %s", resp) 
    except Exception as e: 
     raise Exception("Could not record link! %s" % e) 

它似乎總是在獲取隊列的URL超時。爲什麼是這樣,我怎樣才能真正防止這種情況發生,所以我可以寫入隊列?

+1

您是否將Lambda函數放入VPC中? –

+1

究竟是什麼工作? VPC沒有角色,所以我甚至不確定你在說什麼。 –

+0

我的意思是,我將VPC分配移到了lambda函數中。對困惑感到抱歉。 –

回答

0

我已將此函數分配給VPC和關聯的子網,這阻止了它訪問外部資源。刪除這個解決了我的問題。