enum PassthroughBehavior
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.APIGateway.PassthroughBehavior |
Java | software.amazon.awscdk.services.apigateway.PassthroughBehavior |
Python | aws_cdk.aws_apigateway.PassthroughBehavior |
TypeScript (source) | @aws-cdk/aws-apigateway » PassthroughBehavior |
Example
import * as path from 'path';
import * as lambda from '@aws-cdk/aws-lambda';
import { App, Stack } from '@aws-cdk/core';
import { MockIntegration, PassthroughBehavior, RestApi } from '../../lib';
import { RequestAuthorizer } from '../../lib/authorizers';
import { IdentitySource } from '../../lib/authorizers/identity-source';
// 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
const app = new App();
const stack = new Stack(app, 'RequestAuthorizerInteg');
const authorizerFn = new lambda.Function(stack, 'MyAuthorizerFunction', {
runtime: lambda.Runtime.NODEJS_14_X,
handler: 'index.handler',
code: lambda.AssetCode.fromAsset(path.join(__dirname, 'integ.request-authorizer.handler')),
});
const restapi = new RestApi(stack, 'MyRestApi');
const authorizer = new RequestAuthorizer(stack, 'MyAuthorizer', {
handler: authorizerFn,
identitySources: [IdentitySource.header('Authorization'), IdentitySource.queryString('allow')],
});
restapi.root.addMethod('ANY', new MockIntegration({
integrationResponses: [
{ statusCode: '200' },
],
passthroughBehavior: PassthroughBehavior.NEVER,
requestTemplates: {
'application/json': '{ "statusCode": 200 }',
},
}), {
methodResponses: [
{ statusCode: '200' },
],
authorizer,
});
Members
Name | Description |
---|---|
WHEN_NO_MATCH | Passes the request body for unmapped content types through to the integration back end without transformation. |
NEVER | Rejects unmapped content types with an HTTP 415 'Unsupported Media Type' response. |
WHEN_NO_TEMPLATES | Allows pass-through when the integration has NO content types mapped to templates. |
WHEN_NO_MATCH
Passes the request body for unmapped content types through to the integration back end without transformation.
NEVER
Rejects unmapped content types with an HTTP 415 'Unsupported Media Type' response.
WHEN_NO_TEMPLATES
Allows pass-through when the integration has NO content types mapped to templates.
However if there is at least one content type defined, unmapped content types will be rejected with the same 415 response.