From 9c27c49f5b4d64e05a28e660e17f33f9dc0b351f Mon Sep 17 00:00:00 2001 From: Mark Wolfe Date: Tue, 19 Jul 2022 15:19:10 +1000 Subject: [PATCH] feat(athena): added athena templates to query cur data --- LICENSE | 202 +++++++++++++++ Makefile | 117 ++++++++- README.md | 48 +++- cmd/partitions-curs-lambda/main.go | 48 ++++ cmd/symlink-curs-lambda/main.go | 8 +- go.mod | 19 +- go.sum | 68 +++++ internal/events/events.go | 2 +- internal/flags/flags.go | 14 +- internal/hive/hive.go | 40 +++ internal/hive/hive_test.go | 62 +++++ internal/hive/symlink.go | 4 +- internal/hive/symlink_test.go | 4 +- internal/partitions/handler.go | 61 +++++ internal/partitions/handler_test.go | 1 + internal/partitions/partitions.go | 79 ++++++ internal/partitions/partitions_test.go | 33 +++ internal/s3events/handler_test.go | 1 - internal/{s3events => symlink}/handler.go | 30 +-- internal/symlink/handler_test.go | 1 + sam/app/athena-workspace.yaml | 103 ++++++++ sam/app/athena.yaml | 294 ++++++++++++++++++++++ sam/app/cur-bucket.yaml | 87 +++++++ sam/app/cur.yaml | 27 ++ sam/app/deploy.yaml | 71 ++++++ sam/app/partitions.yaml | 97 +++++++ sam/app/symlink.yaml | 13 +- 27 files changed, 1493 insertions(+), 41 deletions(-) create mode 100644 LICENSE create mode 100644 cmd/partitions-curs-lambda/main.go create mode 100644 internal/hive/hive.go create mode 100644 internal/hive/hive_test.go create mode 100644 internal/partitions/handler.go create mode 100644 internal/partitions/handler_test.go create mode 100644 internal/partitions/partitions.go create mode 100644 internal/partitions/partitions_test.go delete mode 100644 internal/s3events/handler_test.go rename internal/{s3events => symlink}/handler.go (76%) create mode 100644 internal/symlink/handler_test.go create mode 100644 sam/app/athena-workspace.yaml create mode 100644 sam/app/athena.yaml create mode 100644 sam/app/cur-bucket.yaml create mode 100644 sam/app/cur.yaml create mode 100644 sam/app/deploy.yaml create mode 100644 sam/app/partitions.yaml diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0da7b19 --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2019 Mark Wolfe + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/Makefile b/Makefile index 12498a6..6ff5333 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -APPNAME := aws-billing-service +APPNAME := aws-billing-store STAGE ?= dev BRANCH ?= master @@ -6,9 +6,14 @@ GOLANGCI_VERSION = v1.46.2 GIT_HASH := $(shell git rev-parse --short HEAD) +DEPLOY_CMD = sam deploy + .PHONY: ci ci: test build +.PHONY: deploy +deploy: clean build archive deploy-cur-bucket deploy-cur deploy-symlink deploy-athena deploy-athena-workspace deploy-partitions + .PHONY: lint lint: docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:$(GOLANGCI_VERSION) golangci-lint run -v @@ -30,12 +35,61 @@ archive: @echo "--- build an archive" @cd dist && zip -X -9 ./handler.zip *-lambda +.PHONY: deploy-bucket +deploy-bucket: + @echo "--- deploy stack deployment-$(STAGE)-$(BRANCH)" + @$(DEPLOY_CMD) \ + --no-fail-on-empty-changeset \ + --template-file sam/app/symlink.yaml \ + --capabilities CAPABILITY_IAM \ + --s3-bucket $(SAM_BUCKET) \ + --s3-prefix sam/$(GIT_HASH) \ + --tags "environment=$(STAGE)" "branch=$(BRANCH)" "service=deployment" \ + --stack-name deployment-$(STAGE)-$(BRANCH) \ + --parameter-overrides AppName=deployment Stage=$(STAGE) Branch=$(BRANCH) + +.PHONY: deploy-cur-bucket +deploy-cur-bucket: + @echo "--- deploy stack $(APPNAME)-$(STAGE)-$(BRANCH)-cur-bucket" + $(eval SAM_BUCKET := $(shell aws ssm get-parameter --name '/config/$(STAGE)/$(BRANCH)/deploy_bucket' --query 'Parameter.Value' --output text)) + + @$(DEPLOY_CMD) \ + --no-fail-on-empty-changeset \ + --template-file sam/app/cur-bucket.yaml \ + --capabilities CAPABILITY_IAM \ + --s3-bucket $(SAM_BUCKET) \ + --s3-prefix sam/$(GIT_HASH) \ + --tags "environment=$(STAGE)" "branch=$(BRANCH)" "service=$(APPNAME)" \ + --stack-name $(APPNAME)-$(STAGE)-$(BRANCH)-cur-bucket \ + --parameter-overrides AppName=$(APPNAME) Stage=$(STAGE) Branch=$(BRANCH) ReportPrefix=cur/$(APPNAME)-$(STAGE)-$(BRANCH)-cur-$(AWS_DEFAULT_REGION)-athena-hourly + +.PHONY: deploy-cur +deploy-cur: + @echo "--- deploy stack $(APPNAME)-$(STAGE)-$(BRANCH)-cur" + $(eval SAM_BUCKET := $(shell aws ssm --region us-east-1 get-parameter --name '/config/$(STAGE)/$(BRANCH)/deploy_bucket' --query 'Parameter.Value' --output text)) + $(eval CUR_BUCKET_NAME := $(shell aws ssm get-parameter --name '/config/$(STAGE)/$(BRANCH)/$(APPNAME)/report_bucket' --query 'Parameter.Value' --output text)) + $(eval CUR_PREFIX := $(shell aws ssm get-parameter --name '/config/$(STAGE)/$(BRANCH)/$(APPNAME)/report_prefix' --query 'Parameter.Value' --output text)) + + @$(DEPLOY_CMD) \ + --no-fail-on-empty-changeset \ + --region us-east-1 \ + --template-file sam/app/cur.yaml \ + --capabilities CAPABILITY_IAM \ + --s3-bucket $(SAM_BUCKET) \ + --s3-prefix sam/$(GIT_HASH) \ + --tags "environment=$(STAGE)" "branch=$(BRANCH)" "service=$(APPNAME)" \ + --stack-name $(APPNAME)-$(STAGE)-$(BRANCH)-cur-$(AWS_DEFAULT_REGION) \ + --parameter-overrides AppName=$(APPNAME) Stage=$(STAGE) Branch=$(BRANCH) \ + ReportBucketName=$(CUR_BUCKET_NAME) ReportBucketRegion=$(AWS_DEFAULT_REGION) + .PHONY: deploy-symlink deploy-symlink: @echo "--- deploy stack $(APPNAME)-$(STAGE)-$(BRANCH)-symlink" $(eval SAM_BUCKET := $(shell aws ssm get-parameter --name '/config/$(STAGE)/$(BRANCH)/deploy_bucket' --query 'Parameter.Value' --output text)) + $(eval CUR_BUCKET_NAME := $(shell aws ssm get-parameter --name '/config/$(STAGE)/$(BRANCH)/$(APPNAME)/report_bucket' --query 'Parameter.Value' --output text)) + $(eval CUR_PREFIX := $(shell aws ssm get-parameter --name '/config/$(STAGE)/$(BRANCH)/$(APPNAME)/report_prefix' --query 'Parameter.Value' --output text)) - @sam deploy \ + @$(DEPLOY_CMD) \ --no-fail-on-empty-changeset \ --template-file sam/app/symlink.yaml \ --capabilities CAPABILITY_IAM \ @@ -44,4 +98,61 @@ deploy-symlink: --tags "environment=$(STAGE)" "branch=$(BRANCH)" "service=$(APPNAME)" \ --stack-name $(APPNAME)-$(STAGE)-$(BRANCH)-symlink \ --parameter-overrides AppName=$(APPNAME) Stage=$(STAGE) Branch=$(BRANCH) Commit=$(GIT_HASH) \ - DataBucketName=$(DATA_BUCKET_NAME) CurPrefix=$(CUR_PREFIX) \ No newline at end of file + ReportBucketName=$(CUR_BUCKET_NAME) CurPrefix=$(CUR_PREFIX) + +.PHONY: deploy-athena-workspace +deploy-athena-workspace: + @echo "--- deploy stack $(APPNAME)-$(STAGE)-$(BRANCH)-athena-workspace" + $(eval SAM_BUCKET := $(shell aws ssm get-parameter --name '/config/$(STAGE)/$(BRANCH)/deploy_bucket' --query 'Parameter.Value' --output text)) + + @$(DEPLOY_CMD) \ + --no-fail-on-empty-changeset \ + --template-file sam/app/athena-workspace.yaml \ + --capabilities CAPABILITY_IAM \ + --s3-bucket $(SAM_BUCKET) \ + --s3-prefix sam/$(GIT_HASH) \ + --tags "environment=$(STAGE)" "branch=$(BRANCH)" "service=$(APPNAME)" \ + --stack-name $(APPNAME)-$(STAGE)-$(BRANCH)-athena-workspace \ + --parameter-overrides AppName=$(APPNAME) Stage=$(STAGE) Branch=$(BRANCH) Commit=$(GIT_HASH) + +.PHONY: deploy-athena +deploy-athena: + @echo "--- deploy stack $(APPNAME)-$(STAGE)-$(BRANCH)-athena" + $(eval SAM_BUCKET := $(shell aws ssm get-parameter --name '/config/$(STAGE)/$(BRANCH)/deploy_bucket' --query 'Parameter.Value' --output text)) + $(eval CUR_BUCKET_NAME := $(shell aws ssm get-parameter --name '/config/$(STAGE)/$(BRANCH)/$(APPNAME)/report_bucket' --query 'Parameter.Value' --output text)) + $(eval CUR_PREFIX := $(shell aws ssm get-parameter --name '/config/$(STAGE)/$(BRANCH)/$(APPNAME)/report_prefix' --query 'Parameter.Value' --output text)) + + @$(DEPLOY_CMD) \ + --no-fail-on-empty-changeset \ + --template-file sam/app/athena.yaml \ + --capabilities CAPABILITY_IAM \ + --s3-bucket $(SAM_BUCKET) \ + --s3-prefix sam/$(GIT_HASH) \ + --tags "environment=$(STAGE)" "branch=$(BRANCH)" "service=$(APPNAME)" \ + --stack-name $(APPNAME)-$(STAGE)-$(BRANCH)-athena \ + --parameter-overrides AppName=$(APPNAME) Stage=$(STAGE) Branch=$(BRANCH) Commit=$(GIT_HASH) \ + ReportBucketName=$(CUR_BUCKET_NAME) CurPrefix=$(CUR_PREFIX) + +.PHONY: deploy-partitions +deploy-partitions: + @echo "--- deploy stack $(APPNAME)-$(STAGE)-$(BRANCH)-partitions" + $(eval SAM_BUCKET := $(shell aws ssm get-parameter --name '/config/$(STAGE)/$(BRANCH)/deploy_bucket' --query 'Parameter.Value' --output text)) + $(eval CUR_BUCKET_NAME := $(shell aws ssm get-parameter --name '/config/$(STAGE)/$(BRANCH)/$(APPNAME)/report_bucket' --query 'Parameter.Value' --output text)) + $(eval CUR_PREFIX := $(shell aws ssm get-parameter --name '/config/$(STAGE)/$(BRANCH)/$(APPNAME)/report_prefix' --query 'Parameter.Value' --output text)) + $(eval QUERY_RESULTS_BUCKET_NAME := $(shell aws ssm get-parameter --name '/config/$(STAGE)/$(BRANCH)/$(APPNAME)/athena_query_results_bucketname' --query 'Parameter.Value' --output text)) + $(eval GLUE_DATABASE_NAME := $(shell aws ssm get-parameter --name '/config/$(STAGE)/$(BRANCH)/$(APPNAME)/glue_database_name' --query 'Parameter.Value' --output text)) + $(eval GLUE_TABLE_NAME := $(shell aws ssm get-parameter --name '/config/$(STAGE)/$(BRANCH)/$(APPNAME)/glue_table_name' --query 'Parameter.Value' --output text)) + @$(DEPLOY_CMD) \ + --no-fail-on-empty-changeset \ + --template-file sam/app/partitions.yaml \ + --capabilities CAPABILITY_IAM \ + --s3-bucket $(SAM_BUCKET) \ + --s3-prefix sam/$(GIT_HASH) \ + --tags "environment=$(STAGE)" "branch=$(BRANCH)" "service=$(APPNAME)" \ + --stack-name $(APPNAME)-$(STAGE)-$(BRANCH)-partitions \ + --parameter-overrides AppName=$(APPNAME) Stage=$(STAGE) Branch=$(BRANCH) Commit=$(GIT_HASH) \ + ReportBucketName=$(CUR_BUCKET_NAME) \ + CurPrefix=$(CUR_PREFIX) \ + QueryResultsBucketName=$(QUERY_RESULTS_BUCKET_NAME) \ + GlueDatabase=$(GLUE_DATABASE_NAME) \ + GlueTable=$(GLUE_TABLE_NAME) diff --git a/README.md b/README.md index 34ab697..b9fcbc2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,48 @@ -# aws-billing-manager +# aws-billing-store -This project provides an authenticated aws billing dashboard powered by Amazon Athena, Serverless components using Go, and Apache echarts. +This project deploys an automated CUR ingestion which updates an Athena table setup to enable querying of the latest snapshots for each month. This is an alternative to the pre configured athena setup provided by the Billing Team and is more suited to customers with 10s or 100s of CUR files provided in each report. -This project is a made up of a few components which can be deployed either as a complete solution, or as standalone components. +# Overview +The goal of this project is to provide a consistent view of cost and usage reports (CUR) at all times in a Athena table. To do this we use hive symlinks, which are updated each time a new snapshot arrives providing an atomic single file update for new CURs. This is different to the status table provided by AWS Billing team in the pre configured Athena setup. + +# How It Works + +When you enable the option to keep all versions of the CUR, AWS will upload a new snapshot then once complete update the manifest containing a list of file paths for that billing period. We use an s3 file create event to trigger reading of that manifest and creation of a symlink in the hive directory we maintain in the same bucket. This provides Athena with a partitioned structure to query without worrying about CUR files being updated while it is reading them. + +# Prerequisites + +1. An AWS account. +2. [AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html). +3. Exported environment variables for `AWS_DEFAULT_REGION`, `AWS_REGION` and `AWS_PROFILE`. + +# Deployment + +First you will need to deploy the bucket we use to store lambda and CFN artifacts. + +``` +make deploy-bucket +``` + +Deploy the solution. + +``` +make deploy +``` + +This will deploy the following components: + +1. Setup a bucket for the CUR in the region you configured via `AWS_DEFAULT_REGION`. +2. Create a CUR in the billing service. +3. Deploy the lambda which creates the hive directory containing symlinks to the latest CUR. +4. Deploy the Glue database and table used by Athena. +5. Deploy the Athena workspace with an encrypted secure S3 bucket for artifacts. +6. Deploy the template which creates partitions in Athena based on files created in the hive directory. + +# What Next? + +There are some great resources with queries which provide insights from your CUR data, one of the best is [Level 300: AWS CUR Query Library](https://wellarchitectedlabs.com/cost/300_labs/300_cur_queries/) from the [The Well-Architected Labs website](https://wellarchitectedlabs.com/). + +# License + +This project is released under Apache 2.0 license and is copyright [Mark Wolfe](https://www.wolfe.id.au). \ No newline at end of file diff --git a/cmd/partitions-curs-lambda/main.go b/cmd/partitions-curs-lambda/main.go new file mode 100644 index 0000000..0095847 --- /dev/null +++ b/cmd/partitions-curs-lambda/main.go @@ -0,0 +1,48 @@ +package main + +import ( + "context" + "runtime/debug" + + "github.com/alecthomas/kong" + "github.com/aws/aws-lambda-go/lambda" + "github.com/rs/zerolog/log" + "github.com/wolfeidau/aws-billing-store/internal/flags" + "github.com/wolfeidau/aws-billing-store/internal/partitions" + lmw "github.com/wolfeidau/lambda-go-extras/middleware" + "github.com/wolfeidau/lambda-go-extras/middleware/raw" + zlog "github.com/wolfeidau/lambda-go-extras/middleware/zerolog" +) + +var ( + // assigned during build time with -ldflags + commit = "unknown" + + cli flags.Partitions +) + +func main() { + kong.Parse(&cli, + kong.Vars{"version": commit}, // bind a var for version + ) + + flds := lmw.FieldMap{"commit": commit} + + if buildInfo, ok := debug.ReadBuildInfo(); ok { + log.Info().Fields(map[string]interface{}{ + "buildInfo": buildInfo, + }).Msg("startup") + } + + h, err := partitions.NewHandler(context.Background(), cli) + if err != nil { + log.Fatal().Err(err).Msg("handler setup failed") + } + + ch := lmw.New( + raw.New(raw.Fields(flds)), // raw event logger primarily used during development + zlog.New(zlog.Fields(flds)), // inject zerolog into the context + ).Then(h) + + lambda.Start(ch) +} diff --git a/cmd/symlink-curs-lambda/main.go b/cmd/symlink-curs-lambda/main.go index d041b30..5370e66 100644 --- a/cmd/symlink-curs-lambda/main.go +++ b/cmd/symlink-curs-lambda/main.go @@ -7,8 +7,8 @@ import ( "github.com/alecthomas/kong" "github.com/aws/aws-lambda-go/lambda" "github.com/rs/zerolog/log" - "github.com/wolfeidau/aws-billing-service/internal/flags" - "github.com/wolfeidau/aws-billing-service/internal/s3events" + "github.com/wolfeidau/aws-billing-store/internal/flags" + "github.com/wolfeidau/aws-billing-store/internal/symlink" lmw "github.com/wolfeidau/lambda-go-extras/middleware" "github.com/wolfeidau/lambda-go-extras/middleware/raw" zlog "github.com/wolfeidau/lambda-go-extras/middleware/zerolog" @@ -18,7 +18,7 @@ var ( // assigned during build time with -ldflags commit = "unknown" - cli flags.S3Events + cli flags.Symlink ) func main() { @@ -34,7 +34,7 @@ func main() { }).Msg("startup") } - h, err := s3events.NewHandler(context.Background(), cli) + h, err := symlink.NewHandler(context.Background()) if err != nil { log.Fatal().Err(err).Msg("handler setup failed") } diff --git a/go.mod b/go.mod index 4bac8f0..53c0b4b 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/wolfeidau/aws-billing-service +module github.com/wolfeidau/aws-billing-store go 1.18 @@ -13,12 +13,16 @@ require ( github.com/labstack/echo/v4 v4.7.2 github.com/rs/zerolog v1.26.1 github.com/stretchr/testify v1.7.1 + github.com/uber/athenadriver v1.1.13 github.com/wolfeidau/lambda-go-extras v1.4.0 github.com/wolfeidau/lambda-go-extras/middleware/raw v1.4.0 github.com/wolfeidau/lambda-go-extras/middleware/zerolog v1.4.0 ) require ( + github.com/DATA-DOG/go-sqlmock v1.4.1 // indirect + github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect + github.com/aws/aws-sdk-go v1.37.32 // indirect github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.1 // indirect github.com/aws/aws-sdk-go-v2/credentials v1.12.4 // indirect github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.5 // indirect @@ -35,18 +39,31 @@ require ( github.com/aws/smithy-go v1.11.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/ghodss/yaml v1.0.0 // indirect + github.com/go-openapi/errors v0.19.2 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect + github.com/go-openapi/strfmt v0.19.5 // indirect github.com/go-openapi/swag v0.21.1 // indirect + github.com/go-stack/stack v1.8.0 // indirect github.com/golang/mock v1.5.0 // indirect + github.com/jedib0t/go-pretty v4.3.0+incompatible // indirect + github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/labstack/gommon v0.3.1 // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-colorable v0.1.12 // indirect github.com/mattn/go-isatty v0.0.14 // indirect + github.com/mattn/go-runewidth v0.0.9 // indirect + github.com/mitchellh/mapstructure v1.1.2 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/uber-go/tally v3.3.17+incompatible // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v1.2.1 // indirect + github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2 // indirect + go.mongodb.org/mongo-driver v1.0.3 // indirect + go.uber.org/atomic v1.6.0 // indirect + go.uber.org/multierr v1.5.0 // indirect + go.uber.org/zap v1.15.0 // indirect golang.org/x/crypto v0.0.0-20220513210258-46612604a0f9 // indirect golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect golang.org/x/net v0.0.0-20220513224357-95641704303c // indirect diff --git a/go.sum b/go.sum index cfbb51e..95d9831 100644 --- a/go.sum +++ b/go.sum @@ -1,12 +1,19 @@ +github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/DATA-DOG/go-sqlmock v1.4.1 h1:ThlnYciV1iM/V0OSF/dtkqWb6xo5qITT1TJBG1MRDJM= +github.com/DATA-DOG/go-sqlmock v1.4.1/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= github.com/alecthomas/kong v0.5.0 h1:u8Kdw+eeml93qtMZ04iei0CFYve/WPcA5IFh+9wSskE= github.com/alecthomas/kong v0.5.0/go.mod h1:uzxf/HUh0tj43x1AyJROl3JT7SgsZ5m+icOv1csRhc0= github.com/alecthomas/repr v0.0.0-20210801044451-80ca428c5142 h1:8Uy0oSf5co/NZXje7U1z8Mpep++QJOldL2hs/sBQf48= github.com/alecthomas/repr v0.0.0-20210801044451-80ca428c5142/go.mod h1:2kn6fqh/zIyPLmm3ugklbEi5hg5wS435eygvNfaDQL8= +github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a h1:idn718Q4B6AGu/h5Sxe66HYVdqdGu2l9Iebqhi/AEoA= +github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= github.com/aws/aws-lambda-go v1.21.0/go.mod h1:jJmlefzPfGnckuHdXX7/80O3BvUUi12XOkbv4w9SGLU= github.com/aws/aws-lambda-go v1.22.0/go.mod h1:jJmlefzPfGnckuHdXX7/80O3BvUUi12XOkbv4w9SGLU= github.com/aws/aws-lambda-go v1.32.0 h1:i8MflawW1hoyYp85GMH7LhvAs4cqzL7LOS6fSv8l2KM= github.com/aws/aws-lambda-go v1.32.0/go.mod h1:IF5Q7wj4VyZyUFnZ54IQqeWtctHQ9tz+KhcbDenr220= +github.com/aws/aws-sdk-go v1.37.32 h1:gLEASuX1phzqb00APUZU/xVIqf13IoA250RlgQ9rz28= +github.com/aws/aws-sdk-go v1.37.32/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro= github.com/aws/aws-sdk-go-v2 v1.16.4 h1:swQTEQUyJF/UkEA94/Ga55miiKFoXmm/Zd67XHgmjSg= github.com/aws/aws-sdk-go-v2 v1.16.4/go.mod h1:ytwTPBG6fXTZLxxeeCCWj2/EMYp/xDUgX+OET6TLNNU= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.1 h1:SdK4Ppk5IzLs64ZMvr6MrSficMtjY2oS0WOORXTlxwU= @@ -41,6 +48,7 @@ github.com/aws/aws-sdk-go-v2/service/sts v1.16.6 h1:aYToU0/iazkMY67/BYLt3r6/LT/m github.com/aws/aws-sdk-go-v2/service/sts v1.16.6/go.mod h1:rP1rEOKAGZoXp4iGDxSXFvODAtXpm34Egf0lL0eshaQ= github.com/aws/smithy-go v1.11.2 h1:eG/N+CcUMAvsdffgMvjMKwfyDzIkjM6pfxMJ8Mzc6mE= github.com/aws/smithy-go v1.11.2/go.mod h1:3xHYmszWVx2c0kIwQeEVf9uSm4fYZt67FBJnwub1bgM= +github.com/cactus/go-statsd-client/statsd v0.0.0-20200423205355-cb0885a1018c/go.mod h1:l/bIBLeOl9eX+wxJAzxS4TveKRtAqlyDpHjhkfO0MEI= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= @@ -62,8 +70,12 @@ github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeME github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.7.7/go.mod h1:axIBovoeJpVj8S3BwE0uPMTeReE4+AfFtqpqaZ1qq1U= github.com/go-chi/chi/v5 v5.0.7/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= +github.com/go-openapi/errors v0.19.2 h1:a2kIyV3w+OS3S97zxUndRVD46+FhGOUBDFY7nmu4CsY= +github.com/go-openapi/errors v0.19.2/go.mod h1:qX0BLWsyaKfvhluLejVpVNwNRdXZhEbTA4kxxpKBC94= github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY= github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= +github.com/go-openapi/strfmt v0.19.5 h1:0utjKrw+BAh8s57XE9Xz8DUBsVvPmRUB6styvl9wWIM= +github.com/go-openapi/strfmt v0.19.5/go.mod h1:eftuHTlB/dI8Uq8JJOyRlieZf+WkkxUuk0dgdHXr2Qk= github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= github.com/go-openapi/swag v0.21.1 h1:wm0rhTb5z7qpJRHBdPOMuY4QjVUMbF6/kwoYeRAOrKU= github.com/go-openapi/swag v0.21.1/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= @@ -74,6 +86,8 @@ github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+ github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA= github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4= github.com/go-playground/validator/v10 v10.11.0/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU= +github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= @@ -85,19 +99,27 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golangci/lint-1 v0.0.0-20181222135242-d2cdd8c08219 h1:utua3L2IbQJmauC5IXdEA547bcoU5dozgQAfc8Onsg4= github.com/golangci/lint-1 v0.0.0-20181222135242-d2cdd8c08219/go.mod h1:/X8TswGSh1pIozq4ZwCfxS0WA5JGXguxk94ar/4c87Y= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o= github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= +github.com/jedib0t/go-pretty v4.3.0+incompatible h1:CGs8AVhEKg/n9YbUenWmNStRW2PHJzaeDodcfvRAbIo= +github.com/jedib0t/go-pretty v4.3.0+incompatible/go.mod h1:XemHduiw8R651AF9Pt4FwCTKeG3oo7hrHJAoznj9nag= +github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= +github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= @@ -132,6 +154,10 @@ github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= +github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= +github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= @@ -143,6 +169,7 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= @@ -154,6 +181,7 @@ github.com/rs/zerolog v1.26.1/go.mod h1:/wSSJWX7lVrsOwlbyTRSOJvqRlc+WjWlfes+CiJ+ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= @@ -161,6 +189,12 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= +github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= +github.com/uber-go/tally v3.3.17+incompatible h1:nFHIuW3VQ22wItiE9kPXic8dEgExWOsVOHwpmoIvsMw= +github.com/uber-go/tally v3.3.17+incompatible/go.mod h1:YDTIBxdXyOU/sCWilKB4bgyufu1cEi0jdVnRdxvjnmU= +github.com/uber/athenadriver v1.1.13 h1:h67yRqRl0Vj5f30bn6Nsn42bI08rY+yielMn1pdUhV0= +github.com/uber/athenadriver v1.1.13/go.mod h1:mpa8cVqc/JH/xnViFoWFvNkoYyIj5ohn9mxAnBj3fik= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M= github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= @@ -177,9 +211,28 @@ github.com/wolfeidau/lambda-go-extras/middleware/raw v1.4.0 h1:s2ciansk0HPQpADbI github.com/wolfeidau/lambda-go-extras/middleware/raw v1.4.0/go.mod h1:Ogq1ClvHKT3gxg+GF7NFeVJLI6ap1DrxMSehSXCet3g= github.com/wolfeidau/lambda-go-extras/middleware/zerolog v1.4.0 h1:JJCjoQuHVRtclyL9flnfFgJJGrVnLiMQfzVhIrs6CX4= github.com/wolfeidau/lambda-go-extras/middleware/zerolog v1.4.0/go.mod h1:ASSPdDNCKc0ituo6J0nljJL6RRygiWgdDFbL8c9POoc= +github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2 h1:zzrxE1FKn5ryBNl9eKOeqQ58Y/Qpo3Q9QNxKHX5uzzQ= +github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2/go.mod h1:hzfGeIUDq/j97IG+FhNqkowIyEcD88LrW6fyU3K3WqY= github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +go.mongodb.org/mongo-driver v1.0.3 h1:GKoji1ld3tw2aC+GX1wbr/J2fX13yNacEYoJ8Nhr0yU= +go.mongodb.org/mongo-driver v1.0.3/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM= +go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= +go.uber.org/atomic v1.6.0 h1:Ezj3JGmsOnG1MoRWQkPBsKLe9DwWD9QeXzTRzzldNVk= +go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= +go.uber.org/config v1.4.0/go.mod h1:aCyrMHmUAc/s2h9sv1koP84M9ZF/4K+g2oleyESO/Ig= +go.uber.org/dig v1.9.0/go.mod h1:X34SnWGr8Fyla9zQNO2GSO2D+TIuqB14OS8JhYocIyw= +go.uber.org/fx v1.12.0/go.mod h1:egT3Kyg1JFYQkvKLZ3EsykxkNrZxgXS+gKoKo7abERY= +go.uber.org/goleak v0.10.0/go.mod h1:VCZuO8V8mFPlL0F5J5GK1rtHV3DrFcQ1R8ryq7FK0aI= +go.uber.org/multierr v1.4.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= +go.uber.org/multierr v1.5.0 h1:KCa4XfM8CWFCpxXRGok+Q0SS/0XBhMDbHHGABQLvD2A= +go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= +go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4= +go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= +go.uber.org/zap v1.15.0 h1:ZZCA22JRF2gQE5FoNmhmrf7jeJJ2uhqDUNRYKm8dvmM= +go.uber.org/zap v1.15.0/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= @@ -189,6 +242,9 @@ golang.org/x/crypto v0.0.0-20211215165025-cf75a172585e/go.mod h1:P+XmwS30IXTQdn5 golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220513210258-46612604a0f9 h1:NUzdAbFtCJSXU20AOXgeqaUwg8Ypg4MPYmL+d+rsB5c= golang.org/x/crypto v0.0.0-20220513210258-46612604a0f9/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o= @@ -196,6 +252,7 @@ golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2 golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= @@ -207,6 +264,7 @@ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -230,8 +288,15 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20220411224347-583f2d630306/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190828213141-aed303cbaa74/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191030062658-86caa796c7ab/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191104232314-dc038396d1f0/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191114200427-caa0b0f7d508/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo= golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20= @@ -252,6 +317,7 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= @@ -260,3 +326,5 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM= +honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= diff --git a/internal/events/events.go b/internal/events/events.go index 6470ef7..d002d22 100644 --- a/internal/events/events.go +++ b/internal/events/events.go @@ -4,7 +4,7 @@ import ( "encoding/json" "time" - "github.com/wolfeidau/aws-billing-service/internal/events/s3created" + "github.com/wolfeidau/aws-billing-store/internal/events/s3created" ) type AWSEvent struct { diff --git a/internal/flags/flags.go b/internal/flags/flags.go index 46079dd..aa20345 100644 --- a/internal/flags/flags.go +++ b/internal/flags/flags.go @@ -2,10 +2,22 @@ package flags import "github.com/alecthomas/kong" -type S3Events struct { +type Base struct { Version kong.VersionFlag RawEventLogging bool `help:"Enable raw event logging." env:"RAW_EVENT_LOGGING"` Debug bool `help:"Enable debug logging." env:"DEBUG"` Stage string `help:"The development stage." env:"STAGE"` Branch string `help:"The git branch this code originated." env:"BRANCH"` } + +type Symlink struct { + Base +} + +type Partitions struct { + Base + Region string `help:"The AWS region." env:"AWS_REGION"` + QueryBucket string `help:"The Bucket used for Athena query results." env:"QUERY_BUCKET"` + Database string `help:"The Athena database name." env:"DATABASE"` + Table string `help:"The Athena table name." env:"TABLE"` +} diff --git a/internal/hive/hive.go b/internal/hive/hive.go new file mode 100644 index 0000000..05cde98 --- /dev/null +++ b/internal/hive/hive.go @@ -0,0 +1,40 @@ +package hive + +import ( + "fmt" + "strings" +) + +type HivePartitions map[string]string + +// PathString convert a map of partition key/values to a path string +func (hv HivePartitions) PathString() string { + + var parts []string + + for k, v := range hv { + parts = append(parts, fmt.Sprintf("%s=%s", k, v)) + } + + return strings.Join(parts, "/") +} + +// ParsePathString converts a path to a map of partition key/values by locating tokens which contain +// an `=` sign and splitting on that character. +func ParsePathString(path string) HivePartitions { + parts := strings.Split(path, "/") + + hv := HivePartitions{} + + for _, part := range parts { + if strings.Contains(part, "=") { + kv := strings.SplitN(part, "=", 2) + + if len(kv) == 2 { + hv[kv[0]] = kv[1] + } + } + } + + return hv +} diff --git a/internal/hive/hive_test.go b/internal/hive/hive_test.go new file mode 100644 index 0000000..3651992 --- /dev/null +++ b/internal/hive/hive_test.go @@ -0,0 +1,62 @@ +package hive + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestParsePathString(t *testing.T) { + type args struct { + path string + } + tests := []struct { + name string + args args + want HivePartitions + }{ + { + name: "should parse valid path", + args: args{path: "hive/year=2020/month=1/symlink.txt"}, + want: HivePartitions{ + "year": "2020", + "month": "1", + }, + }, + { + name: "should parse valid path", + args: args{path: "hive/year=2020/month=1/symlink.txt"}, + want: HivePartitions{ + "year": "2020", + "month": "1", + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := ParsePathString(tt.args.path) + assert.Equal(t, tt.want, got) + }) + } +} + +func TestHivePartitions_PathString(t *testing.T) { + tests := []struct { + name string + hv HivePartitions + want string + }{ + { + name: "should build valid path", + hv: HivePartitions{"year": "2022", "month": "1"}, + want: "year=2022/month=1", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := tt.hv.PathString(); got != tt.want { + t.Errorf("HivePartitions.PathString() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/internal/hive/symlink.go b/internal/hive/symlink.go index 8c5c449..603fd55 100644 --- a/internal/hive/symlink.go +++ b/internal/hive/symlink.go @@ -25,9 +25,9 @@ func NewSymlinkGenerator(s3client S3Client) *SymlinkGenerator { } } -func (sg *SymlinkGenerator) StoreSymlink(ctx context.Context, bucket, prefix string, hivePartitions, symlinkKeys []string) (*s3.PutObjectOutput, error) { +func (sg *SymlinkGenerator) StoreSymlink(ctx context.Context, bucket, prefix string, hivePartitions HivePartitions, symlinkKeys []string) (*s3.PutObjectOutput, error) { - key := fmt.Sprintf("%s/hive/%s/symlink.txt", prefix, strings.Join(hivePartitions, "/")) + key := fmt.Sprintf("%s/hive/%s/symlink.txt", prefix, hivePartitions.PathString()) buf := bytes.NewBufferString(strings.Join(symlinkKeys, "\n")) diff --git a/internal/hive/symlink_test.go b/internal/hive/symlink_test.go index bc4a299..055f790 100644 --- a/internal/hive/symlink_test.go +++ b/internal/hive/symlink_test.go @@ -27,7 +27,7 @@ func TestSymlinkGenerator_StoreSymlink(t *testing.T) { ctx context.Context bucket string prefix string - hivePartitions []string + hivePartitions map[string]string symlinkKeys []string } tests := []struct { @@ -45,7 +45,7 @@ func TestSymlinkGenerator_StoreSymlink(t *testing.T) { ctx: context.TODO(), bucket: "test-bucket", prefix: "test-prefix", - hivePartitions: []string{"year=2022", "month=1"}, + hivePartitions: map[string]string{"year": "2022", "month": "1"}, symlinkKeys: []string{ "parquet/test-managment-cur/20220401-20220501/20220503T120125Z/test-managment-cur-00001.snappy.parquet", "parquet/test-managment-cur/20220401-20220501/20220503T120125Z/test-managment-cur-00002.snappy.parquet", diff --git a/internal/partitions/handler.go b/internal/partitions/handler.go new file mode 100644 index 0000000..fe2f8b1 --- /dev/null +++ b/internal/partitions/handler.go @@ -0,0 +1,61 @@ +package partitions + +import ( + "context" + "errors" + "fmt" + + "github.com/wolfeidau/aws-billing-store/internal/events" + "github.com/wolfeidau/aws-billing-store/internal/events/s3created" + "github.com/wolfeidau/aws-billing-store/internal/flags" + "github.com/wolfeidau/aws-billing-store/internal/hive" +) + +type Handler struct { + cfg flags.Partitions + pman *Manager +} + +func NewHandler(ctx context.Context, cfg flags.Partitions) (*Handler, error) { + + pman, err := NewManager(cfg.QueryBucket, cfg.Region, cfg.Database, cfg.Table) + if err != nil { + return nil, err + } + + return &Handler{ + cfg: cfg, + pman: pman, + }, nil +} + +func (h *Handler) Invoke(ctx context.Context, payload []byte) ([]byte, error) { + + event, err := events.ParseEvent(payload) + if err != nil { + return nil, err + } + + switch v := event.Detail.(type) { + case *s3created.ObjectCreated: + return h.processCreated(ctx, v) + } + + return nil, errors.New("failed to process event, unknown type") +} + +func (h *Handler) processCreated(ctx context.Context, created *s3created.ObjectCreated) ([]byte, error) { + + hivePartitions := hive.ParsePathString(created.Object.Key) + + if hivePartitions["year"] == "" || hivePartitions["month"] == "" { + return nil, fmt.Errorf("unable to parse hive partitions from path: %s", created.Object.Key) + } + + err := h.pman.CreatePartition(ctx, hivePartitions["year"], hivePartitions["month"]) + if err != nil { + return nil, err + } + + return []byte(`{"msg": "ok"}`), nil +} diff --git a/internal/partitions/handler_test.go b/internal/partitions/handler_test.go new file mode 100644 index 0000000..585172f --- /dev/null +++ b/internal/partitions/handler_test.go @@ -0,0 +1 @@ +package partitions diff --git a/internal/partitions/partitions.go b/internal/partitions/partitions.go new file mode 100644 index 0000000..4e8da04 --- /dev/null +++ b/internal/partitions/partitions.go @@ -0,0 +1,79 @@ +package partitions + +import ( + "bytes" + "context" + "database/sql" + "fmt" + "os" + "text/template" + + "github.com/rs/zerolog/log" + drv "github.com/uber/athenadriver/go" +) + +var ( + parts = template.Must(template.New("partition"). + Parse(`ALTER TABLE {{ .Table }} ADD IF NOT EXISTS +PARTITION (year=?, month=?)`)) +) + +type params struct { + Table string +} + +type Manager struct { + conf *drv.Config + database string + table string +} + +func NewManager(queryBucket, region, database, table string) (*Manager, error) { + os.Setenv("AWS_SDK_LOAD_CONFIG", "1") + conf, err := drv.NewDefaultConfig( + fmt.Sprintf("s3://%s/results", queryBucket), + region, + drv.DummyAccessID, + drv.DummySecretAccessKey, + ) + if err != nil { + return nil, err + } + + conf.SetDB(database) + + return &Manager{conf: conf, database: database, table: table}, nil +} + +func (m *Manager) CreatePartition(ctx context.Context, year, month string) error { + + query, err := buildQuery(m.table) + if err != nil { + return err + } + + db, err := sql.Open(drv.DriverName, m.conf.Stringify()) + if err != nil { + return err + } + + log.Ctx(ctx).Info().Str("query", query).Msg("run query") + + _, err = db.Query(query, year, month) + if err != nil { + return err + } + + return nil +} + +func buildQuery(table string) (string, error) { + buf := new(bytes.Buffer) + + err := parts.Execute(buf, ¶ms{Table: table}) + if err != nil { + return "", err + } + + return buf.String(), nil +} diff --git a/internal/partitions/partitions_test.go b/internal/partitions/partitions_test.go new file mode 100644 index 0000000..18a6c8c --- /dev/null +++ b/internal/partitions/partitions_test.go @@ -0,0 +1,33 @@ +package partitions + +import "testing" + +func Test_buildQuery(t *testing.T) { + type args struct { + table string + } + tests := []struct { + name string + args args + want string + wantErr bool + }{ + { + name: "should build valid query", + args: args{table: "table_name"}, + want: "ALTER TABLE table_name ADD IF NOT EXISTS\nPARTITION (year=?, month=?)", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := buildQuery(tt.args.table) + if (err != nil) != tt.wantErr { + t.Errorf("buildQuery() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("buildQuery() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/internal/s3events/handler_test.go b/internal/s3events/handler_test.go deleted file mode 100644 index f86e36a..0000000 --- a/internal/s3events/handler_test.go +++ /dev/null @@ -1 +0,0 @@ -package s3events diff --git a/internal/s3events/handler.go b/internal/symlink/handler.go similarity index 76% rename from internal/s3events/handler.go rename to internal/symlink/handler.go index baf51c5..2462022 100644 --- a/internal/s3events/handler.go +++ b/internal/symlink/handler.go @@ -1,4 +1,4 @@ -package s3events +package symlink import ( "context" @@ -10,20 +10,18 @@ import ( "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/service/s3" "github.com/rs/zerolog/log" - "github.com/wolfeidau/aws-billing-service/internal/cur" - "github.com/wolfeidau/aws-billing-service/internal/events" - "github.com/wolfeidau/aws-billing-service/internal/events/s3created" - "github.com/wolfeidau/aws-billing-service/internal/flags" - "github.com/wolfeidau/aws-billing-service/internal/hive" + "github.com/wolfeidau/aws-billing-store/internal/cur" + "github.com/wolfeidau/aws-billing-store/internal/events" + "github.com/wolfeidau/aws-billing-store/internal/events/s3created" + "github.com/wolfeidau/aws-billing-store/internal/hive" ) type Handler struct { - cfg flags.S3Events s3client *s3.Client sgen *hive.SymlinkGenerator } -func NewHandler(ctx context.Context, cfg flags.S3Events) (*Handler, error) { +func NewHandler(ctx context.Context) (*Handler, error) { config, err := config.LoadDefaultConfig(ctx) if err != nil { return nil, err @@ -32,7 +30,6 @@ func NewHandler(ctx context.Context, cfg flags.S3Events) (*Handler, error) { s3client := s3.NewFromConfig(config) return &Handler{ - cfg: cfg, s3client: s3client, sgen: hive.NewSymlinkGenerator(s3client), }, nil @@ -92,13 +89,18 @@ func (h *Handler) processCreated(ctx context.Context, created *s3created.ObjectC return nil, err } - // update the hive structure for athena - hivePartitions := []string{ - fmt.Sprintf("year=%d", startDate.Year()), - fmt.Sprintf("month=%d", startDate.Month()), + hivePartitions := hive.HivePartitions{ + "year": fmt.Sprintf("%d", startDate.Year()), + "month": fmt.Sprintf("%d", startDate.Month()), } - _, err = h.sgen.StoreSymlink(ctx, created.Bucket.Name, manifestPeriod.Prefix, hivePartitions, manifest.ReportKeys) + keys := make([]string, len(manifest.ReportKeys)) + + for i, reportKey := range manifest.ReportKeys { + keys[i] = fmt.Sprintf("s3://%s/%s", created.Bucket.Name, reportKey) + } + + _, err = h.sgen.StoreSymlink(ctx, created.Bucket.Name, manifestPeriod.Prefix, hivePartitions, keys) if err != nil { return nil, err } diff --git a/internal/symlink/handler_test.go b/internal/symlink/handler_test.go new file mode 100644 index 0000000..5fc499f --- /dev/null +++ b/internal/symlink/handler_test.go @@ -0,0 +1 @@ +package symlink diff --git a/sam/app/athena-workspace.yaml b/sam/app/athena-workspace.yaml new file mode 100644 index 0000000..c7ad825 --- /dev/null +++ b/sam/app/athena-workspace.yaml @@ -0,0 +1,103 @@ +AWSTemplateFormatVersion: "2010-09-09" +Transform: AWS::Serverless-2016-10-31 +Description: "wolfeidau: Athena results." + +Parameters: + AppName: + Type: String + Description: The name of the application. + + Stage: + Type: String + Description: The stage where the stac is running in, e.g., dev, prod. + Default: dev + + Branch: + Type: String + Description: The branch the stack was deployed. + Default: master + + ObjectExpirationInDays: + Type: Number + Default: 14 + +Outputs: + AthenaWorkGroupName: + Value: !Sub ${AppName}-${Branch}-${Stage}-workgroup + Description: "Athena workgroup name" + + QueryResultsBucketName: + Description: "Athena query results bucket name" + Value: !Ref QueryResultsBucketName + +Resources: + AthenaWorkGroup: + Type: AWS::Athena::WorkGroup + Properties: + Name: !Sub ${AppName}-${Branch}-${Stage}-workgroup + Description: Stax Work Group + WorkGroupConfiguration: + BytesScannedCutoffPerQuery: 10000000 + EnforceWorkGroupConfiguration: true + PublishCloudWatchMetricsEnabled: true + ResultConfiguration: + EncryptionConfiguration: + EncryptionOption: SSE_S3 + OutputLocation: !Sub s3://${QueryResultsBucket}/results + + QueryResultsBucket: + Type: AWS::S3::Bucket + DeletionPolicy: Retain + UpdateReplacePolicy: Retain + Properties: + BucketEncryption: + ServerSideEncryptionConfiguration: + - ServerSideEncryptionByDefault: + SSEAlgorithm: AES256 + LifecycleConfiguration: + Rules: + - Id: DeletionRule + Status: Enabled + ExpirationInDays: !Ref ObjectExpirationInDays + PublicAccessBlockConfiguration: + BlockPublicAcls: True + BlockPublicPolicy: True + IgnorePublicAcls: True + RestrictPublicBuckets: True + + QueryResultsBucketPolicy: + Type: AWS::S3::BucketPolicy + DeletionPolicy: Retain + UpdateReplacePolicy: Retain + Properties: + Bucket: !Ref QueryResultsBucket + PolicyDocument: + Statement: + - Sid: AllowSSLRequestsOnly + Effect: Deny + Principal: "*" + Action: + - s3:* + Resource: + - !Sub "arn:aws:s3:::${QueryResultsBucket}/*" + - !Sub "arn:aws:s3:::${QueryResultsBucket}" + Condition: + Bool: + "aws:SecureTransport": false + + QueryResultsBucketName: + Type: "AWS::SSM::Parameter" + Properties: + Name: !Sub "/config/${Stage}/${Branch}/${AppName}/athena_query_results_bucketname" + Type: "String" + Value: !Ref QueryResultsBucket + Description: "Athena query results bucket name" + + AthenaWorkGroupName: + Type: "AWS::SSM::Parameter" + Properties: + Name: !Sub "/config/${Stage}/${Branch}/${AppName}/athena_workgroup_name" + Type: "String" + Value: !Sub ${AppName}-${Branch}-${Stage}-workgroup + Description: "Athena workgroup name" + diff --git a/sam/app/athena.yaml b/sam/app/athena.yaml new file mode 100644 index 0000000..fb6ad20 --- /dev/null +++ b/sam/app/athena.yaml @@ -0,0 +1,294 @@ +AWSTemplateFormatVersion: "2010-09-09" +Description: "wolfeidau: aws billing Glue database and Athena table" + +Parameters: + AppName: + Type: String + Description: Application Name used to store configuration. + Stage: + Type: String + Description: The stage where the stack is running in, e.g., dev, prod. + Default: dev + Branch: + Type: String + Description: The branch the stack was deployed. + Default: master + ReportBucketName: + Description: The name of the bucket you have configured to receive CUR files. + Type: String + CurPrefix: + Type: String + Description: The prefix for the CUR files in the bucket, this should exclude the leading '/'. + +Outputs: + GlueDatabase: + Value: !Ref GlueDatabase + GlueTable: + Value: !Ref GlueTable + +Resources: + GlueDatabase: + Type: AWS::Glue::Database + Properties: + CatalogId: !Ref AWS::AccountId + DatabaseInput: + Name: !Sub awsbilling_${Branch}_${Stage} + Description: awsbilling CUR database + + GlueTable: + Type: AWS::Glue::Table + Properties: + DatabaseName: !Ref GlueDatabase + CatalogId: !Ref AWS::AccountId + TableInput: + Name: raw_cur_data + StorageDescriptor: + Columns: + - Name: identity_line_item_id + Type: string + - Name: identity_time_interval + Type: string + - Name: bill_invoice_id + Type: string + - Name: bill_invoicing_entity + Type: string + - Name: bill_billing_entity + Type: string + - Name: bill_bill_type + Type: string + - Name: bill_payer_account_id + Type: string + - Name: bill_billing_period_start_date + Type: timestamp + - Name: bill_billing_period_end_date + Type: timestamp + - Name: line_item_usage_account_id + Type: string + - Name: line_item_line_item_type + Type: string + - Name: line_item_usage_start_date + Type: timestamp + - Name: line_item_usage_end_date + Type: timestamp + - Name: line_item_product_code + Type: string + - Name: line_item_usage_type + Type: string + - Name: line_item_operation + Type: string + - Name: line_item_availability_zone + Type: string + - Name: line_item_resource_id + Type: string + - Name: line_item_usage_amount + Type: double + - Name: line_item_normalization_factor + Type: double + - Name: line_item_normalized_usage_amount + Type: double + - Name: line_item_currency_code + Type: string + - Name: line_item_unblended_rate + Type: string + - Name: line_item_unblended_cost + Type: double + - Name: line_item_blended_rate + Type: string + - Name: line_item_blended_cost + Type: double + - Name: line_item_line_item_description + Type: string + - Name: line_item_tax_type + Type: string + - Name: line_item_legal_entity + Type: string + - Name: product_product_name + Type: string + - Name: product_alarm_type + Type: string + - Name: product_availability + Type: string + - Name: product_ci_type + Type: string + - Name: product_description + Type: string + - Name: product_durability + Type: string + - Name: product_endpoint_type + Type: string + - Name: product_event_type + Type: string + - Name: product_fee_code + Type: string + - Name: product_fee_description + Type: string + - Name: product_from_location + Type: string + - Name: product_from_location_type + Type: string + - Name: product_from_region_code + Type: string + - Name: product_group + Type: string + - Name: product_group_description + Type: string + - Name: product_location + Type: string + - Name: product_location_type + Type: string + - Name: product_logs_destination + Type: string + - Name: product_message_delivery_frequency + Type: string + - Name: product_message_delivery_order + Type: string + - Name: product_operation + Type: string + - Name: product_platopricingtype + Type: string + - Name: product_platostoragetype + Type: string + - Name: product_platovolumetype + Type: string + - Name: product_product_family + Type: string + - Name: product_queue_type + Type: string + - Name: product_region + Type: string + - Name: product_region_code + Type: string + - Name: product_request_description + Type: string + - Name: product_request_type + Type: string + - Name: product_routing_target + Type: string + - Name: product_routing_type + Type: string + - Name: product_servicecode + Type: string + - Name: product_servicename + Type: string + - Name: product_sku + Type: string + - Name: product_storage_class + Type: string + - Name: product_storage_media + Type: string + - Name: product_storage_type + Type: string + - Name: product_tickettype + Type: string + - Name: product_to_location + Type: string + - Name: product_to_location_type + Type: string + - Name: product_to_region_code + Type: string + - Name: product_transfer_type + Type: string + - Name: product_usagetype + Type: string + - Name: product_version + Type: string + - Name: product_volume_type + Type: string + - Name: pricing_rate_code + Type: string + - Name: pricing_rate_id + Type: string + - Name: pricing_currency + Type: string + - Name: pricing_public_on_demand_cost + Type: double + - Name: pricing_public_on_demand_rate + Type: string + - Name: pricing_term + Type: string + - Name: pricing_unit + Type: string + - Name: reservation_amortized_upfront_cost_for_usage + Type: double + - Name: reservation_amortized_upfront_fee_for_billing_period + Type: double + - Name: reservation_effective_cost + Type: double + - Name: reservation_end_time + Type: string + - Name: reservation_modification_status + Type: string + - Name: reservation_normalized_units_per_reservation + Type: string + - Name: reservation_number_of_reservations + Type: string + - Name: reservation_recurring_fee_for_usage + Type: double + - Name: reservation_start_time + Type: string + - Name: reservation_subscription_id + Type: string + - Name: reservation_total_reserved_normalized_units + Type: string + - Name: reservation_total_reserved_units + Type: string + - Name: reservation_units_per_reservation + Type: string + - Name: reservation_unused_amortized_upfront_fee_for_billing_period + Type: double + - Name: reservation_unused_normalized_unit_quantity + Type: double + - Name: reservation_unused_quantity + Type: double + - Name: reservation_unused_recurring_fee + Type: double + - Name: reservation_upfront_value + Type: double + - Name: savings_plan_total_commitment_to_date + Type: double + - Name: savings_plan_savings_plan_a_r_n + Type: string + - Name: savings_plan_savings_plan_rate + Type: double + - Name: savings_plan_used_commitment + Type: double + - Name: savings_plan_savings_plan_effective_cost + Type: double + - Name: savings_plan_amortized_upfront_commitment_for_billing_period + Type: double + - Name: savings_plan_recurring_commitment_for_billing_period + Type: double + Location: !Sub s3://${ReportBucketName}/${CurPrefix}/hive/ + InputFormat: org.apache.hadoop.hive.ql.io.SymlinkTextInputFormat + OutputFormat: org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat + Compressed: false + NumberOfBuckets: -1 + SerdeInfo: + SerializationLibrary: org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe + Parameters: + serialization.format: "1" + BucketColumns: [] + SortColumns: [] + StoredAsSubDirectories: false + PartitionKeys: + - Name: year + Type: string + - Name: month + Type: string + TableType: EXTERNAL_TABLE + + GlueDatabaseName: + Type: "AWS::SSM::Parameter" + Properties: + Name: !Sub "/config/${Stage}/${Branch}/${AppName}/glue_database_name" + Type: "String" + Value: !Sub awsbilling_${Branch}_${Stage} + Description: "Glue database name" + + GlueTableName: + Type: "AWS::SSM::Parameter" + Properties: + Name: !Sub "/config/${Stage}/${Branch}/${AppName}/glue_table_name" + Type: "String" + Value: raw_cur_data + Description: "Glue table name" \ No newline at end of file diff --git a/sam/app/cur-bucket.yaml b/sam/app/cur-bucket.yaml new file mode 100644 index 0000000..fa3acba --- /dev/null +++ b/sam/app/cur-bucket.yaml @@ -0,0 +1,87 @@ +AWSTemplateFormatVersion: "2010-09-09" +Description: "wolfeidau: aws billing cost and use report bucket" + +Parameters: + AppName: + Type: String + Description: Application Name used to store configuration. + Stage: + Type: String + Description: The stage where the stack is running in, e.g., dev, prod. + Default: dev + Branch: + Type: String + Description: The branch the stack was deployed. + Default: master + ReportPrefix: + Type: String + +Outputs: + ReportBucket: + Value: !Ref ReportBucket + +Resources: + ReportBucket: + Type: AWS::S3::Bucket + DeletionPolicy: Retain + UpdateReplacePolicy: Retain + Properties: + BucketEncryption: + ServerSideEncryptionConfiguration: + - ServerSideEncryptionByDefault: + SSEAlgorithm: AES256 + PublicAccessBlockConfiguration: + BlockPublicAcls: true + BlockPublicPolicy: true + IgnorePublicAcls: true + RestrictPublicBuckets: true + + ReportBucketPolicy: + Type: AWS::S3::BucketPolicy + Properties: + Bucket: !Ref ReportBucket + PolicyDocument: + Statement: + - Sid: ReportDeliveryBucketRead + Action: + - s3:GetBucketAcl + - s3:GetBucketPolicy + Effect: Allow + Principal: + Service: billingreports.amazonaws.com + Resource: !GetAtt ReportBucket.Arn + - Sid: ReportDeliveryObjectWrite + Action: s3:PutObject + Effect: Allow + Principal: + Service: billingreports.amazonaws.com + Resource: !Sub ${ReportBucket.Arn}/* + - Sid: AllowSSLRequestsOnly + Effect: Deny + Principal: "*" + Action: + - s3:* + Resource: + - Fn::Sub: arn:aws:s3:::${ReportBucket}/* + - Fn::Sub: arn:aws:s3:::${ReportBucket} + Condition: + Bool: + aws:SecureTransport: false + + ReportBucketParam: + Type: AWS::SSM::Parameter + Properties: + Name: + Fn::Sub: /config/${Stage}/${Branch}/${AppName}/report_bucket + Type: String + Value: + Ref: ReportBucket + + ReportPrefixParam: + Type: AWS::SSM::Parameter + Properties: + Name: + Fn::Sub: /config/${Stage}/${Branch}/${AppName}/report_prefix + Type: String + Value: + Ref: ReportPrefix \ No newline at end of file diff --git a/sam/app/cur.yaml b/sam/app/cur.yaml new file mode 100644 index 0000000..e5eac6a --- /dev/null +++ b/sam/app/cur.yaml @@ -0,0 +1,27 @@ +AWSTemplateFormatVersion: "2010-09-09" +Description: "wolfeidau: aws billing cost and use report configuration in us-east-1" + +Parameters: + ReportBucketName: + Type: String + ReportPrefix: + Type: String + Default: cur + ReportBucketRegion: + Type: String + +Resources: + DailyAthenaReportDefinition: + Type: AWS::CUR::ReportDefinition + Properties: + AdditionalSchemaElements: + - RESOURCES + Compression: Parquet + Format: Parquet + RefreshClosedReports: true + ReportName: !Sub ${AWS::StackName}-athena-hourly + ReportVersioning: CREATE_NEW_REPORT + S3Bucket: !Ref ReportBucketName + S3Prefix: !Ref ReportPrefix + S3Region: !Ref ReportBucketRegion + TimeUnit: HOURLY diff --git a/sam/app/deploy.yaml b/sam/app/deploy.yaml new file mode 100644 index 0000000..fbbf74d --- /dev/null +++ b/sam/app/deploy.yaml @@ -0,0 +1,71 @@ +AWSTemplateFormatVersion: "2010-09-09" +Description: + "wolfeidau: Cloudformation deployment infra used to host Serverless Applications Model (SAM) artifacts." +Parameters: + Stage: + Type: String + Description: The stage where the application is running in, e.g., dev, prod. + Default: dev + Branch: + Type: String + Default: master + RetentionInDays: + Description: + Retain the assets uploaded to the deployment bucket for this many + days. + Type: Number + Default: 7 + +Outputs: + BucketName: + Value: + Ref: Bucket + +Resources: + Bucket: + Type: AWS::S3::Bucket + Properties: + BucketEncryption: + ServerSideEncryptionConfiguration: + - ServerSideEncryptionByDefault: + SSEAlgorithm: AES256 + PublicAccessBlockConfiguration: + BlockPublicAcls: true + BlockPublicPolicy: true + IgnorePublicAcls: true + RestrictPublicBuckets: true + LifecycleConfiguration: + Rules: + - Id: DeleteEverything + Prefix: "" + Status: Enabled + ExpirationInDays: + Ref: RetentionInDays + + BucketPolicy: + Type: AWS::S3::BucketPolicy + Properties: + Bucket: + Ref: Bucket + PolicyDocument: + Statement: + - Sid: AllowSSLRequestsOnly + Effect: Deny + Principal: "*" + Action: + - s3:* + Resource: + - Fn::Sub: arn:aws:s3:::${Bucket}/* + - Fn::Sub: arn:aws:s3:::${Bucket} + Condition: + Bool: + aws:SecureTransport: false + + BucketParam: + Type: AWS::SSM::Parameter + Properties: + Name: + Fn::Sub: /config/${Stage}/${Branch}/deploy_bucket + Type: String + Value: + Ref: Bucket diff --git a/sam/app/partitions.yaml b/sam/app/partitions.yaml new file mode 100644 index 0000000..2e76e66 --- /dev/null +++ b/sam/app/partitions.yaml @@ -0,0 +1,97 @@ +AWSTemplateFormatVersion: "2010-09-09" +Transform: AWS::Serverless-2016-10-31 +Description: "wolfeidau: aws billing partition lambda which detects new files in the CUR hive folder and creates athena partitions" + +Parameters: + Stage: + Type: String + Description: The stage where the stack is running in, e.g., dev, prod. + Default: dev + Branch: + Type: String + Description: The branch the stack was deployed. + Default: master + ReportBucketName: + Description: The name of the bucket you have configured to receive CUR files. + Type: String + CurPrefix: + Type: String + Description: The prefix for the CUR files in the bucket, this should exclude the leading '/'. + Commit: + Type: String + GlueDatabase: + Type: String + GlueTable: + Type: String + QueryResultsBucketName: + Type: String + + +Conditions: + IsDev: !Equals [!Ref Stage, "dev"] + IsProd: !Equals [!Ref Stage, "prod"] + +Globals: + Function: + Runtime: go1.x + Timeout: 30 + MemorySize: 256 + Environment: + Variables: + STAGE: !Ref Stage + BRANCH: !Ref Branch + COMMIT: !Ref Commit + AWS_ACCOUNT_ID: !Ref "AWS::AccountId" + RAW_EVENT_LOGGING: !If [IsDev, "true", "false"] + +Resources: + PartitionsFunctionLogGroup: + Type: AWS::Logs::LogGroup + Properties: + LogGroupName: !Sub "/aws/lambda/${PartitionsFunction}" + RetentionInDays: !If [IsProd, 365, 14] + + PartitionsFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: ../../dist/handler.zip + Handler: partitions-curs-lambda + Environment: + Variables: + DATABASE: !Ref GlueDatabase + TABLE: !Ref GlueTable + QUERY_BUCKET: !Ref QueryResultsBucketName + Policies: + - S3ReadPolicy: + BucketName: !Ref QueryResultsBucketName + - S3WritePolicy: + BucketName: !Ref QueryResultsBucketName + - Version: "2012-10-17" + Statement: + - Effect: Allow + Action: + - "athena:StartQueryExecution" + - "athena:GetQueryExecution" + - "athena:GetQueryResults" + - "athena:GetWorkGroup" + - "athena:GetDatabase" + - "glue:BatchCreatePartition" + - "glue:GetTable" + - "glue:GetDatabase" + Resource: "*" + Events: + S3EventRule: + Type: EventBridgeRule + Properties: + Pattern: + source: + - "aws.s3" + "detail-type": + - "Object Created" + detail: + bucket: + name: + - !Ref ReportBucketName + object: + key: + - prefix: !Sub "${CurPrefix}/hive" \ No newline at end of file diff --git a/sam/app/symlink.yaml b/sam/app/symlink.yaml index 8b29ec6..144234a 100644 --- a/sam/app/symlink.yaml +++ b/sam/app/symlink.yaml @@ -1,6 +1,6 @@ AWSTemplateFormatVersion: "2010-09-09" Transform: AWS::Serverless-2016-10-31 -Description: "wolfeidau: aws billing symlink lambda which maintains the hive structure using symlinks for Athena" +Description: "wolfeidau: aws billing symlink lambda which maintains the hive structure for Athena" Parameters: AppName: @@ -16,11 +16,7 @@ Parameters: Default: master Commit: Type: String - LogLevel: - Type: String - Default: info - AllowedValues: ["trace", "debug", "info", "warn", "error", "fatal", "panic"] - DataBucketName: + ReportBucketName: Description: The name of the bucket you have configured to receive CUR files. Type: String CurPrefix: @@ -40,7 +36,6 @@ Globals: Variables: STAGE: !Ref Stage BRANCH: !Ref Branch - LOG_LEVEL: !Ref LogLevel COMMIT: !Ref Commit AWS_ACCOUNT_ID: !Ref "AWS::AccountId" RAW_EVENT_LOGGING: !If [IsDev, "true", "false"] @@ -59,7 +54,7 @@ Resources: Handler: symlink-curs-lambda Policies: - S3CrudPolicy: - BucketName: !Ref DataBucketName + BucketName: !Ref ReportBucketName Events: S3EventRule: Type: EventBridgeRule @@ -72,7 +67,7 @@ Resources: detail: bucket: name: - - !Ref DataBucketName + - !Ref ReportBucketName object: key: - prefix: !Ref CurPrefix \ No newline at end of file