@@ -26,6 +26,7 @@ import _ from 'lodash';
2626
2727import { Config , ConfigFile , ConfigSchema } from '../lib/schema' ;
2828import { LisaServeApplicationStage } from '../lib/stages' ;
29+ import { SSMClient , GetParameterCommand , SSMServiceException } from '@aws-sdk/client-ssm' ;
2930
3031// Read configuration files
3132const baseConfigFilePath = path . join ( __dirname , '../config-base.yaml' ) ;
@@ -71,12 +72,43 @@ const env: cdk.Environment = {
7172 region : config . region ,
7273} ;
7374
74- // Application
75- const app = new cdk . App ( ) ;
75+ function getExistingRagRepositories ( ) {
76+ const registeredRepositoriesParamName = `${ config . deploymentPrefix } /registeredRepositories` ;
77+ const client = new SSMClient ( { region : config . region } ) ;
78+ const command = new GetParameterCommand ( { Name : registeredRepositoriesParamName } ) ;
7679
77- new LisaServeApplicationStage ( app , config . deploymentStage , {
78- env : env ,
79- config : config ,
80- } ) ;
80+ return client . send ( command )
81+ . then ( ( response ) => {
82+ console . log ( 'SSM Parameter Value:' , response . Parameter ?. Value ) ;
83+ return response . Parameter ?. Value ? JSON . parse ( response . Parameter . Value ! ) : [ ] ;
84+ } )
85+ . catch ( ( error : SSMServiceException ) => {
86+ // Handle parameter not found separately
87+ if ( error . name === 'ParameterNotFound' ) {
88+ console . error ( `Parameter '${ registeredRepositoriesParamName } ' not found.` ) ;
89+ return [ ] ;
90+ }
91+
92+ // Handle other errors
93+ console . error ( 'Error fetching SSM parameter:' , error ) ;
94+ throw error ;
95+ } ) ;
96+ }
97+
98+ ( async ( ) => {
99+ // Lookup and pass any previously deployed RAG configurations as an environment variable
100+ // so we can disallow new entries via YAML configuration.
101+ const ragRepositories = await getExistingRagRepositories ( ) ;
102+ process . env . RAG_REPOSITORIES = JSON . stringify ( ragRepositories || [ ] ) ;
103+
104+ // Application
105+ const app = new cdk . App ( ) ;
106+
107+ new LisaServeApplicationStage ( app , config . deploymentStage , {
108+ env : env ,
109+ config : config ,
110+ } ) ;
111+
112+ app . synth ( ) ;
81113
82- app . synth ( ) ;
114+ } ) ( ) ;
0 commit comments