Skip to content
AWS SAM app that sends slowqueries from CloudWatch Logs to Elasticsearch.
Ruby HCL Shell Dockerfile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows
etc
lambda-ruby-bundle
rds_slowquery_to_es
spec
tasks
terraform
.gitignore
.rspec
.rubocop.yml
.ruby-version
Gemfile
LICENSE.txt
README.md
Rakefile
docker-compose.yml
local-env.json
pt-fingerprint.patch
template.yaml.sample

README.md

rds-slowquery-to-es

AWS SAM project that sends slowqueries from CloudWatch Logs to Elasticsearch.

Setup

#pip install awscli
#pip install aws-sam-cli (>= 0.35.0)
#aws s3 mb aws s3://s3_bucket_for_sam_app
bundle install
bundle exec rake docker:lambda-ruby-bundle:build
bundle exec rake sam:bundle
bundle exec rake pt-fingerprint:download

cp template.yaml.sample template.yaml
vi template.yaml # Fix Role/ELASTICSEARCH_URL

Environment variables

export AWS_DEFAULT_REGION=ap-northeast-1
export AWS_ACCESS_KEY_ID=...
export AWS_SECRET_ACCESS_KEY=...
export S3_BUCKET=... # e.g. S3_BUCKET=s3_bucket_for_sam_app

Setup AWS resources using Terraform

cd terraform
cp variables.tfvars.sample variables.tfvars
vi variables.tfvars
terraform init
terraform plan -var-file=variables.tfvars
terraform apply -var-file=variables.tfvars

# After deploying SAM app
vi cloudwatch_logs.tf
# Uncomment aws_cloudwatch_log_subscription_filter.rds_slowquery_to_es
terraform plan -var-file=variables.tfvars
terraform apply -var-file=variables.tfvars

Invoke Lambda locally

docker-compose up -d
bundle exec rake sam:local:invoke
open http://localhost:5601

Create Kibana index pattern

  1. Management -> Create index pattern
  2. Create index pattern:
    • Index pattern: aws_rds_*_slowquery-*
    • Time Filter field name: timestamp

Run tests

bundle exec rake

Deploy

bundle exec rake sam:deploy-noop
bundle exec rake sam:deploy

Invoke Lambda remotely

# tail -f function log
sam logs -n sam-rds-slowquery-to-es -t
bundle exec rake sam:invoke

Delete AWS resources

aws cloudformation delete-stack --stack-name sam-rds-slowquery-to-es
cd terraform
terraform destroy -var-file=variables.tfvars
You can’t perform that action at this time.