Lambda can't send message to SQS

Viewed 1239

I'm having trouble sending a message to my SQS queue from my lambda function. Here's my setup

  • Lambda is connected to 3 public subnets in the default VPC
  • A VPC endpoint for SQS exists

I'm trying to send a message via boto3 using the following:

import json
import boto3

sqs = boto3.client("sqs")
sqs.send_message(
    QueueUrl="https://sqs.eu-west-1.amazonaws.com/012345678901/my_queue",
    MessageBody=json.dumps({"message": "hello"}),
)

The lambda is timing out (60s). While debugging, I noticed that the boto3 client is connecting to eu-west-1.queue.amazonaws.com rather than sqs.eu-west-1.amazonaws.com, which I specified in the QueueUrl parameter. Through further debugging, I noticed that eu-west-1.queue.amazonaws.com resolves to a public address within the Lambda whereas sqs.eu-west-1.amazonaws.com resolves to a private address. I don't understand why this is happening.

1 Answers

I asked the same question on GitHub, so thanks to swetashre for answering me there. It turns out I needed to specify the endpoint URL when creating the SQS client.

sqs = boto3.client("sqs", endpoint_url="https://sqs.eu-west-1.amazonaws.com")
Related