# FunctionHook

Class · Stable

Use a Lambda Function as a hook target.

Internally creates a Topic to make the connection.

Implements: [ILifecycleHookTarget](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_autoscaling.ILifecycleHookTarget.html)

- Source: [`aws-autoscaling-hooktargets/lib/lambda-hook.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-autoscaling-hooktargets/lib/lambda-hook.ts#L15)
- Type last changed: v2.2.0 · 15 Dec 2021

## Example

TypeScript:

```ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { aws_autoscaling_hooktargets as autoscaling_hooktargets } from 'aws-cdk-lib';
import { aws_kms as kms } from 'aws-cdk-lib';
import { aws_lambda as lambda } from 'aws-cdk-lib';

declare const function_: lambda.Function;
declare const key: kms.Key;
const functionHook = new autoscaling_hooktargets.FunctionHook(function_, /* all optional props */ key);
```

Python:

```python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
from aws_cdk import aws_autoscaling_hooktargets as autoscaling_hooktargets
from aws_cdk import aws_kms as kms
from aws_cdk import aws_lambda as lambda_

# function_: lambda.Function
# key: kms.Key

function_hook = autoscaling_hooktargets.FunctionHook(function_, key)
```

Java:

```java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.services.autoscaling.hooktargets.*;
import software.amazon.awscdk.services.kms.*;
import software.amazon.awscdk.services.lambda.*;

Function function_;
Key key;

FunctionHook functionHook = new FunctionHook(function_, key);
```

C#:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK.AWS.AutoScaling.HookTargets;
using Amazon.CDK.AWS.KMS;
using Amazon.CDK.AWS.Lambda;

Function function_;
Key key;

var functionHook = new FunctionHook(function_, key);
```

Go:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"

var function_ Function
var key Key

functionHook := awscdk.Aws_autoscaling_hooktargets.NewFunctionHook(function_, key)
```

## Initializer

TypeScript:

```ts
new FunctionHook(fn: IFunction, encryptionKey?: IKey)
```

Python:

```python
FunctionHook(fn: IFunction, encryption_key: typing.Optional[IKey] = None)
```

Java:

```java
new FunctionHook(IFunction fn, IKey encryptionKey)
```

C#:

```csharp
new FunctionHook(IFunction fn, IKey? encryptionKey = null)
```

Go:

```go
NewFunctionHook(Fn IFunction, EncryptionKey IKey)
```

## Methods

- `bind(_scope: Construct, options: BindHookTargetOptions): LifecycleHookTargetConfig` — If the `IRole` does not exist in `options`, will create an `IRole` and an SNS Topic and attach both to the lifecycle hook.

  If the `IRole` does exist in `options`, will only create an SNS Topic and attach it to the lifecycle hook.
