@@ -11,6 +11,7 @@ import { isEmpty } from 'lodash';
1111import * as ossDeployment from '@alicloud/ros-cdk-ossdeployment' ;
1212import * as ros from '@alicloud/ros-cdk-core' ;
1313import * as sls from '@alicloud/ros-cdk-sls' ;
14+ import { RosFunction } from '@alicloud/ros-cdk-fc3/lib/fc3.generated' ;
1415
1516export const resolveFunctions = (
1617 scope : ros . Construct ,
@@ -22,34 +23,44 @@ export const resolveFunctions = (
2223 if ( isEmpty ( functions ) ) {
2324 return undefined ;
2425 }
25- const slsService = new sls . Project (
26- scope ,
27- `${ service } _sls` ,
28- { name : `${ service } -sls` , tags : replaceReference ( tags , context ) } ,
29- true ,
30- ) ;
26+ let logConfig : RosFunction . LogConfigProperty | undefined = undefined ;
3127
32- const slsLogstore = new sls . Logstore (
33- scope ,
34- `${ service } _sls_logstore` ,
35- {
36- logstoreName : `${ service } -sls-logstore` ,
37- projectName : slsService . attrName ,
38- ttl : 7 ,
39- } ,
40- true ,
41- ) ;
28+ const enableLog = functions ?. some ( ( { log } ) => log ) ;
29+ if ( enableLog ) {
30+ const slsService = new sls . Project (
31+ scope ,
32+ `${ service } _sls` ,
33+ { name : `${ service } -sls` , tags : replaceReference ( tags , context ) } ,
34+ true ,
35+ ) ;
4236
43- new sls . Index (
44- scope ,
45- `${ service } _sls_index` ,
46- {
47- projectName : slsService . attrName ,
48- logstoreName : slsLogstore . attrLogstoreName ,
49- fullTextIndex : { enable : true } ,
50- } ,
51- true ,
52- ) ;
37+ const slsLogstore = new sls . Logstore (
38+ scope ,
39+ `${ service } _sls_logstore` ,
40+ {
41+ logstoreName : `${ service } -sls-logstore` ,
42+ projectName : slsService . attrName ,
43+ ttl : 7 ,
44+ } ,
45+ true ,
46+ ) ;
47+
48+ new sls . Index (
49+ scope ,
50+ `${ service } _sls_index` ,
51+ {
52+ projectName : slsService . attrName ,
53+ logstoreName : slsLogstore . attrLogstoreName ,
54+ fullTextIndex : { enable : true } ,
55+ } ,
56+ true ,
57+ ) ;
58+ logConfig = {
59+ project : slsLogstore . attrProjectName ,
60+ logstore : slsLogstore . attrLogstoreName ,
61+ enableRequestMetrics : true ,
62+ } ;
63+ }
5364
5465 const fileSources = functions
5566 ?. filter ( ( { code } ) => readCodeSize ( code ) > CODE_ZIP_SIZE_LIMIT )
@@ -102,17 +113,15 @@ export const resolveFunctions = (
102113 timeout : replaceReference ( fnc . timeout , context ) ,
103114 environmentVariables : replaceReference ( fnc . environment , context ) ,
104115 code,
105- logConfig : {
106- project : slsLogstore . attrProjectName ,
107- logstore : slsLogstore . attrLogstoreName ,
108- enableRequestMetrics : true ,
109- } ,
116+ logConfig,
110117 } ,
111118 true ,
112119 ) ;
113- fcn . addRosDependency ( `${ service } _sls` ) ;
114- fcn . addRosDependency ( `${ service } _sls_logstore` ) ;
115- fcn . addRosDependency ( `${ service } _sls_index` ) ;
120+ if ( enableLog ) {
121+ fcn . addRosDependency ( `${ service } _sls` ) ;
122+ fcn . addRosDependency ( `${ service } _sls_logstore` ) ;
123+ fcn . addRosDependency ( `${ service } _sls_index` ) ;
124+ }
116125
117126 if ( storeInBucket ) {
118127 fcn . addRosDependency ( `${ service } _artifacts_code_deployment` ) ;
0 commit comments