Table of Contents

Enum PassthroughBehavior

Namespace
Amazon.CDK.AWS.APIGateway
Assembly
Amazon.CDK.AWS.APIGateway.dll
public enum PassthroughBehavior

Fields

NEVER = 1

Rejects unmapped content types with an HTTP 415 'Unsupported Media Type' response.

WHEN_NO_MATCH = 0

Passes the request body for unmapped content types through to the integration back end without transformation.

WHEN_NO_TEMPLATES = 2

Allows pass-through when the integration has NO content types mapped to templates.

Examples

using Path;
            using Amazon.CDK.AWS.Lambda;
            using Amazon.CDK;
            using Amazon.CDK.AWS.APIGateway;

            // 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

            var app = new App();
            var stack = new Stack(app, "RequestAuthorizerInteg");

            var authorizerFn = new Function(stack, "MyAuthorizerFunction", new FunctionProps {
                Runtime = Runtime.NODEJS_14_X,
                Handler = "index.handler",
                Code = AssetCode.FromAsset(Join(__dirname, "integ.request-authorizer.handler"))
            });

            var restapi = new RestApi(stack, "MyRestApi");

            var authorizer = new RequestAuthorizer(stack, "MyAuthorizer", new RequestAuthorizerProps {
                Handler = authorizerFn,
                IdentitySources = new [] { IdentitySource.Header("Authorization"), IdentitySource.QueryString("allow") }
            });

            restapi.Root.AddMethod("ANY", new MockIntegration(new IntegrationOptions {
                IntegrationResponses = new [] { new IntegrationResponse { StatusCode = "200" } },
                PassthroughBehavior = PassthroughBehavior.NEVER,
                RequestTemplates = new Dictionary<string, string> {
                    { "application/json", "{ \"statusCode\": 200 }" }
                }
            }), new MethodOptions {
                MethodResponses = new [] { new MethodResponse { StatusCode = "200" } },
                Authorizer = authorizer
            });

Remarks

ExampleMetadata: lit=test/authorizers/integ.request-authorizer.lit.ts infused