- Navigation GuideYou are on a Command (operation) page with structural examples. Use the navigation breadcrumb if you would like to return to the Client landing page.
TestInvokeMethodCommand
Simulate the invocation of a Method in your RestApi with headers, parameters, and an incoming request body.
Example Syntax
Use a bare-bones client and the command you need to make an API call.
import { APIGatewayClient, TestInvokeMethodCommand } from "@aws-sdk/client-api-gateway"; // ES Modules import
// const { APIGatewayClient, TestInvokeMethodCommand } = require("@aws-sdk/client-api-gateway"); // CommonJS import
const client = new APIGatewayClient(config);
const input = { // TestInvokeMethodRequest
restApiId: "STRING_VALUE", // required
resourceId: "STRING_VALUE", // required
httpMethod: "STRING_VALUE", // required
pathWithQueryString: "STRING_VALUE",
body: "STRING_VALUE",
headers: { // MapOfStringToString
"<keys>": "STRING_VALUE",
},
multiValueHeaders: { // MapOfStringToList
"<keys>": [ // ListOfString
"STRING_VALUE",
],
},
clientCertificateId: "STRING_VALUE",
stageVariables: {
"<keys>": "STRING_VALUE",
},
};
const command = new TestInvokeMethodCommand(input);
const response = await client.send(command);
// { // TestInvokeMethodResponse
// status: Number("int"),
// body: "STRING_VALUE",
// headers: { // MapOfStringToString
// "<keys>": "STRING_VALUE",
// },
// multiValueHeaders: { // MapOfStringToList
// "<keys>": [ // ListOfString
// "STRING_VALUE",
// ],
// },
// log: "STRING_VALUE",
// latency: Number("long"),
// };
TestInvokeMethodCommand Input
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
httpMethod Required | string | undefined | Specifies a test invoke method request's HTTP method. |
resourceId Required | string | undefined | Specifies a test invoke method request's resource ID. |
restApiId Required | string | undefined | The string identifier of the associated RestApi. |
body | string | undefined | The simulated request body of an incoming invocation request. |
clientCertificateId | string | undefined | A ClientCertificate identifier to use in the test invocation. API Gateway will use the certificate when making the HTTPS request to the defined back-end endpoint. |
headers | Record<string, string> | undefined | A key-value map of headers to simulate an incoming invocation request. |
multiValueHeaders | Record<string, string[]> | undefined | The headers as a map from string to list of values to simulate an incoming invocation request. |
pathWithQueryString | string | undefined | The URI path, including query string, of the simulated invocation request. Use this to specify path parameters and query string parameters. |
stageVariables | Record<string, string> | undefined | A key-value map of stage variables to simulate an invocation on a deployed Stage. |
TestInvokeMethodCommand Output
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
$metadata Required | ResponseMetadata | Metadata pertaining to this request. |
body | string | undefined | The body of the HTTP response. |
headers | Record<string, string> | undefined | The headers of the HTTP response. |
latency | number | undefined | The execution latency, in ms, of the test invoke request. |
log | string | undefined | The API Gateway execution log for the test invoke request. |
multiValueHeaders | Record<string, string[]> | undefined | The headers of the HTTP response as a map from string to list of values. |
status | number | undefined | The HTTP status code. |
Throws
Name | Fault | Details |
---|
Name | Fault | Details |
---|---|---|
BadRequestException | client | The submitted request is not valid, for example, the input is incomplete or incorrect. See the accompanying error message for details. |
NotFoundException | client | The requested resource is not found. Make sure that the request URI is correct. |
TooManyRequestsException | client | The request has reached its throttling limit. Retry after the specified time period. |
UnauthorizedException | client | The request is denied because the caller has insufficient permissions. |
APIGatewayServiceException | Base exception class for all service exceptions from APIGateway service. |