README
¶
s3athena
This example is more specific example for production use case. In this scenario, We want to permanently store the access logs of our application. The access logs should be searchable when needed. We also need to be able to query for certain condition against our access logs.
Architecture overview

A brief description of the resources illustrated in the diagram above.
- Fluent Bit; A log forwarder.
- Amazon S3; A cloud object storage.
- AWS Glue; A serverless ETL service.
- Amazon Athena; A serverless query service that makes it easy to analyze data directly in S3 using standard SQL.
Prerequisites
- Golang 1.17+
- Environments to run docker compose(like Docker Desktop)
- Amazon S3 bucket for your log files
- AWS identity that has the following permissions
s3:PutObjectglue:CreateDatabaseglue:StartCrawlerglue:CreateCrawler
- AWS IAM Role that must provide permissions similar to the AWS managed policy, AWSGlueServiceRole, plus access to your data stores.
Step by step tutorial
- You need to set ENV
AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY. - In fluent-bit.conf, Replace ${YOUR_S3_BUCKET_NAME_FOR_LOG_FILES}, ${YOUR_SERVICE_NAME} with your owns.
- Run
docker compose up. - In another terminal, run
go run main.go - In another terminal,
curl localhost:3000/ping
If worked successfully, the following logs in output from the fluent-bit container. Depending on the value you set, the log may be slightly different.
fluent-bit_1 | [2021/12/07 15:40:18] [ info] [output:s3:s3.0] Successfully uploaded object /example/alpha/year=2021/month=12/day=07/hour=15/minute=40/thS0Tjuj
-
If you see the log output as above, see your S3 bucket and check if the logs are stored properly.
-
(If it is already exist, please skip) Creates a new AWS Glue database.
aws glue create-database --region ap-northeast-2 --database-input "{\"Name\":\"access_log\"}"
- Creates a new AWS Glue crawler(The role is noted in Prerequisites).
aws glue create-crawler \
--region ap-northeast-2 \
--name example \
--role service-role/AWSGlueServiceRole-example \
--database-name example \
--targets "{\"S3Targets\":[{\"Path\":\"s3://YOUR_S3_BUCKET_NAME_FOR_LOG_FILES/example/alpha\"}]}" \
--recrawl-policy "{\"RecrawlBehavior\":\"CRAWL_NEW_FOLDERS_ONLY\"}" \
--schema-change-policy "{\"UpdateBehavior\":\"LOG\",\"DeleteBehavior\": \"LOG\"}"
- Starts the crawler.
aws glue start-crawler --region ap-northeast-2 --name example
If the crawling has been completed successfully, you can check the created data catalog table in the AWS Glue console. You can now run queries on tables created through Amazon Athena.
References
To optimize logging settings for your own services, please refer to the following materials.
Documentation
¶
There is no documentation for this package.