https://github.com/mashiike/queryrunner
https://github.com/mashiike/queryrunner
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/mashiike/queryrunner
- Owner: mashiike
- License: mit
- Created: 2022-10-12T02:12:35.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-08-07T20:19:08.000Z (almost 2 years ago)
- Last Synced: 2024-06-19T05:43:24.069Z (12 months ago)
- Language: Go
- Size: 135 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# queryrunner


[](https://github.com/mashiike/queryrunner/blob/master/LICENSE)query-runner is a helper tool that makes querying several AWS services convenient
## Usage
```
query-runner is a helper tool that makes querying several AWS services convenientusages:
query-runner -l
query-runner [options] ...
cat params.json | query-runner [options]options:
-c, --config config dir, config format is HCL (defualt: ~/.config/query-runner/)
-l, --list displays a list of formats
-o, --output output format [json|table|markdown|borderless|vertical] (default:json)
-v, --variables variables json
-h, --help prints help information
--log-level log output level (default: info)
```sample config and sample command is following
```
$ query-runner --variables '{"function_name": "helloworld"}' lambda_hello_world
```~/.config/query-runner/config.hcl
```hcl
query_runner "cloudwatch_logs_insights" "default" {
region = "ap-northeast-1"
}query "lambda_logs" {
runner = query_runner.cloudwatch_logs_insights.default
start_time = strftime_in_zone("%Y-%m-%dT%H:%M:%S%z", "UTC", now() - duration("15m"))
end_time = strftime_in_zone("%Y-%m-%dT%H:%M:%S%z", "UTC", now())
query = <")
if !ok {
log.Fatalln("query not found")
}
result, err := query.Run(egctx, p.MarshalCTYValues(), nil)
if err != nil {
log.Fatalln(err)
}
log.Println(result.ToTable())
}
```## Usage with AWS Lambda (serverless)
query-runner works with AWS Lambda and Amazon SQS.
sample payload:
```json
{
"queries": [
"lambda_logs"
],
"variables": {
"function_name": "query-runner"
}
}
```sample output
```json
{
"results": {
"lambda_logs": [
{
"@message": "END RequestId: 00000000-0000-0000-0000-000000000000\n",
"@timestamp": "2022-10-12 09:22:49.638"
},
{
"@message": "REPORT RequestId: 00000000-0000-0000-0000-000000000000\tDuration: 2336.30 ms\tBilled Duration: 2346 ms\tMemory Size: 128 MB\tMax Memory Used: 20 MB\tInit Duration: 8.97 ms\t\n",
"@timestamp": "2022-10-12 09:22:49.638"
},
{
"@message": "2022/10/12 18:22:49 [debug] finish run `lambda_logs` runner type `cloudwatch_logs_insights`\n",
"@timestamp": "2022-10-12 09:22:49.637"
},
{
"@message": "2022/10/12 18:22:49 [debug][00000000-0000-0000-0000-000000000000] query result: 0 results, 0 B scanned, 0.000000 records matched, 0.000000 recoreds scanned\n",
"@timestamp": "2022-10-12 09:22:49.637"
},
{
"@message": "2022/10/12 18:22:49 [debug][00000000-0000-0000-0000-000000000000] wating cloudwatch logs insights query elapsed_time=1.642910477s\n",
"@timestamp": "2022-10-12 09:22:49.601"
}
]
}
}
```Let's solidify the Lambda package with the following zip arcive (runtime `provided.al2`)
```
lambda.zip
├── bootstrap # build binary
└── config.hcl # configuration file
```A related document is [https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html)
for example.
deploy two lambda functions, prepalert-http and prepalert-worker in [lambda directory](lambda/)
The example of lambda directory uses [lambroll](https://github.com/fujiwara/lambroll) for deployment.For more information on the infrastructure around lambda functions, please refer to [example.tf](lambda/example.tf).
## LICENSEMIT License
Copyright (c) 2022 IKEDA Masashi