@@ -169,6 +169,27 @@ export interface ApiGatewayToSqsProps {
169169 * @default - None
170170 */
171171 readonly encryptionKeyProps ?: kms . KeyProps ;
172+ /**
173+ * Optional, custom API Gateway path for the GET method.
174+ * This property can only be specified if the `allowReadOperation` property is not set to false.
175+ *
176+ * @default - ""
177+ */
178+ readonly readRequestPath ?: string ;
179+ /**
180+ * Optional, custom API Gateway path for the POST method.
181+ * This property can only be specified if the `allowCreateOperation` property is not set to false.
182+ *
183+ * @default - ""
184+ */
185+ readonly createRequestPath ?: string ;
186+ /**
187+ * Optional, custom API Gateway path for the DELETE method.
188+ * This property can only be specif||ied if the `allowDeleteOperation` property is not set to false.
189+ *
190+ * @default - "message"
191+ */
192+ readonly deleteRequestPath ?: string ;
172193}
173194
174195/**
@@ -200,15 +221,15 @@ export class ApiGatewayToSqs extends Construct {
200221
201222 if ( this . CheckCreateRequestProps ( props ) ) {
202223 throw new Error ( `The 'allowCreateOperation' property must be set to true when setting any of the following: ` +
203- `'createRequestTemplate', 'additionalCreateRequestTemplates', 'createIntegrationResponses'` ) ;
224+ `'createRequestTemplate', 'additionalCreateRequestTemplates', 'createIntegrationResponses', 'createRequestPath '` ) ;
204225 }
205226 if ( this . CheckReadRequestProps ( props ) ) {
206227 throw new Error ( `The 'allowReadOperation' property must be set to true or undefined when setting any of the following: ` +
207- `'readRequestTemplate', 'additionalReadRequestTemplates', 'readIntegrationResponses'` ) ;
228+ `'readRequestTemplate', 'additionalReadRequestTemplates', 'readIntegrationResponses', 'readRequestPath '` ) ;
208229 }
209230 if ( this . CheckDeleteRequestProps ( props ) ) {
210231 throw new Error ( `The 'allowDeleteOperation' property must be set to true when setting any of the following: ` +
211- `'deleteRequestTemplate', 'additionalDeleteRequestTemplates', 'deleteIntegrationResponses'` ) ;
232+ `'deleteRequestTemplate', 'additionalDeleteRequestTemplates', 'deleteIntegrationResponses', 'deleteRequestPath '` ) ;
212233 }
213234
214235 // Setup the dead letter queue, if applicable
@@ -244,13 +265,14 @@ export class ApiGatewayToSqs extends Construct {
244265 // Create
245266 const createRequestTemplate = props . createRequestTemplate ?? this . defaultCreateRequestTemplate ;
246267 if ( props . allowCreateOperation && props . allowCreateOperation === true ) {
268+ const apiCreateRequestResource = props . createRequestPath ? this . apiGateway . root . addResource ( props . createRequestPath ) : this . apiGateway . root ;
247269 this . addActionToPolicy ( "sqs:SendMessage" ) ;
248270 defaults . addProxyMethodToApiResource ( {
249271 service : "sqs" ,
250272 path : `${ cdk . Aws . ACCOUNT_ID } /${ this . sqsQueue . queueName } ` ,
251273 apiGatewayRole : this . apiGatewayRole ,
252274 apiMethod : "POST" ,
253- apiResource : this . apiGateway . root ,
275+ apiResource : apiCreateRequestResource ,
254276 requestTemplate : createRequestTemplate ,
255277 additionalRequestTemplates : props . additionalCreateRequestTemplates ,
256278 contentType : "'application/x-www-form-urlencoded'" ,
@@ -261,13 +283,14 @@ export class ApiGatewayToSqs extends Construct {
261283 // Read
262284 const readRequestTemplate = props . readRequestTemplate ?? this . defaultReadRequestTemplate ;
263285 if ( props . allowReadOperation === undefined || props . allowReadOperation === true ) {
286+ const apiReadRequestResource = props . readRequestPath ? this . apiGateway . root . addResource ( props . readRequestPath ) : this . apiGateway . root ;
264287 this . addActionToPolicy ( "sqs:ReceiveMessage" ) ;
265288 defaults . addProxyMethodToApiResource ( {
266289 service : "sqs" ,
267290 path : `${ cdk . Aws . ACCOUNT_ID } /${ this . sqsQueue . queueName } ` ,
268291 apiGatewayRole : this . apiGatewayRole ,
269292 apiMethod : "GET" ,
270- apiResource : this . apiGateway . root ,
293+ apiResource : apiReadRequestResource ,
271294 requestTemplate : readRequestTemplate ,
272295 additionalRequestTemplates : props . additionalReadRequestTemplates ,
273296 contentType : "'application/x-www-form-urlencoded'" ,
@@ -278,14 +301,14 @@ export class ApiGatewayToSqs extends Construct {
278301 // Delete
279302 const deleteRequestTemplate = props . deleteRequestTemplate ?? this . defaultDeleteRequestTemplate ;
280303 if ( props . allowDeleteOperation && props . allowDeleteOperation === true ) {
281- const apiGatewayResource = this . apiGateway . root . addResource ( 'message' ) ;
304+ const apiDeleteRequestResource = this . apiGateway . root . addResource ( props . deleteRequestPath ?? 'message' ) ;
282305 this . addActionToPolicy ( "sqs:DeleteMessage" ) ;
283306 defaults . addProxyMethodToApiResource ( {
284307 service : "sqs" ,
285308 path : `${ cdk . Aws . ACCOUNT_ID } /${ this . sqsQueue . queueName } ` ,
286309 apiGatewayRole : this . apiGatewayRole ,
287310 apiMethod : "DELETE" ,
288- apiResource : apiGatewayResource ,
311+ apiResource : apiDeleteRequestResource ,
289312 requestTemplate : deleteRequestTemplate ,
290313 additionalRequestTemplates : props . additionalDeleteRequestTemplates ,
291314 contentType : "'application/x-www-form-urlencoded'" ,
@@ -294,22 +317,22 @@ export class ApiGatewayToSqs extends Construct {
294317 }
295318 }
296319 private CheckReadRequestProps ( props : ApiGatewayToSqsProps ) : boolean {
297- if ( ( props . readRequestTemplate || props . additionalReadRequestTemplates || props . readIntegrationResponses )
320+ if ( ( props . readRequestTemplate || props . additionalReadRequestTemplates || props . readIntegrationResponses || props . readRequestPath )
298321 && props . allowReadOperation === false ) {
299322 return true ;
300323 }
301324 return false ;
302325 }
303326 private CheckDeleteRequestProps ( props : ApiGatewayToSqsProps ) : boolean {
304- if ( ( props . deleteRequestTemplate || props . additionalDeleteRequestTemplates || props . deleteIntegrationResponses )
327+ if ( ( props . deleteRequestTemplate || props . additionalDeleteRequestTemplates || props . deleteIntegrationResponses || props . deleteRequestPath )
305328 && props . allowDeleteOperation !== true ) {
306329 return true ;
307330 }
308331 return false ;
309332 }
310333
311334 private CheckCreateRequestProps ( props : ApiGatewayToSqsProps ) : boolean {
312- if ( ( props . createRequestTemplate || props . additionalCreateRequestTemplates || props . createIntegrationResponses )
335+ if ( ( props . createRequestTemplate || props . additionalCreateRequestTemplates || props . createIntegrationResponses || props . createRequestPath )
313336 && props . allowCreateOperation !== true ) {
314337 return true ;
315338 }
0 commit comments