Home icon

Automate PostgreSQL audit log extraction and analysis with Amazon S3

Database Blog



This article demonstrates how to automate PostgreSQL audit log extraction from CloudWatch Logs, convert them to structured CSV format, and store them in Amazon S3 using an event-driven Lambda pipeline.

  • Deploy an automated pipeline using CloudFormation that extracts pgAudit logs from CloudWatch Logs in near real time
  • Convert unstructured audit logs to structured CSV format with fields like timestamp, user, database, action, object, and query
  • Store logs in S3 with date-partitioned organization and lifecycle policies for cost optimization
  • Enable optional ad-hoc SQL queries on audit logs using Amazon Athena without additional infrastructure
  • Includes security considerations for handling sensitive data like PII in query parameters stored in S3
  • Solution designed for single database cluster; multiple databases require separate CloudFormation stacks

The solution eliminates manual audit log review bottlenecks for RDS PostgreSQL and Aurora PostgreSQL users by automating extraction, structuring, and long-term retention of audit data.



Go to article

The AWS News Feed is currently looking for gold sponsors. If you want to support the AWS community and reach a large audience of AWS professionals, consider sponsoring the AWS News Feed.

Related articles

Jul 28
2026
Automated PII redaction for Amazon RDS for PostgreSQL audit logs
Jan 21
2026
Automate the export of Amazon RDS for MySQL or Amazon Aurora MySQL audit logs to Amazon S3 with batching or near real-time processing
May 27
2026
Amazon S3 audit logging, Part 1: Analyzing server access logs with Amazon Athena for performance insights
May 28
2025
Automate Amazon RDS for PostgreSQL major or minor version upgrade using AWS Systems Manager and Amazon EC2

The AWS News Feed is currently looking for silver sponsors. If you want to support the AWS community and reach a large audience of AWS professionals, consider sponsoring the AWS News Feed.