Data Services

New-file notifications through a dedicated SQS queue

For S3 deliveries, Synoptic can create an Amazon SQS queue just for you that receives a message each time a new file lands in your part of the delivery bucket. Your systems read the queue and fetch each file as soon as it arrives, instead of repeatedly listing the bucket.

The queue lives in our AWS account, and we set up everything that feeds it. You don't need an AWS account, and there's nothing to configure on your side beyond the code that reads it. If you'd rather receive notifications in a queue or topic you own, see Configuring S3 bucket in another account to notify SQS or SNS.

How it works

  1. A new file is written to the delivery bucket, for example under yourorg/.

  2. The bucket's event notification passes through a filter we keep for your queue. Only events for your files reach your queue: usually new objects under your prefix, but we can filter on other attributes too, such as event type.

  3. Your code receives the message, downloads the file it names, and deletes the message.

Your access covers receiving and deleting messages on your queue, and reading files under your prefix. You can't see or affect anyone else's queue, files or notifications, and nobody else can see yours.

Getting set up

Contact us at support@synopticdata.com or through your Synoptic contact, and tell us:

  • How you'll authenticate: an AWS role, an Azure managed identity, a Google Cloud service account, certificates from your own CA, or an access key. See .

  • What you want to hear about: normally every new file under your prefix. Tell us if you only want some of them, such as one file type.

We send you a connection guide with your queue ARN, the bucket and prefix, and code for your authentication method. Each example below starts from that method's session.

What a message looks like

Each message body is the S3 event itself, as JSON. It's delivered raw, not wrapped in an SNS notification, so there's no Type, TopicArn or Message envelope to unpack: parse the body and you have the event. The fields you'll usually need are the bucket name and the object key:

JSON
{
  "Records": [
    {
      "eventVersion": "2.1",
      "eventSource": "aws:s3",
      "awsRegion": "us-west-2",
      "eventTime": "2026-11-10T06:00:04.512Z",
      "eventName": "ObjectCreated:Put",
      "s3": {
        "bucket": {"name": "synoptic-delivery-yourorg-example-a1b2c"},
        "object": {
          "key": "yourorg/20261110/obs.20261110060000.json",
          "size": 48213,
          "eTag": "9b2cf535f27731c974343645a3985328",
          "sequencer": "0065A1B2C3D4E5F601"
        }
      }
    }
  ]
}
  • Keys are URL-encoded in these events: a space arrives as +, and most punctuation as %XX. Decode them with urllib.parse.unquote_plus before using them.

  • Some deliveries route events through Amazon EventBridge, in which case the message has detail-type Object Created, and the key, unencoded, is in detail.object.key. The example below handles both; your connection guide says which you'll get.

  • Ignore anything else, such as an s3:TestEvent message when notifications are first set up.

Reading the queue

This loop long-polls the queue, downloads each new file, then deletes its message. Long polling waits up to 20 seconds for a message, so files are fetched within moments of arriving, without busy-waiting.

Python
import json
from pathlib import Path
from urllib.parse import unquote_plus

QUEUE_ARN = "<your queue ARN>"
DOWNLOADS = Path("downloads")

s3 = session.client("s3")
_, _, _, region, account, queue_name = QUEUE_ARN.split(":")
sqs = session.client("sqs", region_name=region)
queue_url = sqs.get_queue_url(QueueName=queue_name, QueueOwnerAWSAccountId=account)["QueueUrl"]


def new_objects(body):
    """(bucket, key) for each new object in one message."""
    event = json.loads(body)
    if "Records" in event:  # an S3 event notification
        for record in event["Records"]:
            if record.get("eventName", "").startswith("ObjectCreated:"):
                yield record["s3"]["bucket"]["name"], unquote_plus(record["s3"]["object"]["key"])
    elif event.get("detail-type") == "Object Created":  # through EventBridge
        yield event["detail"]["bucket"]["name"], event["detail"]["object"]["key"]


while True:
    response = sqs.receive_message(QueueUrl=queue_url, MaxNumberOfMessages=10, WaitTimeSeconds=20)
    for message in response.get("Messages", []):
        for bucket, key in new_objects(message["Body"]):
            target = DOWNLOADS / key
            target.parent.mkdir(parents=True, exist_ok=True)
            s3.download_file(bucket, key, str(target))
            print(f"downloaded s3://{bucket}/{key}")
        # Only once the file is safely downloaded: otherwise the message
        # comes back after its visibility timeout, and you can try again.
        sqs.delete_message(QueueUrl=queue_url, ReceiptHandle=message["ReceiptHandle"])

If a download fails, leave the message: it becomes visible again after its visibility timeout (30 seconds by default) and is received again. For files that take longer than that to handle, extend the timeout while you work:

Python
sqs.change_message_visibility(QueueUrl=queue_url, ReceiptHandle=message["ReceiptHandle"], VisibilityTimeout=300)

Good to know

  • Messages wait for you. The queue keeps messages for 14 days, so if your reader is down for a while, it catches up when it restarts.

  • At least once. A message can occasionally be delivered more than once, and messages aren't guaranteed to arrive in the order files were written. Make processing safe to repeat (downloading the same file twice is harmless), and sort by eventTime or key if order matters.

  • Several readers can share the queue, for example for throughput: each message goes to one of them at a time. If several separate systems each need every notification, ask us for a queue each.

  • Your queue is read by polling. Because it's in our account, it can't trigger an AWS Lambda function in yours directly. Run a small reader like the one above, which can then pass the files on to anything you like. Or, if you want events delivered into your own account, see Configuring S3 bucket in another account to notify SQS or SNS.

  • Encrypted: the queue uses SQS-managed encryption at rest, and every request goes over TLS.

  • Listing still works. Your read access lets you list your prefix too, for example to catch up on files from before your queue existed: see Amazon S3-based data delivery.

Troubleshooting

  • No messages: check you're reading the queue ARN in your connection guide, in its region. Then check new files are actually arriving under your prefix (list it). If they are and the queue stays empty, contact us: the filter may not match your files.

  • AccessDenied on download: the key is outside your prefix, or wasn't decoded. Use unquote_plus on keys from S3 events.

  • The same file again: a message wasn't deleted before its visibility timeout ran out, so it was delivered again. Delete each message once its file is handled, and extend the timeout for slow downloads.