Alex
Alex

Reputation: 8313

Sending a message to AWS SQS Queue with AWS Lambda Python API Times out

I am trying to write to an SQS message in AWS Lambda using its Python API, but anything I try times out (I've run it for a minute but no success). I have SQS full access configured for the role. I can see the function logs get to the right place, yet the last line says

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

before it times out. I'm testing it using the test client within the AWS console.

The handler code is:

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)

It seems to always time out on retrieving the queue URL. Why is this and how do I actually prevent that from happening so I can write to the queue?

Upvotes: 5

Views: 10536

Answers (1)

Alex
Alex

Reputation: 8313

I had assigned this function to a VPC and associated subnets, which was preventing it from accessing external resources. Removing this resolved my issue.

Upvotes: 4

Related Questions