For compliance frameworks like SOC 2, HIPAA, and GDPR, organizations need to retain authorization events for extended periods. TheDocumentation Index
Fetch the complete documentation index at: https://docs.grantex.dev/llms.txt
Use this file to discover all available pages before exploring further.
@grantex/destinations package provides S3Destination and BigQueryDestination classes that archive events to durable storage for long-term retention and analytics.
Prerequisites
- The
@grantex/destinationspackage installed:
- For S3: AWS credentials configured (environment variables, IAM role, or
~/.aws/credentials) - For BigQuery: Google Cloud credentials configured (service account key or Application Default Credentials)
Amazon S3
Setup
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
bucket | string | required | S3 bucket name |
prefix | string | grantex-events | Key prefix for uploaded objects |
region | string | us-east-1 | AWS region |
batchSize | number | 1000 | Number of events to buffer before flushing |
flushIntervalMs | number | — | Flush buffered events on a timer (milliseconds) |
How It Works
TheS3Destination buffers events and writes them as NDJSON (newline-delimited JSON) files to S3. Each flush produces one object with a timestamped key:
The S3 destination dynamically imports
@aws-sdk/client-s3 at runtime. Install it as a peer dependency: npm install @aws-sdk/client-s3.IAM Policy
The S3 destination requiress3:PutObject permission. Attach this policy to your IAM role or user:
S3 Lifecycle Policy
Configure an S3 lifecycle policy for cost-effective long-term retention:- Moves objects to Standard-IA after 30 days
- Moves to Glacier after 90 days
- Moves to Deep Archive after 1 year
- Deletes after 7 years (adjust per your retention requirements)
Querying with Athena
Set up an Athena table to query your archived events with standard SQL:Google BigQuery
Setup
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
projectId | string | required | Google Cloud project ID |
datasetId | string | required | BigQuery dataset ID |
tableId | string | required | BigQuery table ID |
batchSize | number | 500 | Number of events to buffer before flushing |
flushIntervalMs | number | — | Flush buffered events on a timer (milliseconds) |
How It Works
TheBigQueryDestination buffers events and inserts them as rows into a BigQuery table using the streaming insert API. Each event maps to a row with these columns:
| Column | BigQuery Type | Source |
|---|---|---|
event_id | STRING | event.id |
event_type | STRING | event.type |
created_at | STRING | event.createdAt |
data | STRING | JSON.stringify(event.data) |
The BigQuery destination dynamically imports
@google-cloud/bigquery at runtime. Install it as a peer dependency: npm install @google-cloud/bigquery.Table Schema
Create the BigQuery table before starting the destination:event_type gives you fast queries and lower costs for time-range and type-filtered queries.
IAM Permissions
The service account needs these BigQuery permissions:bigquery.tables.updateData(for streaming inserts)bigquery.tables.get(to verify table existence)
BigQuery Data Editor role on the dataset:
Example Queries
Multi-Destination Setup
For comprehensive compliance, send events to both a SIEM (for real-time alerting) and a data warehouse (for long-term retention):Compliance Best Practices
Retention Periods
Align your retention periods with your compliance framework:| Framework | Minimum Retention | Recommendation |
|---|---|---|
| SOC 2 | 1 year | 3 years |
| HIPAA | 6 years | 7 years |
| GDPR | As needed | 3 years (with deletion capability) |
| PCI DSS | 1 year | 3 years |
| FedRAMP | 3 years | 5 years |
Immutability
Enable object lock on your S3 bucket to prevent deletion or modification of archived events:Encryption
- S3: Enable SSE-S3 or SSE-KMS default encryption on your bucket
- BigQuery: Data is encrypted at rest by default; use CMEK for additional control
Access Controls
- Use dedicated IAM roles with least-privilege permissions
- Enable CloudTrail (AWS) or Audit Logs (GCP) on the archival resources
- Restrict access to the archival bucket/dataset to compliance and security teams
Completeness Verification
Periodically verify that your archive contains all expected events:GET /v1/audit/entries) to confirm no events were lost.
Graceful Shutdown
Ensure buffered events are flushed before your process exits:Next Steps
- Event Streaming — SSE/WebSocket architecture overview
- Datadog Integration — real-time alerting with Datadog
- Splunk Integration — search and dashboards with Splunk
- Metrics & Observability — Prometheus metrics and Grafana dashboards