@@ -2,7 +2,9 @@ import { getMetadata, constants } from '../../../../annotations'
22const { CLASS_APIGATEWAYKEY } = constants
33import { ExecuteStep , executor } from '../../../context'
44import { setResource } from '../utils'
5- import { setStackParameter , getStackName } from './stack'
5+ import { setStackParameter , getStackName , createStack } from './stack'
6+
7+ import { projectConfig } from '../../../project/config'
68
79export const API_GATEWAY_REST_API = 'ApiGatewayRestApi'
810
@@ -20,17 +22,28 @@ export const gatewayRestApi = ExecuteStep.register('ApiGateway-RestApi', async (
2022 }
2123 }
2224
23- const resourceName = setResource ( context , API_GATEWAY_REST_API , RestApi )
25+ context . ApiGatewayStackName = projectConfig . ApiGatewayStackName || null
26+ if ( context . ApiGatewayStackName ) {
27+ await executor ( {
28+ context : { ...context , stackName : context . ApiGatewayStackName } ,
29+ name : `CloudFormation-Stack-init-${ context . ApiGatewayStackName } ` ,
30+ method : createStack
31+ } )
32+ }
33+
34+ const resourceName = setResource ( context , API_GATEWAY_REST_API , RestApi , context . ApiGatewayStackName , true )
2435
2536 await setStackParameter ( {
2637 ...context ,
27- resourceName
38+ resourceName,
39+ sourceStackName : context . ApiGatewayStackName
2840 } )
2941
3042 await setStackParameter ( {
3143 ...context ,
3244 resourceName,
33- attr : 'RootResourceId'
45+ attr : 'RootResourceId' ,
46+ sourceStackName : context . ApiGatewayStackName
3447 } )
3548
3649 context . CloudFormationTemplate . Outputs [ `ServiceEndpoint` ] = {
@@ -39,9 +52,14 @@ export const gatewayRestApi = ExecuteStep.register('ApiGateway-RestApi', async (
3952 "" ,
4053 [
4154 "https://" ,
42- {
43- "Ref" : resourceName
44- } ,
55+ context . ApiGatewayStackName ? {
56+ "Fn::GetAtt" : [
57+ context . ApiGatewayStackName ,
58+ "Outputs." + resourceName
59+ ]
60+ } : {
61+ "Ref" : resourceName
62+ } ,
4563 ".execute-api." ,
4664 context . awsRegion ,
4765 ".amazonaws.com/" ,
@@ -258,9 +276,14 @@ export const gatewayDeployment = ExecuteStep.register('ApiGateway-Deployment', a
258276 const ApiGatewayDeployment = {
259277 "Type" : "AWS::ApiGateway::Deployment" ,
260278 "Properties" : {
261- "RestApiId" : {
262- "Ref" : API_GATEWAY_REST_API
263- } ,
279+ "RestApiId" : context . ApiGatewayStackName ? {
280+ "Fn::GetAtt" : [
281+ context . ApiGatewayStackName ,
282+ "Outputs." + API_GATEWAY_REST_API
283+ ]
284+ } : {
285+ "Ref" : API_GATEWAY_REST_API
286+ } ,
264287 "StageName" : context . stage
265288 } ,
266289 "DependsOn" : [
0 commit comments