11import * as ros from '@alicloud/ros-cdk-core' ;
22import { Context , EventDomain , EventTypes , ServerlessIac } from '../../types' ;
33import * as ram from '@alicloud/ros-cdk-ram' ;
4- import { encodeBase64ForRosId , calcRefs , splitDomain } from '../../common' ;
4+ import { calcRefs , calcValue , formatRosId , splitDomain } from '../../common' ;
55import * as agw from '@alicloud/ros-cdk-apigateway' ;
66import { isEmpty } from 'lodash' ;
77import * as dns from '@alicloud/ros-cdk-dns' ;
@@ -22,9 +22,9 @@ export const resolveEvents = (
2222 apiGateway . forEach ( ( event ) => {
2323 const gatewayAccessRole = new ram . RosRole (
2424 scope ,
25- calcRefs ( `${ event . key } _role` , context ) ,
25+ formatRosId ( `${ event . key } _agw_role` ) ,
2626 {
27- roleName : calcRefs ( `${ service } - ${ event . name } -agw-access-role` , context ) ,
27+ roleName : calcRefs ( `${ event . name } -agw-access-role` , context ) ,
2828 description : calcRefs ( `${ service } role` , context ) ,
2929 assumeRolePolicyDocument : {
3030 version : '1' ,
@@ -60,20 +60,20 @@ export const resolveEvents = (
6060
6161 const apiGatewayGroup = new agw . RosGroup (
6262 scope ,
63- calcRefs ( `${ service } _apigroup` , context ) ,
63+ formatRosId ( `${ event . key } _agw_group` ) ,
6464 {
65- groupName : calcRefs ( `${ service } _apigroup ` , context ) ,
65+ groupName : calcRefs ( `${ service } -agw-group ` , context ) ,
6666 tags : calcRefs ( tags , context ) ,
6767 passthroughHeaders : 'host' ,
6868 } ,
6969 true ,
7070 ) ;
7171
7272 if ( event . domain ) {
73- const dnsRecordRosId = `${ event . key } _custom_domain_record_ ${ encodeBase64ForRosId ( event . domain . domain_name ) } ` ;
73+ const dnsRecordId = formatRosId ( `${ event . key } _agw_custom_domain_record` ) ;
7474 const { domainName, rr } = splitDomain ( event . domain ?. domain_name ) ;
7575
76- new dns . DomainRecord ( scope , dnsRecordRosId , {
76+ new dns . DomainRecord ( scope , dnsRecordId , {
7777 domainName,
7878 rr,
7979 type : 'CNAME' ,
@@ -82,7 +82,7 @@ export const resolveEvents = (
8282
8383 const agwCustomDomain = new agw . RosCustomDomain (
8484 scope ,
85- `${ event . key } _custom_domain_ ${ encodeBase64ForRosId ( event . domain . domain_name ) } ` ,
85+ formatRosId ( `${ event . key } _agw_custom_domain` ) ,
8686 {
8787 groupId : apiGatewayGroup . attrGroupId ,
8888 domainName : event . domain . domain_name ,
@@ -92,17 +92,16 @@ export const resolveEvents = (
9292 } ,
9393 true ,
9494 ) ;
95- agwCustomDomain . addRosDependency ( dnsRecordRosId ) ;
95+ agwCustomDomain . addRosDependency ( dnsRecordId ) ;
9696 }
9797
9898 event . triggers . forEach ( ( trigger ) => {
99- const key = encodeBase64ForRosId ( calcRefs ( `${ trigger . method } _${ trigger . path } ` , context ) ) ;
100-
99+ const key = formatRosId ( calcValue ( `${ trigger . method } _${ trigger . path } ` , context ) ) ;
101100 const api = new agw . RosApi (
102101 scope ,
103- `${ event . key } _api_ ${ key } ` ,
102+ formatRosId ( `${ event . key } _agw_api_ ${ key } ` ) ,
104103 {
105- apiName : calcRefs ( `${ event . name } _api_ ${ key } ` , context ) ,
104+ apiName : calcRefs ( `${ event . name } -agw-api- ${ key . replace ( / _ / g , '-' ) } ` , context ) ,
106105 groupId : apiGatewayGroup . attrGroupId ,
107106 visibility : 'PRIVATE' ,
108107 authType : 'ANONYMOUS' ,
@@ -130,11 +129,14 @@ export const resolveEvents = (
130129 ) ;
131130 api . addDependsOn ( apiGatewayGroup ) ;
132131
133- new agw . Deployment ( scope , `${ service } _deployment` , {
132+ new agw . Deployment ( scope , formatRosId ( `${ event . key } _agw_api_deployment_ ${ key } ` ) , {
134133 apiId : api . attrApiId ,
135134 groupId : apiGatewayGroup . attrGroupId ,
136135 stageName : 'RELEASE' ,
137- description : `${ service } Api Gateway deployment` ,
136+ description : calcRefs (
137+ `${ service } Api Gateway deployment for api: ${ trigger . method } ${ trigger . path } ` ,
138+ context ,
139+ ) ,
138140 } ) ;
139141 } ) ;
140142 } ) ;
0 commit comments