> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cotool.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# AWS S3/SQS Log Ingestion

> Ingest CloudTrail, GuardDuty, Security Hub, VPC flow, load balancer, CloudFront, WAF, S3 access, Route 53 Resolver, and other JSON logs from S3 through a dedicated SQS queue

The AWS S3/SQS integration reads log files your AWS services already write to S3. Each new object is announced on an SQS queue dedicated to Cotool; Cotool assumes a role in your account, receives the notification, reads the object, and indexes its events into Cotool Logs.

```mermaid theme={null}
flowchart LR
    Producer["CloudTrail, GuardDuty, or another AWS service"] --> S3["S3 bucket"]
    S3 -- "ObjectCreated notification" --> SQS["Dedicated SQS queue"]
    SQS --> Cotool["Cotool (assumes your role)"]
    Cotool -- "s3:GetObject" --> S3
```

You can connect several named sources, for example one per environment or AWS organization, and pause, edit, or remove each independently.

## Log types

Each source carries one log type. Give each AWS service its own source and prefix: the setup suggests one per service.

| Log type | Cotool Logs table | What Cotool does |
| - | - | - |
| AWS CloudTrail | `aws_cloudtrail` | Unwraps CloudTrail's `Records` envelope and maps actor, action, service, resource, source IP, outcome, account, and region into columns shared with `gcp_cloud_audit`. Digest files are skipped. Events are keyed by `eventID`. |
| Amazon GuardDuty findings | `aws_guardduty_findings` | Reads exported findings (and findings wrapped in EventBridge events) into finding type, severity, resource, actor, access key, API, remote IP, and timestamps. Each update of a finding is kept as its own version. |
| AWS Security Hub findings | `aws_security_hub_findings` | Reads ASFF findings from `Security Hub Findings - Imported` events into title, severity, product, compliance and workflow status, resource, and remote IP. Each update of a finding is kept as its own version. |
| Amazon VPC flow logs | `aws_vpc_flow_logs` | Parses text flow logs in the default or any custom field order, one row per flow. `NODATA` and `SKIPDATA` records are dropped. |
| Application Load Balancer access logs | `aws_alb_access_logs` | Parses each request: client, target, status codes, timings, bytes, request line, user agent, TLS, and the matched rule and actions. |
| Amazon CloudFront access logs | `aws_cloudfront_logs` | Parses standard logs as text (with their `#Fields` header) or JSON: client, edge location and result, method, host, URI, status, bytes, and timings. Requests are keyed by their edge request ID. |
| AWS WAF logs | `aws_waf_logs` | Reads each inspected request with its web ACL, the rule and action that decided it, client IP and country, and the HTTP request. |
| Amazon S3 server access logs | `aws_s3_access_logs` | Parses each request: bucket, requester, operation, key, status, error code, bytes, and authentication. Requests are keyed by their request ID and object key. |
| Route 53 Resolver query logs | `aws_route53_resolver_logs` | Reads each DNS query from your VPCs with its source, name, type, response code, answers, and any firewall rule action. |
| Generic JSON | `aws_generic_logs` | Stores each JSON record with its original payload, top-level fields as a searchable `fields` map, and the object it came from. Records are not normalized and no detection coverage is implied. |

Supported formats are JSON, JSON arrays, newline-delimited JSON, the text formats AWS writes for flow, load balancer, CloudFront, and S3 access logs, and gzip-compressed versions of each. Objects in other formats (Parquet, ZIP, and so on) are reported with an actionable error on the source instead of being ingested. Flow logs must be delivered as plain text.

If the access test reads objects that look like another built-in log type, for example flow logs on a source set to Generic JSON, it offers to switch.

## Step 1: Create the queue and role

On the integration page, select **Add log source** and choose what to ingest: CloudTrail, one of the AWS services in the table above, or other JSON logs. Then enter each bucket and prefix, and any customer-managed KMS keys that encrypt the objects. Choosing a service suggests a prefix for it, like `guardduty/`. The setup section fills them, the **Cotool principal**, and your **External ID** into a Terraform configuration, an AWS CLI script, and a CloudFormation template. Each creates:

* a dedicated SQS queue (`cotool-log-ingest-<suffix>`) with a dead-letter queue, and a queue policy that accepts notifications from your log buckets,
* an IAM role (`CotoolLogIngest-<suffix>`) that trusts the Cotool principal only with your external ID, and can:
  * `sqs:ReceiveMessage`, `sqs:DeleteMessage`, `sqs:ChangeMessageVisibility`, and `sqs:GetQueueAttributes` on that queue,
  * `s3:GetObject` and `s3:GetObjectVersion` on each bucket prefix,
  * `kms:Decrypt` on the log keys, when objects are encrypted with customer-managed KMS keys.

`<suffix>` is a short random value generated for each setup, so several sources can live in the same account. Cotool only assumes roles whose name starts with `CotoolLogIngest`; keep that prefix if you rename the role.

> [!WARNING]
>
> Use a queue dedicated to Cotool. Cotool deletes messages once their objects
> are ingested, so sharing a queue with another SIEM would take messages away
> from it. If another tool already consumes the bucket's notifications, have
> the bucket notify an SNS topic and subscribe both queues to it by adapting
> the generated configuration to use SNS.

## Step 2: Deploy it

Deploy in the buckets' account and region: S3 only notifies queues in its own region. S3 keeps a single notification configuration per bucket, so the generated notification script adds `s3:ObjectCreated:*` notifications for each prefix only to buckets that have none, and prints what to add to the others.

> [tab] Terraform
>
> 1. Save the configuration in your infrastructure repository, and configure the AWS provider for the buckets' account and region.
> 2. Run `terraform init`, review `terraform plan`, then run `terraform apply`.
> 3. Run the generated `cotool-bucket-notifications.sh`, which reads the queue from `terraform output`. The configuration only manages the notifications itself when you set `manage_bucket_notifications = true`, because `aws_s3_bucket_notification` replaces a bucket's entire notification configuration. If Terraform already manages a bucket's notifications, add the queue to that resource instead.
> 4. `terraform output` prints `queue_url` and `role_arn` for the connection form.

> [tab] AWS CLI
>
> 1. Save the script. It needs AWS CLI v2, signed in to the buckets' account with permission to create SQS queues and IAM roles and to change the buckets' notifications.
> 2. Run `AWS_REGION=<bucket-region> bash cotool-log-ingest.sh`.
> 3. It prints `queue_url` and `role_arn` for the connection form. If a bucket already has notifications, the script leaves them in place and prints the queue ARN to add to them.

> [tab] CloudFormation
>
> 1. Save the template, and deploy it in the buckets' region with the generated `aws cloudformation deploy` command (stack `cotool-log-ingest-<suffix>`), or upload it under **Create stack** in the CloudFormation console.
> 2. A stack can't change a bucket it didn't create, so add the notifications once the stack is up: run the generated `cotool-bucket-notifications.sh`, or in the S3 console open each bucket's **Properties > Event notifications** and send all object create events for the prefix to the `cotool-log-ingest-<suffix>` queue.
> 3. The stack's `QueueUrl` and `RoleArn` outputs go into the connection form.

To create the resources in the console instead, expand **Setting it up in the console?** for the principal and external ID the role must trust.

## Step 3: Connect the source

1. **Connect**: enter the queue URL (the region fills in from it), the role ARN, and each bucket and prefix Cotool may read. Objects outside these prefixes are skipped even if they reach the queue.
2. **Test**: Cotool assumes the role, reads the queue attributes, samples up to ten messages, and reads one announced object. Sampled messages are returned to the queue, not deleted. If the queue is empty, paste a sample log.
3. **Format**: name the source and confirm the format: the service you chose, **Generic JSON**, or **Custom format, normalized to OCSF**. Cotool previews the sampled events parsed with that format.
4. Select **Enable source**, or **Save paused** to enable it later. Enabling needs a passing test.

## Step 4: Point the service at the bucket

For a built-in service, the last connection step gives the commands that turn on its delivery to your bucket and prefix, filled in from the bucket, the queue's region and account, and the KMS key. The source's **Setup guide** shows them again later. AWS constrains where some services can write:

| Service | Delivery |
| - | - |
| CloudTrail | A multi-region trail. Skip this if a trail, such as an organization trail, already writes to the bucket. |
| GuardDuty | A publishing destination per region with a detector, publishing every 15 minutes. GuardDuty only exports findings encrypted with a symmetric KMS key in the bucket's region, so the source requires the key ARN. |
| Security Hub | Security Hub has no S3 export. The generated script creates an EventBridge rule for imported findings and a Firehose stream that writes them to the bucket. Run it in Security Hub's aggregation region. It reads Security Hub CSPM findings in ASFF, not the OCSF findings of `Findings Imported V2` events. |
| VPC flow logs | Flow logs per VPC, as plain text. The command uses a custom format with every field Cotool reads; the default format works too. |
| Application Load Balancer | Access logs per load balancer. The bucket must be in the load balancer's region and use S3-managed encryption (SSE-S3). |
| CloudFront | Standard logs per distribution, delivered as JSON and configured in `us-east-1`. Legacy standard logs are read too. |
| WAF | Logging per web ACL. WAF only writes to buckets whose names start with `aws-waf-logs-`; the setup warns when the bucket doesn't. |
| S3 server access logs | Server access logging on each bucket to watch. The log bucket must be in the same region and account and use SSE-S3. |
| Route 53 Resolver | A query logging configuration, associated with each VPC. |

## Reliability

* Messages are deleted only after the object's events are archived and indexed. If Cotool restarts mid-run, the message becomes visible again and is reprocessed.
* A temporary failure (throttling, a network error, or access denied while permissions are being fixed) keeps the message on the queue and retries it with backoff up to 15 minutes, for about a day with the template's dead-letter settings.
* Malformed lines are skipped individually and kept in the raw archive with the reason. Objects that can never be read (unsupported format, deleted, too large) are recorded on the source and their messages removed so they cannot block the queue.
* Redelivered notifications do not create duplicates: CloudTrail events are keyed by `eventID`, GuardDuty and Security Hub findings by finding ID and update time, CloudFront and S3 access log requests by request ID, WAF records by their content, and other records by object version and position.

## Status

Each source shows its health, last successful ingestion, events and bytes read in the last 24 hours, the age of the oldest message received, the approximate queue depth, and recent errors with the object they concern.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.