@@ -5,22 +5,25 @@ import {
55 Stack ,
66 aws_ecr as ECR ,
77} from 'aws-cdk-lib'
8- import type { BackendLambdas } from '.. /BackendLambdas.js'
8+ import type { BackendLambdas } from './BackendLambdas.js'
99import type { PackedLayer } from '@bifravst/aws-cdk-lambda-helpers/layer'
1010import { LambdaSource } from '@bifravst/aws-cdk-lambda-helpers/cdk'
11- import { ConnectionInformationGeoLocation } from '.. /resources/ConnectionInformationGeoLocation.js'
12- import { LwM2MShadow } from '.. /resources/LwM2MShadow.js'
13- import { PublicDevices } from '.. /resources/PublicDevices.js'
14- import { ShareAPI } from '.. /resources/ShareAPI.js'
11+ import { ConnectionInformationGeoLocation } from './resources/ConnectionInformationGeoLocation.js'
12+ import { LwM2MShadow } from './resources/LwM2MShadow.js'
13+ import { PublicDevices } from './resources/PublicDevices.js'
14+ import { ShareAPI } from './resources/ShareAPI.js'
1515import { STACK_NAME } from './stackConfig.js'
16- import { DevicesAPI } from '.. /resources/DevicesAPI.js'
17- import { LwM2MObjectsHistory } from '.. /resources/LwM2MObjectsHistory.js'
18- import { CustomDevicesAPI } from '.. /resources/CustomDevicesAPI.js'
19- import { SenMLMessages } from '.. /resources/SenMLMessage.js'
20- import { ContainerRepositoryId } from '../../ aws/ecr.js'
16+ import { DevicesAPI } from './resources/DevicesAPI.js'
17+ import { LwM2MObjectsHistory } from './resources/LwM2MObjectsHistory.js'
18+ import { CustomDevicesAPI } from './resources/CustomDevicesAPI.js'
19+ import { SenMLMessages } from './resources/SenMLMessage.js'
20+ import { ContainerRepositoryId } from '../aws/ecr.js'
2121import { repositoryName } from '@bifravst/aws-cdk-ecr-helpers/repository'
2222import { ContinuousDeployment } from '@bifravst/ci'
23- import { API } from '../resources/api/API.js'
23+ import { API } from './resources/api/API.js'
24+ import type { DomainCert } from '../aws/acm.js'
25+ import { ApiHealthCheck } from './resources/api/HealthCheck.js'
26+ import { CustomDomain } from './resources/api/CustomDomain.js'
2427
2528/**
2629 * Provides resources for the backend serving data to hello.nrfcloud.com/map
@@ -29,12 +32,16 @@ export class BackendStack extends Stack {
2932 constructor (
3033 parent : App ,
3134 {
35+ domain,
36+ apiDomain,
3237 layer,
3338 lambdaSources,
3439 openSSLLambdaContainerTag,
3540 repository,
3641 gitHubOICDProviderArn,
3742 } : {
43+ domain : string
44+ apiDomain ?: DomainCert
3845 layer : PackedLayer
3946 lambdaSources : BackendLambdas
4047 openSSLLambdaContainerTag : string
@@ -59,8 +66,41 @@ export class BackendStack extends Stack {
5966 } )
6067
6168 const publicDevices = new PublicDevices ( this )
69+ new CfnOutput ( this , 'publicDevicesTableName' , {
70+ exportName : `${ this . stackName } :publicDevicesTableName` ,
71+ description : 'name of the public devices table' ,
72+ value : publicDevices . publicDevicesTable . tableName ,
73+ } )
6274
6375 const api = new API ( this )
76+ api . addRoute (
77+ 'GET /health' ,
78+ new ApiHealthCheck ( this , { baseLayer, lambdaSources } ) . fn ,
79+ )
80+
81+ if ( apiDomain === undefined ) {
82+ new CfnOutput ( this , 'APIURL' , {
83+ exportName : `${ this . stackName } :APIURL` ,
84+ description : 'API endpoint' ,
85+ value : api . URL ,
86+ } )
87+ } else {
88+ const domain = new CustomDomain ( this , {
89+ api,
90+ apiDomain,
91+ } )
92+ new CfnOutput ( this , 'gatewayDomainName' , {
93+ exportName : `${ this . stackName } :gatewayDomainName` ,
94+ description :
95+ 'The domain name associated with the regional endpoint for the custom domain name. Use this as the target for the CNAME record for your custom domain name.' ,
96+ value : domain . gatewayDomainName . toString ( ) ,
97+ } )
98+ new CfnOutput ( this , 'APIURL' , {
99+ exportName : `${ this . stackName } :APIURL` ,
100+ description : 'API endpoint' ,
101+ value : domain . URL ,
102+ } )
103+ }
64104
65105 new LwM2MShadow ( this , {
66106 baseLayer,
@@ -84,6 +124,7 @@ export class BackendStack extends Stack {
84124 } )
85125
86126 const shareAPI = new ShareAPI ( this , {
127+ domain,
87128 baseLayer,
88129 lambdaSources,
89130 publicDevices,
@@ -124,22 +165,12 @@ export class BackendStack extends Stack {
124165
125166 api . addRoute ( 'POST /credentials' , customDevicesAPI . createCredentials )
126167
168+ // CD
169+
127170 const cd = new ContinuousDeployment ( this , {
128171 repository,
129172 gitHubOICDProviderArn,
130173 } )
131-
132- // Outputs
133- new CfnOutput ( this , 'APIURL' , {
134- exportName : `${ this . stackName } :APIURL` ,
135- description : 'API endpoint' ,
136- value : api . URL ,
137- } )
138- new CfnOutput ( this , 'publicDevicesTableName' , {
139- exportName : `${ this . stackName } :publicDevicesTableName` ,
140- description : 'name of the public devices table' ,
141- value : publicDevices . publicDevicesTable . tableName ,
142- } )
143174 new CfnOutput ( this , 'cdRoleArn' , {
144175 exportName : `${ this . stackName } :cdRoleArn` ,
145176 description : 'Role ARN to use in the deploy GitHub Actions Workflow' ,
@@ -149,7 +180,20 @@ export class BackendStack extends Stack {
149180}
150181
151182export type StackOutputs = {
152- APIURL : string // e.g. 'https://iiet67bnlmbtuhiblik4wcy4ni0oujot.execute-api.eu-west-1.amazonaws.com/2024-04-12/'
183+ /**
184+ * The URL of the deployed API
185+ * @example https://api.nordicsemi.world/2024-04-12/
186+ * @example https://9gsm5gind2.execute-api.eu-west-1.amazonaws.com/2024-04-12
187+ */
188+ APIURL : string
189+ /**
190+ * The domain name associated with the regional endpoint for the custom domain name. Use this as the target for the CNAME record for your custom domain name.
191+ *
192+ * Only present if custom domain is used
193+ *
194+ * @example d-nygno3o155.execute-api.eu-west-1.amazonaws.com
195+ */
196+ gatewayDomainName ?: string
153197 publicDevicesTableName : string
154198 /**
155199 * Role ARN to use in the deploy GitHub Actions Workflow
0 commit comments