Skip to content

Commit

Permalink
Fix: Error related to saving subrecipients for treasury-report genera…
Browse files Browse the repository at this point in the history
…tion (#454)

* fix: naming and permissions

* fix: ensure lambdas have access to get and put subrecipients file
  • Loading branch information
as1729 authored Sep 27, 2024
1 parent 2fd8210 commit 80cae1e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export const processRecord = async (
}

try {
const subrecipientKey = `treasuryreports/${organizationId}/${reportingPeriod.id}/subrecipients`
const subrecipientKey = `treasuryreports/${organizationId}/${reportingPeriod.id}/subrecipients.json`
const { startDate, endDate } = reportingPeriod
const subrecipientsWithUploads = await db.subrecipient.findMany({
where: { createdAt: { lte: endDate, gte: startDate } },
Expand Down
6 changes: 3 additions & 3 deletions python/src/functions/subrecipient_treasury_report_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def process_event(
download_s3_object(
client=s3_client,
bucket=os.environ["REPORTING_DATA_BUCKET_NAME"],
key=f"treasuryreports/{organization_id}/{reporting_period_id}/subrecipients",
key=f"treasuryreports/{organization_id}/{reporting_period_id}/subrecipients.json",
destination=recent_subrecipients_file,
)
except ClientError as e:
Expand Down Expand Up @@ -224,7 +224,7 @@ def upload_workbook(
Handles upload of workbook to S3, both in xlsx and csv formats
"""

with tempfile.NamedTemporaryFile("w") as new_xlsx_file:
with tempfile.NamedTemporaryFile("rb+") as new_xlsx_file:
workbook.save(new_xlsx_file.name)
upload_generated_file_to_s3(
s3client,
Expand All @@ -237,7 +237,7 @@ def upload_workbook(
new_xlsx_file,
)

with tempfile.NamedTemporaryFile("w") as new_csv_file:
with tempfile.NamedTemporaryFile("r+") as new_csv_file:
convert_xlsx_to_csv(
new_csv_file,
workbook,
Expand Down
11 changes: 11 additions & 0 deletions terraform/functions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,17 @@ module "lambda_function-processValidationJson" {
"${module.reporting_data_bucket.bucket_arn}/uploads/*/*/*/*/*.json",
]
}
AllowUploadSubrecipientsFile = {
effect = "Allow"
actions = [
"s3:PutObject",
]
resources = [
# These are temporary files shared across services containing subrecipient data.
# Path: treasuryreports/{organization_id}/{reporting_period_id}/subrecipients.json
"${module.reporting_data_bucket.bucket_arn}/treasuryreports/*/*/subrecipients.json",
]
}
}

// Artifacts
Expand Down
4 changes: 2 additions & 2 deletions terraform/treasury_generation_lambda_functions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ module "lambda_function-subrecipientTreasuryReportGen" {
]
resources = [
# These are temporary files shared across services containing subrecipient data.
# Path: /{organization_id}/{reporting_period_id}/subrecipients
"${module.reporting_data_bucket.bucket_arn}/*/*/subrecipients",
# Path: treasuryreports/{organization_id}/{reporting_period_id}/subrecipients.json
"${module.reporting_data_bucket.bucket_arn}/treasuryreports/*/*/subrecipients.json",
]
}
AllowDownloadTreasuryOutputTemplates = {
Expand Down

0 comments on commit 80cae1e

Please sign in to comment.