Enable mock integration using the API Gateway console
You must have a method available in API Gateway. Follow the instructions in Tutorial: Create a REST API with an HTTP non-proxy integration.
-
Choose an API resource and choose Create method.
To create the method, do the following:
For Method type, select a method.
For Integration type, select Mock.
Choose Create method.
On the Method request tab, for Method request settings, choose Edit.
-
Choose URL query string parameters. Choose Add query string and for Name, enter
scope
. This query parameter determines if the caller is internal or otherwise. -
Choose Save.
-
On the Method response tab, choose Create response, and then do the following:
-
For HTTP Status, enter
500
. Choose Save.
-
-
On the Integration request tab, for Integration request settings, choose Edit.
-
Choose Mapping templates, and then do the following:
Choose Add mapping template.
For Content type, enter
application/json
.For Template body, enter the following:
{ #if( $input.params('scope') == "internal" ) "statusCode": 200 #else "statusCode": 500 #end }
Choose Save.
-
On the Integration response tab, for the Default - Response choose Edit.
-
Choose Mapping templates, and then do the following:
For Content type, enter
application/json
.For Template body, enter the following:
{ "statusCode": 200, "message": "Go ahead without me" }
Choose Save.
-
Choose Create response.
To create a 500 response, do the following:
-
For HTTP status regex, enter
5\d{2}
. For Method response status, select
500
.Choose Save.
-
For 5\d{2} - Response, choose Edit.
Choose Mapping templates, and then choose Add mapping template.
For Content type, enter
application/json
.For Template body, enter the following:
{ "statusCode": 500, "message": "The invoked method is not supported on the API resource." }
Choose Save.
-
-
Choose the Test tab. You might need to choose the right arrow button to show the tab. To test your mock integration, do the following:
-
Enter
scope=internal
under Query strings. Choose Test. The test result shows:Request: /?scope=internal Status: 200 Latency: 26 ms Response Body { "statusCode": 200, "message": "Go ahead without me" } Response Headers {"Content-Type":"application/json"}
-
Enter
scope=public
underQuery strings
or leave it blank. Choose Test. The test result shows:Request: / Status: 500 Latency: 16 ms Response Body { "statusCode": 500, "message": "The invoked method is not supported on the API resource." } Response Headers {"Content-Type":"application/json"}
-
You can also return headers in a mock integration response by first adding a header to the method response and then setting up a header mapping in the integration response. In fact, this is how the API Gateway console enables CORS support by returning CORS required headers.