@@ -21,6 +21,16 @@ import path from 'path';
2121import * as sfn from 'aws-cdk-lib/aws-stepfunctions' ;
2222import * as events from 'aws-cdk-lib/aws-events' ;
2323import * as eventsTargets from 'aws-cdk-lib/aws-events-targets' ;
24+ import * as ssm from 'aws-cdk-lib/aws-ssm' ;
25+ import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager' ;
26+ import * as lambda from 'aws-cdk-lib/aws-lambda' ;
27+ import { MetadataToolsPythonLambdaLayer } from '../../../../../../../components/python-metadata-tools-layer' ;
28+ import {
29+ hostedZoneNameParameterPath ,
30+ jwtSecretName ,
31+ } from '../../../../../../../../../config/constants' ;
32+ import { PythonFunction } from '@aws-cdk/aws-lambda-python-alpha' ;
33+ import { Duration } from 'aws-cdk-lib' ;
2434
2535export interface PieriandxInitialiseLibraryConstructProps {
2636 tableObj : dynamodb . ITableV2 ;
@@ -45,6 +55,51 @@ export class PieriandxInitialiseLibraryConstruct extends Construct {
4555 constructor ( scope : Construct , id : string , props : PieriandxInitialiseLibraryConstructProps ) {
4656 super ( scope , id ) ;
4757
58+ /*
59+ Part 0: Get the metadata layer
60+ */
61+ // Get the metadata layer object
62+ const metadataLayerObj = new MetadataToolsPythonLambdaLayer ( this , 'metadata-tools-layer' , {
63+ layerPrefix : 'nails-get-library' ,
64+ } ) ;
65+
66+ /*
67+ Collect the required secret and ssm parameters for getting metadata
68+ */
69+ const hostnameSsmParameterObj = ssm . StringParameter . fromStringParameterName (
70+ this ,
71+ 'hostname_ssm_parameter' ,
72+ hostedZoneNameParameterPath
73+ ) ;
74+ const orcabusTokenSecretObj = secretsmanager . Secret . fromSecretNameV2 (
75+ this ,
76+ 'orcabus_token_secret' ,
77+ jwtSecretName
78+ ) ;
79+
80+ // Get library objects
81+ const lambdaObj = new PythonFunction ( this , 'get_project_id_from_library_id_py' , {
82+ entry : path . join ( __dirname , 'lambdas' , 'get_project_id_from_library_id_py' ) ,
83+ runtime : lambda . Runtime . PYTHON_3_12 ,
84+ architecture : lambda . Architecture . ARM_64 ,
85+ index : 'get_project_id_from_library_id.py' ,
86+ handler : 'handler' ,
87+ memorySize : 1024 ,
88+ layers : [ metadataLayerObj . lambdaLayerVersionObj ] ,
89+ environment : {
90+ HOSTNAME_SSM_PARAMETER : hostnameSsmParameterObj . parameterName ,
91+ ORCABUS_TOKEN_SECRET_ID : orcabusTokenSecretObj . secretName ,
92+ } ,
93+ // We dont know how big the database will get so will may need a longer timeout
94+ timeout : Duration . seconds ( 120 ) ,
95+ } ) ;
96+
97+ // Allow the lambda to read the secret
98+ orcabusTokenSecretObj . grantRead ( lambdaObj . currentVersion ) ;
99+
100+ // Allow the lambda to read the ssm parameter
101+ hostnameSsmParameterObj . grantRead ( lambdaObj . currentVersion ) ;
102+
48103 /*
49104 Part 1: Build the internal sfn
50105 */
@@ -61,6 +116,10 @@ export class PieriandxInitialiseLibraryConstruct extends Construct {
61116 /* General */
62117 __table_name__ : props . tableObj . tableName ,
63118
119+ /* Lambdas */
120+ __get_project_id_from_library_id_lambda_function_arn__ :
121+ lambdaObj . currentVersion . functionArn ,
122+
64123 /* Table Partitions */
65124 __library_partition_name__ : this . PieriandxInitialiseLibrary . tablePartition . library ,
66125 } ,
@@ -70,7 +129,9 @@ export class PieriandxInitialiseLibraryConstruct extends Construct {
70129 Part 2: Grant the sfn permissions
71130 */
72131 // access the dynamodb table
73- props . tableObj . grantReadWriteData ( inputMakerSfn . role ) ;
132+ props . tableObj . grantReadWriteData ( inputMakerSfn ) ;
133+ // invoke the lambda
134+ lambdaObj . currentVersion . grantInvoke ( inputMakerSfn ) ;
74135
75136 /*
76137 Part 3: Subscribe to the library events from the event bus where the library assay type
0 commit comments