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.94.0 (build b380f01)", date="2024-02-23T02:06:27.539Z") @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.App;
 import software.amazon.awscdk.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_LATEST)
         .handler("index.handler")
         .code(AssetCode.fromAsset(join(__dirname, "integ.request-authorizer.handler")))
         .build();
 RestApi restapi = RestApi.Builder.create(stack, "MyRestApi").cloudWatchRole(true).build();
 RequestAuthorizer authorizer = RequestAuthorizer.Builder.create(stack, "MyAuthorizer")
         .handler(authorizerFn)
         .identitySources(List.of(IdentitySource.header("Authorization"), IdentitySource.queryString("allow")))
         .build();
 RequestAuthorizer secondAuthorizer = RequestAuthorizer.Builder.create(stack, "MySecondAuthorizer")
         .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());
 restapi.root.resourceForPath("auth").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(secondAuthorizer)
         .build());
 
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    A fluent builder for MockIntegration.

    Nested classes/interfaces inherited from class software.amazon.jsii.JsiiObject

    software.amazon.jsii.JsiiObject.InitializationMode
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
     
     
     
     
    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

      @Stability(Stable) public MockIntegration(@Nullable IntegrationOptions options)
      Parameters:
      options -
    • MockIntegration

      @Stability(Stable) public MockIntegration()