11import * as ros from '@alicloud/ros-cdk-core' ;
22import { RosParameterType } from '@alicloud/ros-cdk-core' ;
3- import { ActionContext , EventTypes , ServerlessIac } from '../types' ;
3+ import {
4+ ActionContext ,
5+ DatabaseEngineMode ,
6+ DatabaseEnum ,
7+ EventTypes ,
8+ ServerlessIac ,
9+ } from '../types' ;
410import * as fc from '@alicloud/ros-cdk-fc3' ;
511import { RosFunction } from '@alicloud/ros-cdk-fc3/lib/fc3.generated' ;
612import * as ram from '@alicloud/ros-cdk-ram' ;
713import * as agw from '@alicloud/ros-cdk-apigateway' ;
814import * as oss from '@alicloud/ros-cdk-oss' ;
915import * as ossDeployment from '@alicloud/ros-cdk-ossdeployment' ;
16+ import * as esServerless from '@alicloud/ros-cdk-elasticsearchserverless' ;
1017import {
1118 CODE_ZIP_SIZE_LIMIT ,
1219 getFileSource ,
1320 readCodeSize ,
1421 replaceReference ,
1522 resolveCode ,
1623} from '../common' ;
24+ import { isEmpty } from 'lodash' ;
1725
1826export class IacStack extends ros . Stack {
1927 private readonly service : string ;
@@ -47,15 +55,15 @@ export class IacStack extends ros.Stack {
4755 new ros . RosInfo ( this , ros . RosInfo . description , `${ this . service } stack` ) ;
4856
4957 const fileSources = iac . functions
50- . filter ( ( { code } ) => readCodeSize ( code ) > CODE_ZIP_SIZE_LIMIT )
58+ ? .filter ( ( { code } ) => readCodeSize ( code ) > CODE_ZIP_SIZE_LIMIT )
5159 . map ( ( { code, name } ) => {
5260 const fcName = replaceReference ( name , context ) ;
5361
5462 return { fcName, ...getFileSource ( fcName , code ) } ;
5563 } ) ;
5664
5765 let destinationBucket : oss . Bucket ;
58- if ( fileSources . length > 0 ) {
66+ if ( ! isEmpty ( fileSources ) ) {
5967 // creat oss to store code
6068 destinationBucket = new oss . Bucket (
6169 this ,
@@ -70,7 +78,7 @@ export class IacStack extends ros.Stack {
7078 this ,
7179 `${ this . service } _artifacts_code_deployment` ,
7280 {
73- sources : fileSources . map ( ( { source } ) => source ) ,
81+ sources : fileSources ! . map ( ( { source } ) => source ) ,
7482 destinationBucket,
7583 timeout : 300 ,
7684 logMonitoring : false , // 是否开启日志监控,设为false则不开启
@@ -79,14 +87,14 @@ export class IacStack extends ros.Stack {
7987 ) ;
8088 }
8189
82- iac . functions . forEach ( ( fnc ) => {
90+ iac . functions ? .forEach ( ( fnc ) => {
8391 let code : RosFunction . CodeProperty = {
8492 zipFile : resolveCode ( fnc . code ) ,
8593 } ;
8694 if ( readCodeSize ( fnc . code ) > CODE_ZIP_SIZE_LIMIT ) {
8795 code = {
8896 ossBucketName : destinationBucket . attrName ,
89- ossObjectName : fileSources . find ( ( { fcName } ) => fcName === fnc . name ) ?. objectKey ,
97+ ossObjectName : fileSources ? .find ( ( { fcName } ) => fcName === fnc . name ) ?. objectKey ,
9098 } ;
9199 }
92100 new fc . RosFunction (
@@ -204,5 +212,30 @@ export class IacStack extends ros.Stack {
204212 } ) ;
205213 } ) ;
206214 }
215+ iac . databases ?. forEach ( ( db ) => {
216+ if ( [ DatabaseEnum . ELASTICSEARCH_SERVERLESS ] . includes ( db . type ) ) {
217+ new esServerless . App (
218+ this ,
219+ replaceReference ( db . key , context ) ,
220+ {
221+ appName : replaceReference ( db . name , context ) ,
222+ appVersion : db . version ,
223+ authentication : {
224+ basicAuth : [
225+ {
226+ password : replaceReference ( db . security . basicAuth . password , context ) ,
227+ } ,
228+ ] ,
229+ } ,
230+ quotaInfo : {
231+ cu : db . cu ,
232+ storage : db . storageSize ,
233+ appType : db . engineMode === DatabaseEngineMode . TIMESERIES ? 'TRIAL' : 'STANDARD' ,
234+ } ,
235+ } ,
236+ true ,
237+ ) ;
238+ }
239+ } ) ;
207240 }
208241}
0 commit comments