{
  "$schema" : "https://json-schema.org/draft/2020-12/schema",
  "$id" : "https://voltdb.com/voltsp/schemas/source/s3-sqs-event-listener",
  "title" : "S3-sqs-event-listener Source Configuration",
  "description" : "The S3 SQS Event Listener receives Amazon S3 bucket notifications via an SQS queue.\n This approach is more efficient and real-time compared to polling-based solutions.\n\nThe listener will read all messages from SQS.\n The listener can be configured with filtering prefix and\n if prefix doesn't match the message will not be processed, it will be deleted along all other processed messages.\n\nThe metadata contains additional information about eventTime, eventType, versionId read from SQS.\n\nPrerequisites:\n1. Configure S3 bucket notifications to send events to an SQS queue\n  A: Create SQS Queue: `aws sqs create-queue --queue-name s3-events-queue`\n  B: Allow S3 to send messages to your queue (the `s3-events-queue`) by applying the policy\n     ```\n     {\n       \"Version\": \"2012-10-17\",\n       \"Statement\": [\n         {\n           \"Effect\": \"Allow\",\n           \"Principal\": {\n             \"Service\": \"s3.amazonaws.com\"\n           },\n           \"Action\": \"sqs:SendMessage\",\n           \"Resource\": \"arn:aws:sqs:us-east-1:123456789012:s3-events-queue\",\n           \"Condition\": {\n             \"ArnEquals\": {\n               \"aws:SourceArn\": \"arn:aws:s3:::your-bucket-name\"\n             }\n           }\n         }\n       ]\n     }\n     ```\n  C: Configure S3 Bucket Notifications\n     ```\n     aws s3api put-bucket-notification-configuration          --bucket your-bucket-name          --notification-configuration '{\n           \"QueueConfigurations\": [\n             {\n               \"Id\": \"s3-sqs-notification\",\n               \"QueueArn\": \"arn:aws:sqs:us-east-1:123456789012:s3-events-queue\",\n               \"Events\": [\"s3:ObjectCreated:*\", \"s3:ObjectRemoved:*\"],\n               \"Filter\": {\n                 \"Key\": {\n                   \"FilterRules\": [\n                     {\n                       \"Name\": \"prefix\",\n                       \"Value\": \"uploads/\"\n                     }\n                   ]\n                 }\n               }\n             }\n           ]\n         }\n     ```\n2. Ensure the SQS queue has appropriate permissions to receive S3 notifications\n3. Configure IAM permissions for the application to read from the SQS queue\n\nThe listener automatically handles:\n- SNS-wrapped messages (if S3 notifications go through SNS first)\n- Message deletion from the queue after successful processing\n- Event type mapping (ObjectCreated -> CREATED, ObjectRemoved -> DELETED)\n- Bucket and prefix filtering\n\nThe `S3ObjectMessage` includes the following metadata:\n- `bucketName`: The name of the S3 bucket\n- `key`: The key (path) of the S3 object\n- `content`: The actual content of the S3 object as a ByteBuffer, can be null\n- `contentType`: The content type of the S3 object\n- `contentLength`: The size of the S3 object in bytes\n- `lastModified`: The timestamp when the S3 object was last modified\n- `eTag`: The entity tag of the S3 object\n- `metadata`: A map of user-defined metadata associated with the S3 object\n",
  "type" : "object",
  "properties" : {
    "s3-sqs-event-listener" : {
      "type" : "object",
      "properties" : {
        "s3Resource" : {
          "description" : "Reference to the S3 client resource.",
          "anyOf" : [ {
            "type" : "string"
          }, {
            "$ref" : "resource-s3.schema.json#/properties/s3"
          } ]
        },
        "sqsResource" : {
          "description" : "Reference to the SQS client resource.",
          "anyOf" : [ {
            "type" : "string"
          }, {
            "$ref" : "resource-sqs.schema.json#/properties/sqs"
          } ]
        },
        "queueUrl" : {
          "type" : "string",
          "description" : "The name of the SQS queue."
        },
        "prefix" : {
          "type" : "string",
          "description" : "Optional prefix filter. If specified, only events for objects with keys starting with this prefix will be processed.\nIf null or empty, objects will not be filtered by prefix.\n"
        },
        "downloadContent" : {
          "type" : "boolean",
          "description" : "Whether to pull object's content into worker's memory. This can be expensive operation for big files.",
          "default" : "false"
        },
        "maxMessages" : {
          "type" : "integer",
          "description" : "Maximum number of messages to receive in a single request (1-10).",
          "default" : "10",
          "minimum" : -2147483648,
          "maximum" : 2147483647
        },
        "maxWaitTime" : {
          "type" : "string",
          "pattern" : "^(\\d+[smhd]|P(T|\\d+[YMD]).*)",
          "description" : "The duration for which the call waits for a message to arrive. Minimum 1 second.",
          "default" : "PT1M"
        }
      },
      "required" : [ "s3Resource", "sqsResource", "queueUrl" ],
      "additionalProperties" : false
    }
  },
  "required" : [ "s3-sqs-event-listener" ],
  "additionalProperties" : false
}
