Class MockIntegration
java.lang.Object
software.amazon.jsii.JsiiObject
software.amazon.awscdk.services.apigateway.Integration
software.amazon.awscdk.services.apigateway.MockIntegration
- All Implemented Interfaces:
software.amazon.jsii.JsiiSerializable
@Generated(value="jsii-pacmak/1.84.0 (build 5404dcf)",
date="2023-06-19T16:30:45.015Z")
@Stability(Stable)
public class MockIntegration
extends Integration
This type of integration lets API Gateway return a response without sending the request further to the backend.
This is useful for API testing because it can be used to test the integration set up without incurring charges for using the backend and to enable collaborative development of an API. In collaborative development, a team can isolate their development effort by setting up simulations of API components owned by other teams by using the MOCK integrations. It is also used to return CORS-related headers to ensure that the API method permits CORS access. In fact, the API Gateway console integrates the OPTIONS method to support CORS with a mock integration. Gateway responses are other examples of mock integrations.
Example:
import path.*; import software.amazon.awscdk.services.lambda.*; import software.amazon.awscdk.core.App; import software.amazon.awscdk.core.Stack; import software.amazon.awscdk.services.apigateway.MockIntegration; import software.amazon.awscdk.services.apigateway.PassthroughBehavior; import software.amazon.awscdk.services.apigateway.RestApi; import software.amazon.awscdk.services.apigateway.RequestAuthorizer; import software.amazon.awscdk.services.apigateway.IdentitySource; // Against the RestApi endpoint from the stack output, run // `curl -s -o /dev/null -w "%{http_code}" <url>` should return 401 // `curl -s -o /dev/null -w "%{http_code}" -H 'Authorization: deny' <url>?allow=yes` should return 403 // `curl -s -o /dev/null -w "%{http_code}" -H 'Authorization: allow' <url>?allow=yes` should return 200 App app = new App(); Stack stack = new Stack(app, "RequestAuthorizerInteg"); Function authorizerFn = Function.Builder.create(stack, "MyAuthorizerFunction") .runtime(Runtime.NODEJS_14_X) .handler("index.handler") .code(AssetCode.fromAsset(join(__dirname, "integ.request-authorizer.handler"))) .build(); RestApi restapi = new RestApi(stack, "MyRestApi"); RequestAuthorizer authorizer = RequestAuthorizer.Builder.create(stack, "MyAuthorizer") .handler(authorizerFn) .identitySources(List.of(IdentitySource.header("Authorization"), IdentitySource.queryString("allow"))) .build(); restapi.root.addMethod("ANY", MockIntegration.Builder.create() .integrationResponses(List.of(IntegrationResponse.builder().statusCode("200").build())) .passthroughBehavior(PassthroughBehavior.NEVER) .requestTemplates(Map.of( "application/json", "{ \"statusCode\": 200 }")) .build(), MethodOptions.builder() .methodResponses(List.of(MethodResponse.builder().statusCode("200").build())) .authorizer(authorizer) .build());
-
Nested Class Summary
Nested classes/interfaces inherited from class software.amazon.jsii.JsiiObject
software.amazon.jsii.JsiiObject.InitializationMode
-
Constructor Summary
ModifierConstructorDescriptionMockIntegration
(IntegrationOptions options) protected
MockIntegration
(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) protected
MockIntegration
(software.amazon.jsii.JsiiObjectRef objRef) -
Method Summary
Methods inherited from class software.amazon.awscdk.services.apigateway.Integration
bind
Methods inherited from class software.amazon.jsii.JsiiObject
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSet
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface software.amazon.jsii.JsiiSerializable
$jsii$toJson
-
Constructor Details
-
MockIntegration
protected MockIntegration(software.amazon.jsii.JsiiObjectRef objRef) -
MockIntegration
protected MockIntegration(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) -
MockIntegration
- Parameters:
options
-
-
MockIntegration
@Stability(Stable) public MockIntegration()
-