IntegrationOptions Struct
| Source | aws-apigateway/lib/integration.ts |
|---|---|
| Type last changed |
Example
import * as path from 'path';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import { Construct } from 'constructs';
import { App, Stack } from 'aws-cdk-lib';
import { MockIntegration, PassthroughBehavior, RestApi, TokenAuthorizer, Cors } from 'aws-cdk-lib/aws-apigateway';
/// !show
class MyStack extends Stack {
constructor(scope: Construct, id: string) {
super(scope, id);
const authorizerFn = new lambda.Function(this, 'MyAuthorizerFunction', {
runtime: lambda.Runtime.NODEJS_LATEST,
handler: 'index.handler',
code: lambda.AssetCode.fromAsset(path.join(__dirname, 'integ.token-authorizer.handler')),
});
const authorizer = new TokenAuthorizer(this, 'MyAuthorizer', {
handler: authorizerFn,
});
const restapi = new RestApi(this, 'MyRestApi', {
cloudWatchRole: true,
defaultMethodOptions: {
authorizer,
},
defaultCorsPreflightOptions: {
allowOrigins: Cors.ALL_ORIGINS,
},
});
restapi.root.addMethod('ANY', new MockIntegration({
integrationResponses: [
{ statusCode: '200' },
],
passthroughBehavior: PassthroughBehavior.NEVER,
requestTemplates: {
'application/json': '{ "statusCode": 200 }',
},
}), {
methodResponses: [
{ statusCode: '200' },
],
});
}
}
from aws_cdk.aws_apigateway import MethodOptions, CorsOptions, IntegrationResponse, MethodResponse
class MyStack(Stack):
def __init__(self, scope, id):
super().__init__(scope, id)
authorizer_fn = lambda_.Function(self, "MyAuthorizerFunction",
runtime=lambda_.Runtime.NODEJS_LATEST,
handler="index.handler",
code=lambda_.AssetCode.from_asset(path.join(__dirname, "integ.token-authorizer.handler"))
)
authorizer = TokenAuthorizer(self, "MyAuthorizer",
handler=authorizer_fn
)
restapi = RestApi(self, "MyRestApi",
cloud_watch_role=True,
default_method_options=MethodOptions(
authorizer=authorizer
),
default_cors_preflight_options=CorsOptions(
allow_origins=Cors.ALL_ORIGINS
)
)
restapi.root.add_method("ANY", MockIntegration(
integration_responses=[IntegrationResponse(status_code="200")
],
passthrough_behavior=PassthroughBehavior.NEVER,
request_templates={
"application/json": "{ \"statusCode\": 200 }"
}
),
method_responses=[MethodResponse(status_code="200")
]
)
public class MyStack extends Stack {
public MyStack(Construct scope, String id) {
super(scope, id);
Function authorizerFn = Function.Builder.create(this, "MyAuthorizerFunction")
.runtime(Runtime.NODEJS_LATEST)
.handler("index.handler")
.code(AssetCode.fromAsset(join(__dirname, "integ.token-authorizer.handler")))
.build();
TokenAuthorizer authorizer = TokenAuthorizer.Builder.create(this, "MyAuthorizer")
.handler(authorizerFn)
.build();
RestApi restapi = RestApi.Builder.create(this, "MyRestApi")
.cloudWatchRole(true)
.defaultMethodOptions(MethodOptions.builder()
.authorizer(authorizer)
.build())
.defaultCorsPreflightOptions(CorsOptions.builder()
.allowOrigins(Cors.ALL_ORIGINS)
.build())
.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()))
.build());
}
}
// Install: dotnet add package Amazon.CDK.Lib
class MyStack : Stack
{
public MyStack(Construct scope, string id) : base(scope, id)
{
var authorizerFn = new Function(this, "MyAuthorizerFunction", new FunctionProps {
Runtime = Runtime.NODEJS_LATEST,
Handler = "index.handler",
Code = AssetCode.FromAsset(Join(__dirname, "integ.token-authorizer.handler"))
});
var authorizer = new TokenAuthorizer(this, "MyAuthorizer", new TokenAuthorizerProps {
Handler = authorizerFn
});
var restapi = new RestApi(this, "MyRestApi", new RestApiProps {
CloudWatchRole = true,
DefaultMethodOptions = new MethodOptions {
Authorizer = authorizer
},
DefaultCorsPreflightOptions = new CorsOptions {
AllowOrigins = Cors.ALL_ORIGINS
}
});
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" } }
});
}
}
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
type myStack struct {
Stack
}
func newMyStack(scope Construct, id *string) *myStack {
this := &myStack{}
newStack_Override(this, scope, id)
authorizerFn := lambda.NewFunction(this, jsii.String("MyAuthorizerFunction"), &FunctionProps{
Runtime: lambda.Runtime_NODEJS_LATEST(),
Handler: jsii.String("index.handler"),
Code: lambda.AssetCode_FromAsset(path.join(__dirname, jsii.String("integ.token-authorizer.handler"))),
})
authorizer := awscdk.NewTokenAuthorizer(this, jsii.String("MyAuthorizer"), &TokenAuthorizerProps{
Handler: authorizerFn,
})
restapi := awscdk.NewRestApi(this, jsii.String("MyRestApi"), &RestApiProps{
CloudWatchRole: jsii.Boolean(true),
DefaultMethodOptions: &MethodOptions{
Authorizer: *Authorizer,
},
DefaultCorsPreflightOptions: &CorsOptions{
AllowOrigins: awscdk.Cors_ALL_ORIGINS(),
},
})
restapi.Root.AddMethod(jsii.String("ANY"), awscdk.NewMockIntegration(&IntegrationOptions{
IntegrationResponses: []IntegrationResponse{
&IntegrationResponse{
StatusCode: jsii.String("200"),
},
},
PassthroughBehavior: awscdk.PassthroughBehavior_NEVER,
RequestTemplates: map[string]*string{
"application/json": jsii.String("{ \"statusCode\": 200 }"),
},
}), &MethodOptions{
MethodResponses: []MethodResponse{
&MethodResponse{
StatusCode: jsii.String("200"),
},
},
})
return this
}
Properties
cacheKeyParametersoptionalstring[]cache_key_parametersoptionaltyping.List[str]cacheKeyParametersoptionalList<String>CacheKeyParametersoptionalstring[]CacheKeyParametersoptional*[]*string #It determines request parameters that will make it into the cache key.
cacheNamespaceoptionalstringcache_namespaceoptionalstrcacheNamespaceoptionalStringCacheNamespaceoptionalstringCacheNamespaceoptional*string #connectionTypeoptionalConnectionTypeconnection_typeoptionalConnectionTypeconnectionTypeoptionalConnectionTypeConnectionTypeoptionalConnectionTypeConnectionTypeoptionalConnectionType #Default: ConnectionType.VPC_LINK if vpcLink property is configured; ConnectionType.Internet otherwise.
contentHandlingoptionalContentHandlingcontent_handlingoptionalContentHandlingcontentHandlingoptionalContentHandlingContentHandlingoptionalContentHandlingContentHandlingoptionalContentHandling #Default: none if this property isn't defined, the request payload is passed through from the method request to the integration request without modification, provided that the passthroughBehaviors property is configured to support payload pass-through.
credentialsPassthroughoptionalbooleancredentials_passthroughoptionalboolcredentialsPassthroughoptionalBooleanCredentialsPassthroughoptionalboolCredentialsPassthroughoptional*bool #Default: Caller identity is not passed through
credentialsRoleoptionalIRolecredentials_roleoptionalIRolecredentialsRoleoptionalIRoleCredentialsRoleoptionalIRoleCredentialsRoleoptionalIRole #Default: A role is not assumed
Mutually exclusive with credentialsPassThrough.
integrationResponsesoptionalIntegrationResponse[]integration_responsesoptionaltyping.List[IntegrationResponse]integrationResponsesoptionalList<IntegrationResponse>IntegrationResponsesoptionalIntegrationResponse[]IntegrationResponsesoptional*[]IntegrationResponse #API Gateway intercepts the response from the backend so that you can control how API Gateway surfaces backend responses. For example, you can map the backend status codes to codes that you define.
passthroughBehavioroptionalPassthroughBehaviorpassthrough_behavioroptionalPassthroughBehaviorpassthroughBehavioroptionalPassthroughBehaviorPassthroughBehavioroptionalPassthroughBehaviorPassthroughBehavioroptionalPassthroughBehavior #There are three valid values: WHEN_NO_MATCH, WHEN_NO_TEMPLATES, and NEVER.
requestParametersoptional{ [key: string]: string }request_parametersoptionaltyping.Mapping[str, str]requestParametersoptionalMap<String, String>RequestParametersoptionalIDictionary<string, string>RequestParametersoptional*map[string]*string #notes
Specify request parameters as key-value pairs (string-to-string mappings), with a destination as the key and a source as the value.
Specify the destination by using the following pattern integration.request.location.name, where location is querystring, path, or header, and name is a valid, unique parameter name.
The source must be an existing method request parameter or a static value. You must enclose static values in single quotation marks and pre-encode these values based on their destination in the request.
requestTemplatesoptional{ [key: string]: string }request_templatesoptionaltyping.Mapping[str, str]requestTemplatesoptionalMap<String, String>RequestTemplatesoptionalIDictionary<string, string>RequestTemplatesoptional*map[string]*string #notes
The template that API Gateway uses is based on the value of the Content-Type header that's sent by the client. The content type value is the key, and the template is the value (specified as a string), such as the following snippet:
{ "application/json": "{ \"statusCode\": 200 }" }
responseTransferModeoptionalResponseTransferModeresponse_transfer_modeoptionalResponseTransferModeresponseTransferModeoptionalResponseTransferModeResponseTransferModeoptionalResponseTransferModeResponseTransferModeoptionalResponseTransferMode = ResponseTransferMode.BUFFERED #To enable response streaming, set this value to ResponseTransferMode.STREAM.
timeoutoptionalDurationtimeoutoptionalDurationtimeoutoptionalDurationTimeoutoptionalDurationTimeoutoptionalDuration = Duration.seconds(29) #notes
By default, the value must be between 50 milliseconds and 29 seconds. The upper bound can be increased for regional and private Rest APIs only, via a quota increase request for your account. This increase might require a reduction in your account-level throttle quota limit.
See Amazon API Gateway quotas for more details.