-
Notifications
You must be signed in to change notification settings - Fork 1
[IT-4485] Upload CSV files from MIP to FloQast #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[IT-4485] Upload CSV files from MIP to FloQast #2
Conversation
65a5a47 to
b43f063
Compare
Create a Lambda to periodically fetch balance CSV data from lambda-mips-api and upload it to FloQast.
Pull Request Test Coverage Report for Build 17113633803Details
💛 - Coveralls |
README.md
Outdated
| # lambda-template | ||
| A GitHub template for quickly starting a new AWS lambda project. | ||
| # lambda-finops-floqast-sftp | ||
| AWS Lambda to periodically fetch balance CSV files from lambda-mips-api and upload |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what are balance CSV files? elaboration would be nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new lambda-mips-api endpoint for balances provides the data in CSV format, so I'm referring to the API response as CSV files here. I've reworded this to hopefully make it a little more clear.
floqast_sftp/app.py
Outdated
| None | ||
| """ | ||
| client.putfo(fl=file_obj, remotepath=name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should make sure to close the connection by wrapping this in try finally block. take a look https://stackoverflow.com/a/8293225/1094247
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, great catch! I wasn't closing the session anywhere. I do want to re-use the session for all of the uploads (each activity period has it's own CSV file) so I put the try/finally block around the main lambda_handler loop.
template.yaml
Outdated
| "ssm_secret_prefix": "/floqast-sftp", | ||
| "period_count": "1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't these be passed in as lambda parameters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I was being lazy and hard-coded the values, but I've moved them to template parameters
|
|
||
| # Use 'source' instead of 'omit' in order to ignore 'tests/unit/__init__.py' | ||
| source = hello_world | ||
| source = floqast_sftp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, can't seem to see line coverage in coveralls. it says source not available when click on the source files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see it here for an out-of-date build: https://coveralls.io/builds/74889781
but it took a couple refreshes to get past an ajax error so maybe coveralls is having some sort of partial outage
| if "ssm_secret_prefix" not in event: | ||
| raise ValueError("'ssm_secret_prefix' not provided") | ||
| ssm_prefix = event["ssm_secret_prefix"] | ||
| auth = get_ssm_params(ssm_prefix) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What secrets are required for this lambda? It would help if you can provide some instructions in the docs on setting up these secrets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added to parameter documentation
floqast_sftp/app.py
Outdated
|
|
||
| # number of months to get balances for | ||
| period_count = get_period_count(event) | ||
| logging.info(f"Getting balances for past {period_count} months") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems like an important setting for users however there's no docs for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added to parameter documentation
461aeee to
a04269b
Compare
floqast_sftp/app.py
Outdated
|
|
||
| ssm_client = None | ||
|
|
||
| _csv_url = "https://mips-api.finops.sageit.org/balances?show_inactive_codes" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you think about passing in this var as a lambda parameter in case it ever changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my initial thinking was that it's just one line and easy to update if we need to. but it's probably worth it to make it a parameter so that if we do need to update it, we can do it from org-formation instead of needing to release a new lambda version.
| when = period.isoformat() | ||
| name, file_obj = get_balances_csv(when) | ||
| logging.info(f"Uploading {name} to SFTP server") | ||
| put_sftp_file(client, name, file_obj) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about logging failures? also do you think we need to handle failures or just report them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, great catch, we should definitely add more logging around upload errors, this is currently just relying on the lambda environment logging a generic exception and exiting.
but I'm not sure there's much handling we can do other than logging. and I would prefer for the exceptions to be fatal because if one upload fails, it's very unlikely that the next upload would succeed, and repeated failures might lock us out.
zaro0508
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
🎉 All dependencies have been resolved ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR transforms a lambda template project into a FloQast SFTP integration that periodically fetches trial balance CSV files from lambda-mips-api and uploads them to FloQast via SFTP. The Lambda is configured to run on a schedule and processes multiple months of financial data.
- Replaces the template "hello world" functionality with SFTP file upload logic
- Implements scheduled execution via EventBridge with configurable parameters
- Adds comprehensive error handling and parameter validation for financial data processing
Reviewed Changes
Copilot reviewed 9 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/test_handler.py | Comprehensive test suite covering SSM parameter handling, CSV processing, and Lambda handler scenarios |
| template.yaml | CloudFormation template updated for scheduled execution with SFTP-specific parameters and IAM configuration |
| hello_world/app.py | Removed original template handler code |
| floqast_sftp/app.py | New Lambda handler implementing SFTP client, CSV fetching, and file upload functionality |
| events/event.json | Updated test event structure for scheduled Lambda execution |
| README.md | Documentation updated with SFTP configuration, SSM parameters, and deployment instructions |
| Pipfile | Dependencies updated to include paramiko, requests, and testing libraries |
| .pre-commit-config.yaml | Updated hook versions and added black formatter |
| .coveragerc | Updated source directory reference |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
* Close the SFTP session * Improve documentation * Parameterize inputs * Make the balances endopint URL configurable * Add upload failure logging * Expand some testing
09ece9f to
75c3500
Compare
* Add KMS key for encryting/decrypting SSM parameters * Fix parsing SSM parameter short names * Increase runtime timeout * Improve logging
Create a Lambda to periodically fetch balance CSV data from lambda-mips-api and upload it to FloQast.
Depends on Sage-Bionetworks-IT/lambda-mips-api#50