-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat-mm/238-notify-metadata-state-change
- Loading branch information
Showing
12 changed files
with
510 additions
and
75 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
22 changes: 22 additions & 0 deletions
22
lib/workload/stateless/stacks/metadata-manager/app/management/commands/load_from_csv.py
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,22 @@ | ||
import logging | ||
from django.core.management import BaseCommand | ||
from libumccr import libjson | ||
|
||
from handler.load_custom_metadata_csv import handler | ||
|
||
logger = logging.getLogger() | ||
logger.setLevel(logging.INFO) | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Trigger lambda handler for to sync metadata from csv url" | ||
|
||
def handle(self, *args, **options): | ||
event = { | ||
"url": "SOME_URL", | ||
} | ||
|
||
print(f"Trigger lambda handler for sync tracking sheet. Event {libjson.dumps(event)}") | ||
result = handler(event, {}) | ||
|
||
print(f"result: {libjson.dumps(result)}") |
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
54 changes: 54 additions & 0 deletions
54
...rkload/stateless/stacks/metadata-manager/deploy/construct/lambda-load-custom-csv/index.ts
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,54 @@ | ||
import path from 'path'; | ||
import { Construct } from 'constructs'; | ||
import { Duration } from 'aws-cdk-lib'; | ||
import { PythonFunction } from '@aws-cdk/aws-lambda-python-alpha'; | ||
import { ISecret } from 'aws-cdk-lib/aws-secretsmanager'; | ||
import { StringParameter } from 'aws-cdk-lib/aws-ssm'; | ||
import { | ||
DockerImageFunction, | ||
DockerImageFunctionProps, | ||
DockerImageCode, | ||
} from 'aws-cdk-lib/aws-lambda'; | ||
|
||
type LambdaProps = { | ||
/** | ||
* The basic common lambda properties that it should inherit from | ||
*/ | ||
basicLambdaConfig: Partial<DockerImageFunctionProps>; | ||
/** | ||
* The secret for the db connection where the lambda will need access to | ||
*/ | ||
dbConnectionSecret: ISecret; | ||
}; | ||
|
||
export class LambdaLoadCustomCSVConstruct extends Construct { | ||
private readonly lambda: PythonFunction; | ||
|
||
constructor(scope: Construct, id: string, lambdaProps: LambdaProps) { | ||
super(scope, id); | ||
|
||
this.lambda = new DockerImageFunction(this, 'LoadCustomCSVLambda', { | ||
environment: { | ||
...lambdaProps.basicLambdaConfig.environment, | ||
}, | ||
securityGroups: lambdaProps.basicLambdaConfig.securityGroups, | ||
vpc: lambdaProps.basicLambdaConfig.vpc, | ||
vpcSubnets: lambdaProps.basicLambdaConfig.vpcSubnets, | ||
architecture: lambdaProps.basicLambdaConfig.architecture, | ||
code: DockerImageCode.fromImageAsset(path.join(__dirname, '../../../'), { | ||
file: 'deploy/construct/lambda-load-custom-csv/lambda.Dockerfile', | ||
}), | ||
timeout: Duration.minutes(15), | ||
memorySize: 4096, | ||
}); | ||
|
||
lambdaProps.dbConnectionSecret.grantRead(this.lambda); | ||
|
||
// We need to store this lambda ARN somewhere so that we could refer when need to load this manually | ||
const ssmParameter = new StringParameter(this, 'LoadCustomCSVLambdaArnParameterStore', { | ||
parameterName: '/orcabus/metadata-manager/load-custom-csv-lambda-arn', | ||
description: 'The ARN of the lambda that load metadata from a presigned URL CSV file', | ||
stringValue: this.lambda.functionArn, | ||
}); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...ateless/stacks/metadata-manager/deploy/construct/lambda-load-custom-csv/lambda.Dockerfile
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,12 @@ | ||
FROM public.ecr.aws/lambda/python:3.12 | ||
|
||
WORKDIR ${LAMBDA_TASK_ROOT} | ||
|
||
# COPY all files | ||
COPY . . | ||
|
||
# Install the specified packages | ||
RUN pip install -r deps/requirements-full.txt | ||
|
||
# Specify handler | ||
CMD [ "handler.load_custom_metadata_csv.handler" ] |
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
2 changes: 1 addition & 1 deletion
2
lib/workload/stateless/stacks/metadata-manager/docs/architecture.drawio.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions
35
lib/workload/stateless/stacks/metadata-manager/handler/load_custom_metadata_csv.py
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,35 @@ | ||
import django | ||
import os | ||
import logging | ||
|
||
from libumccr import libjson | ||
|
||
from proc.service.utils import sanitize_lab_metadata_df, warn_drop_duplicated_library | ||
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings.base') | ||
django.setup() | ||
|
||
from proc.service.load_csv_srv import load_metadata_csv, download_csv_to_pandas | ||
|
||
logger = logging.getLogger() | ||
logger.setLevel(logging.INFO) | ||
|
||
|
||
def handler(event, _context): | ||
logger.info(f'event: {libjson.dumps(event)}') | ||
|
||
csv_url = event.get('url', None) | ||
if csv_url is None: | ||
raise ValueError("URL is required") | ||
|
||
csv_df = download_csv_to_pandas(csv_url) | ||
sanitize_df = sanitize_lab_metadata_df(csv_df) | ||
duplicate_clean_df = warn_drop_duplicated_library(sanitize_df) | ||
result = load_metadata_csv(duplicate_clean_df) | ||
|
||
logger.info(f'persist report: {libjson.dumps(result)}') | ||
return result | ||
|
||
|
||
if __name__ == '__main__': | ||
handler({}, {}) |
Oops, something went wrong.