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?

4
  • 1
    Did you place the Lambda function inside a VPC? Commented Dec 12, 2016 at 20:32
  • 1
    What worked exactly? VPCs don't have roles, so I'm not even sure what you are saying you did. Commented Dec 12, 2016 at 21:00
  • I removed the VPC assignment to the lambda function, I meant. Sorry for the confusion. Commented Dec 12, 2016 at 21:05
  • 1
    Possible duplicate of Why aws lambda within VPC can not send message to SNS? Commented Dec 12, 2016 at 21:33

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.