Skip to content
v2.274.0

HttpIntegration Class ​

You can integrate an API method with an HTTP endpoint using the HTTP proxy integration or the HTTP custom integration,.

With the proxy integration, the setup is simple. You only need to set the HTTP method and the HTTP endpoint URI, according to the backend requirements, if you are not concerned with content encoding or caching.

With the custom integration, the setup is more involved. In addition to the proxy integration setup steps, you need to specify how the incoming request data is mapped to the integration request and how the resulting integration response data is mapped to the method response.

Example ​

ts
declare const authFn: lambda.Function;
declare const books: apigateway.Resource;

const auth = new apigateway.RequestAuthorizer(this, 'booksAuthorizer', {
  handler: authFn,
  identitySources: [apigateway.IdentitySource.header('Authorization')]
});

books.addMethod('GET', new apigateway.HttpIntegration('http://amazon.com'), {
  authorizer: auth
});
python
# auth_fn: lambda.Function
# books: apigateway.Resource


auth = apigateway.RequestAuthorizer(self, "booksAuthorizer",
    handler=auth_fn,
    identity_sources=[apigateway.IdentitySource.header("Authorization")]
)

books.add_method("GET", apigateway.HttpIntegration("http://amazon.com"),
    authorizer=auth
)
java
Function authFn;
Resource books;


RequestAuthorizer auth = RequestAuthorizer.Builder.create(this, "booksAuthorizer")
        .handler(authFn)
        .identitySources(List.of(IdentitySource.header("Authorization")))
        .build();

books.addMethod("GET", new HttpIntegration("http://amazon.com"), MethodOptions.builder()
        .authorizer(auth)
        .build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
Function authFn;
Resource books;


var auth = new RequestAuthorizer(this, "booksAuthorizer", new RequestAuthorizerProps {
    Handler = authFn,
    IdentitySources = new [] { IdentitySource.Header("Authorization") }
});

books.AddMethod("GET", new HttpIntegration("http://amazon.com"), new MethodOptions {
    Authorizer = auth
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var authFn Function
var books Resource


auth := apigateway.NewRequestAuthorizer(this, jsii.String("booksAuthorizer"), &RequestAuthorizerProps{
	Handler: authFn,
	IdentitySources: []*string{
		apigateway.IdentitySource_Header(jsii.String("Authorization")),
	},
})

books.AddMethod(jsii.String("GET"), apigateway.NewHttpIntegration(jsii.String("http://amazon.com")), &MethodOptions{
	Authorizer: auth,
})

Initializer ​

ts
new HttpIntegration(url: string, props?: HttpIntegrationProps)
python
HttpIntegration(url: str, props: typing.Optional[HttpIntegrationProps] = None)
java
new HttpIntegration(String url, HttpIntegrationProps props)
csharp
new HttpIntegration(string url, HttpIntegrationProps? props = null)
go
NewHttpIntegration(Url *string, Props HttpIntegrationProps)

Methods ​

bind(method: Method): IntegrationConfigdef bind(self, method: Method) -> IntegrationConfigpublic IntegrationConfig bind(Method method)public IntegrationConfig Bind(Method method)func Bind(Method Method) IntegrationConfig#
Can be overridden by subclasses to allow the integration to interact with the method being integrated, access the REST API object, method ARNs, etc.