# Integration

Base class for backend integrations for an API Gateway method.

Use one of the concrete classes such as `MockIntegration`, `AwsIntegration`, `LambdaIntegration`
or implement on your own by specifying the set of props.

Superclass of: [AwsIntegration](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.AwsIntegration.html), [HttpIntegration](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.HttpIntegration.html), [LambdaIntegration](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.LambdaIntegration.html), [MockIntegration](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.MockIntegration.html), SagemakerIntegration
Used as argument in: [IResource.addMethod](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.IResource.html#addmethod)

- Source: [`aws-apigateway/lib/integration.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-apigateway/lib/integration.ts#L228)
- Type last changed: v2.178.0 · 6 Feb 2025

## Example

TypeScript:

```ts
declare const books: apigateway.Resource;
declare const iamUser: iam.User;

const getBooks = books.addMethod('GET', new apigateway.HttpIntegration('http://amazon.com'), {
  authorizationType: apigateway.AuthorizationType.IAM
});

iamUser.attachInlinePolicy(new iam.Policy(this, 'AllowBooks', {
  statements: [
    new iam.PolicyStatement({
      actions: [ 'execute-api:Invoke' ],
      effect: iam.Effect.ALLOW,
      resources: [ getBooks.methodArn ]
    })
  ]
}))
```

Python:

```python
# books: apigateway.Resource
# iam_user: iam.User

get_books = books.add_method("GET", apigateway.HttpIntegration("http://amazon.com"),
    authorization_type=apigateway.AuthorizationType.IAM
)

iam_user.attach_inline_policy(iam.Policy(self, "AllowBooks",
    statements=[
        iam.PolicyStatement(
            actions=["execute-api:Invoke"],
            effect=iam.Effect.ALLOW,
            resources=[get_books.method_arn]
        )
    ]
))
```

Java:

```java
Resource books;
User iamUser;

Method getBooks = books.addMethod("GET", new HttpIntegration("http://amazon.com"), MethodOptions.builder()
        .authorizationType(AuthorizationType.IAM)
        .build());

iamUser.attachInlinePolicy(Policy.Builder.create(this, "AllowBooks")
        .statements(List.of(
            PolicyStatement.Builder.create()
                    .actions(List.of("execute-api:Invoke"))
                    .effect(Effect.ALLOW)
                    .resources(List.of(getBooks.getMethodArn()))
                    .build()))
        .build());
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
Resource books;
User iamUser;

var getBooks = books.AddMethod("GET", new HttpIntegration("http://amazon.com"), new MethodOptions {
    AuthorizationType = AuthorizationType.IAM
});

iamUser.AttachInlinePolicy(new Policy(this, "AllowBooks", new PolicyProps {
    Statements = new [] {
        new PolicyStatement(new PolicyStatementProps {
            Actions = new [] { "execute-api:Invoke" },
            Effect = Effect.ALLOW,
            Resources = new [] { getBooks.MethodArn }
        }) }
}));
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var books Resource
var iamUser User

getBooks := books.AddMethod(jsii.String("GET"), apigateway.NewHttpIntegration(jsii.String("http://amazon.com")), &MethodOptions{
	AuthorizationType: apigateway.AuthorizationType_IAM,
})

iamUser.AttachInlinePolicy(iam.NewPolicy(this, jsii.String("AllowBooks"), &PolicyProps{
	Statements: []PolicyStatement{
		iam.NewPolicyStatement(&PolicyStatementProps{
			Actions: []*string{
				jsii.String("execute-api:Invoke"),
			},
			Effect: iam.Effect_ALLOW,
			Resources: []*string{
				getBooks.methodArn,
			},
		}),
	},
}))
```

## Initializer

TypeScript:

```ts
new Integration(props: IntegrationProps)
```

Python:

```python
Integration(props: IntegrationProps)
```

Java:

```java
new Integration(IntegrationProps props)
```

C# / .NET:

```csharp
new Integration(IntegrationProps props)
```

Golang:

```go
NewIntegration(Props IntegrationProps)
```

## Methods

- `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.
