-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
453 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { Handler } from 'aws-lambda' | ||
import { initTracer, initMeter } from '../../../uploads/src/lib/otel' | ||
import { configurePostgres } from './configuration' | ||
import { NewPostgresStore } from '../postgres/postgresStore' | ||
import { Store } from '../postgres' | ||
import { HealthPlanRevisionTable } from '@prisma/client' | ||
import { isStoreError, StoreError } from '../postgres/storeError' | ||
|
||
export const getDatabaseConnection = async (): Promise<Store> => { | ||
const dbURL = process.env.DATABASE_URL | ||
const secretsManagerSecret = process.env.SECRETS_MANAGER_SECRET | ||
|
||
if (!dbURL) { | ||
console.error('DATABASE_URL not set') | ||
throw new Error('Init Error: DATABASE_URL is required to run app-api') | ||
} | ||
if (!secretsManagerSecret) { | ||
console.error('SECRETS_MANAGER_SECRET not set') | ||
} | ||
|
||
const pgResult = await configurePostgres(dbURL, secretsManagerSecret) | ||
if (pgResult instanceof Error) { | ||
console.error( | ||
"Init Error: Postgres couldn't be configured in data exporter" | ||
) | ||
throw pgResult | ||
} else { | ||
console.info('Postgres configured in data exporter') | ||
} | ||
const store = NewPostgresStore(pgResult) | ||
|
||
return store | ||
} | ||
|
||
export const getRevisions = async ( | ||
store: Store | ||
): Promise<HealthPlanRevisionTable[]> => { | ||
const result: HealthPlanRevisionTable[] | StoreError = | ||
await store.findAllRevisions() | ||
if (isStoreError(result)) { | ||
console.error( | ||
`Error getting revisions from db ${JSON.stringify(result)}` | ||
) | ||
throw new Error('Error getting records; cannot generate report') | ||
} | ||
|
||
return result | ||
} | ||
|
||
export const main: Handler = async (event, context) => { | ||
// Check on the values for our required config | ||
const stageName = process.env.stage ?? 'stageNotSet' | ||
const serviceName = `proto_to_db_lambda-${stageName}` | ||
const otelCollectorURL = process.env.REACT_APP_OTEL_COLLECTOR_URL | ||
if (otelCollectorURL) { | ||
initTracer(serviceName, otelCollectorURL) | ||
} else { | ||
console.error( | ||
'Configuration Error: REACT_APP_OTEL_COLLECTOR_URL must be set' | ||
) | ||
} | ||
|
||
initMeter(serviceName) | ||
const store = await getDatabaseConnection() | ||
|
||
const revisions = await getRevisions(store) | ||
// Get the pkgID from the first revision in the list | ||
const pkgID = revisions[0].pkgID | ||
if (!pkgID) { | ||
console.error('Package ID is missing in the revisions') | ||
throw new Error('Package ID is required') | ||
} | ||
console.info(`Package ID: ${pkgID}`) | ||
|
||
return { | ||
statusCode: 200, | ||
body: JSON.stringify({ | ||
message: 'Lambda function executed successfully', | ||
packageId: pkgID, | ||
}), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.