@@ -20,6 +20,7 @@ import { SenMLMessages } from '../resources/SenMLMessage.js'
2020import { 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'
2324
2425/**
2526 * Provides resources for the backend serving data to hello.nrfcloud.com/map
@@ -76,22 +77,29 @@ export class BackendStack extends Stack {
7677 lambdaSources,
7778 } )
7879
80+ const api = new API ( this )
81+
7982 const shareAPI = new ShareAPI ( this , {
8083 baseLayer,
8184 lambdaSources,
8285 publicDevices,
8386 } )
87+ api . addRoute ( 'POST /share' , shareAPI . shareFn )
88+ api . addRoute ( 'POST /share/confirm' , shareAPI . confirmOwnershipFn )
89+ api . addRoute ( 'GET /device/{id}' , shareAPI . sharingStatusFn )
8490
8591 const devicesAPI = new DevicesAPI ( this , {
8692 baseLayer,
8793 lambdaSources,
8894 publicDevices,
8995 } )
96+ api . addRoute ( 'GET /devices' , devicesAPI . devicesFn )
9097
9198 const lwm2mObjectHistory = new LwM2MObjectsHistory ( this , {
9299 baseLayer,
93100 lambdaSources,
94101 } )
102+ api . addRoute ( 'GET /history' , lwm2mObjectHistory . historyFn )
95103
96104 const customDevicesAPI = new CustomDevicesAPI ( this , {
97105 baseLayer,
@@ -110,41 +118,18 @@ export class BackendStack extends Stack {
110118 publicDevices,
111119 } )
112120
121+ api . addRoute ( 'PUT /credentials' , customDevicesAPI . createCredentials )
122+
113123 const cd = new ContinuousDeployment ( this , {
114124 repository,
115125 gitHubOICDProviderArn,
116126 } )
117127
118128 // Outputs
119- new CfnOutput ( this , 'shareAPIURL' , {
120- exportName : `${ this . stackName } :shareAPI` ,
121- description : 'API endpoint for sharing devices' ,
122- value : shareAPI . shareURL . url ,
123- } )
124- new CfnOutput ( this , 'confirmOwnershipAPIURL' , {
125- exportName : `${ this . stackName } :confirmOwnershipAPI` ,
126- description : 'API endpoint for confirming ownership' ,
127- value : shareAPI . confirmOwnershipURL . url ,
128- } )
129- new CfnOutput ( this , 'sharingStatusAPIURL' , {
130- exportName : `${ this . stackName } :sharingStatusAPI` ,
131- description : 'API endpoint for checking the sharing status of a device' ,
132- value : shareAPI . sharingStatusURL . url ,
133- } )
134- new CfnOutput ( this , 'devicesAPIURL' , {
135- exportName : `${ this . stackName } :devicesAPI` ,
136- description : 'API endpoint for retrieving public device information' ,
137- value : devicesAPI . devicesURL . url ,
138- } )
139- new CfnOutput ( this , 'queryHistoryAPIURL' , {
140- exportName : `${ this . stackName } :queryHistoryAPI` ,
141- description : 'API endpoint for querying device history' ,
142- value : lwm2mObjectHistory . historyURL . url ,
143- } )
144- new CfnOutput ( this , 'createCredentialsAPIURL' , {
145- exportName : `${ this . stackName } :createCredentialsAPIURL` ,
146- description : 'API endpoint for creating credentials for custom devices' ,
147- value : customDevicesAPI . createCredentialsURL . url ,
129+ new CfnOutput ( this , 'APIURL' , {
130+ exportName : `${ this . stackName } :APIURL` ,
131+ description : 'API endpoint' ,
132+ value : api . URL ,
148133 } )
149134 new CfnOutput ( this , 'publicDevicesTableName' , {
150135 exportName : `${ this . stackName } :publicDevicesTableName` ,
@@ -160,12 +145,7 @@ export class BackendStack extends Stack {
160145}
161146
162147export type StackOutputs = {
163- shareAPIURL : string // e.g. 'https://iiet67bnlmbtuhiblik4wcy4ni0oujot.lambda-url.eu-west-1.on.aws/'
164- confirmOwnershipAPIURL : string // e.g. 'https://aqt7qs3nzyo4uh2v74quysvmxe0ubeth.lambda-url.eu-west-1.on.aws/'
165- sharingStatusAPIURL : string // e.g. 'https://aqt7qs3nzyo4uh2v74quysvmxe0ubeth.lambda-url.eu-west-1.on.aws/'
166- devicesAPIURL : string // e.g. 'https://a2udxgawcxd5tbmmfagi726jsm0obxov.lambda-url.eu-west-1.on.aws/'
167- queryHistoryAPIURL : string
168- createCredentialsAPIURL : string
148+ APIURL : string // e.g. 'https://iiet67bnlmbtuhiblik4wcy4ni0oujot.execute-api.eu-west-1.amazonaws.com/2024-04-12/'
169149 publicDevicesTableName : string
170150 /**
171151 * Role ARN to use in the deploy GitHub Actions Workflow
0 commit comments