5

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?

Alex
  • 8,093
  • 6
  • 49
  • 79
  • 1
    Did you place the Lambda function inside a VPC? – Mark B Dec 12 '16 at 20:32
  • 1
    What worked exactly? VPCs don't have roles, so I'm not even sure what you are saying you did. – Mark B Dec 12 '16 at 21:00
  • I removed the VPC assignment to the lambda function, I meant. Sorry for the confusion. – Alex Dec 12 '16 at 21:05
  • 1
    Possible duplicate of [Why aws lambda within VPC can not send message to SNS?](http://stackoverflow.com/questions/38188532/why-aws-lambda-within-vpc-can-not-send-message-to-sns) – Mark B Dec 12 '16 at 21:33

1 Answers1

4

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

Alex
  • 8,093
  • 6
  • 49
  • 79