Skip to content

Commit

Permalink
[IT-3068] Lambda for emailing monthly S3 cost reports (#1)
Browse files Browse the repository at this point in the history
* Fork from Sage-Bionetworks-IT/lambda-finops-email-totals#1.1.4
* Rename to lamda-finops-s3-cost-report
* Convert lambda to meet STRIDES' needs for IT-3068

Send a monthly email with the total monthly costs broken down by AWS service, and the total monthly S3 costs broken down by usage type.
  • Loading branch information
ConsoleCatzirl authored Oct 16, 2024
1 parent a1a71d6 commit 81b7394
Show file tree
Hide file tree
Showing 20 changed files with 2,692 additions and 331 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
relative_files = True

# Use 'source' instead of 'omit' in order to ignore 'tests/unit/__init__.py'
source = hello_world
source = s3_cost_report
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: sam-build
name: sam-build-and-lint

runs:
# This creates a composite action to be used as a step in a job
Expand All @@ -8,7 +8,7 @@ runs:
# Convert Pipfile.lock to requirements.txt for sam
- uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: 3.12
- run: pip install -U pipenv
shell: bash

Expand All @@ -21,6 +21,14 @@ runs:
with:
use-installer: true

# Lint the input template
- run: sam validate --lint
shell: bash

# Use a lambda-like docker container to build the lambda artifact
- run: sam build --use-container
shell: bash

# Lint the built template
- run: sam validate --lint --template .aws-sam/build/template.yaml
shell: bash
9 changes: 6 additions & 3 deletions .github/workflows/post-merge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
steps:
- uses: actions/checkout@v4

# Install sam-cli and run "sam build"
- uses: ./.github/actions/sam-build
# install sam-cli, build, and lint
- uses: ./.github/actions/sam-build-and-lint

# authenticate with AWS via OIDC
- uses: aws-actions/configure-aws-credentials@v4
Expand All @@ -38,5 +38,8 @@ jobs:
# upload the lambda artifact to s3 and generate a cloudformation template referencing it
- run: sam package --template-file .aws-sam/build/template.yaml --s3-bucket $ESSENTIALS_BUCKET --s3-prefix ${{ github.event.repository.name }}/${{ github.ref_name }} --output-template-file .aws-sam/build/${{ github.event.repository.name }}.yaml

# upload the generated cloudformation template to s3
# validate final template with cloudformation
- run: aws cloudformation validate-template --template-body file://.aws-sam/build/${{ github.event.repository.name }}.yaml

# upload the final template to s3
- run: aws s3 cp .aws-sam/build/${{ github.event.repository.name }}.yaml s3://$BOOTSTRAP_BUCKET/${{ github.event.repository.name }}/${{ github.ref_name }}/
13 changes: 7 additions & 6 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: 3.12
- uses: pre-commit/[email protected]

pytest:
Expand All @@ -23,18 +23,19 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: 3.12
- run: pip install -U pipenv
- run: pipenv install --dev
- run: pipenv run coverage run -m pytest tests/ -vv
- run: pipenv sync --dev
- run: pipenv run coverage run -m pytest tests/ -svv
- run: pipenv run coverage lcov
- name: upload coverage to coveralls
uses: coverallsapp/github-action@v2
with:
file: coverage.lcov
fail-on-error: false

sam-build-and-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/sam-build
- run: sam validate --lint --template .aws-sam/build/template.yaml
- uses: ./.github/actions/sam-build-and-lint
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ coverage.xml
*.py,cover
.hypothesis/
.pytest_cache/
coverage.lcov

# Translations
*.mo
Expand Down
13 changes: 9 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ repos:
rev: v1.5.5
hooks:
- id: remove-tabs
- repo: https://github.com/aristanetworks/j2lint.git
rev: v1.1.0
hooks:
- id: j2lint
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.18 # Use the ref you want to point at
hooks:
- id: mdformat
# Optionally add plugins
additional_dependencies:
- mdformat-gfm # github-flavored markdown
files: README.md
args: [--wrap=80]
11 changes: 6 additions & 5 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
pytest = "~=7.1"
pytest = "~=8.3"
pytest-mock = "~=3.8"
boto3 = "~=1.24"
coverage = "~=7.3"
coverage = "~=7.0"
pre-commit = "~=4.0"
aws-sam-cli = "~=1.0"

[packages]
crhelper = "~=2.0"
boto3 = "~=1.24"

[requires]
python_version = "3.9"
python_version = "3.12"
Loading

0 comments on commit 81b7394

Please sign in to comment.