# ApiKeyOptions

The options for creating an API Key.

Extends: [ResourceOptions](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.ResourceOptions.html)
Used as argument in: [IStage.addApiKey](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.IStage.html#addapikey), [RestApiBase.addApiKey](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.RestApiBase.html#addapikey)

- Source: [`aws-apigateway/lib/api-key.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-apigateway/lib/api-key.ts#L38)

## Example

TypeScript:

```ts
declare const api: apigateway.RestApi;
const key = api.addApiKey('ApiKey', {
  apiKeyName: 'myApiKey1',
  value: 'MyApiKeyThatIsAtLeast20Characters',
});
```

Python:

```python
# api: apigateway.RestApi

key = api.add_api_key("ApiKey",
    api_key_name="myApiKey1",
    value="MyApiKeyThatIsAtLeast20Characters"
)
```

Java:

```java
RestApi api;

IApiKey key = api.addApiKey("ApiKey", ApiKeyOptions.builder()
        .apiKeyName("myApiKey1")
        .value("MyApiKeyThatIsAtLeast20Characters")
        .build());
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
RestApi api;

var key = api.AddApiKey("ApiKey", new ApiKeyOptions {
    ApiKeyName = "myApiKey1",
    Value = "MyApiKeyThatIsAtLeast20Characters"
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var api RestApi

key := api.AddApiKey(jsii.String("ApiKey"), &ApiKeyOptions{
	ApiKeyName: jsii.String("myApiKey1"),
	Value: jsii.String("MyApiKeyThatIsAtLeast20Characters"),
})
```

## Properties

- `apiKeyName`: string — A name for the API key.

  **Default:** automically generated name

  If you don't specify a name, AWS CloudFormation generates a unique physical ID and uses that ID for the API key name.

- `defaultCorsPreflightOptions`: [CorsOptions](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.CorsOptions.html) — Adds a CORS preflight OPTIONS method to this resource and all child resources.

  **Default:** CORS is disabled

  You can add CORS at the resource-level using `addCorsPreflight`.

- `defaultIntegration`: [Integration](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.Integration.html) — An integration to use as a default for all methods created within this API unless an integration is specified.

  **Default:** Inherited from parent.

- `defaultMethodOptions`: [MethodOptions](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.MethodOptions.html) — Method options to use as a default for all methods created within this API unless custom options are specified.

  **Default:** Inherited from parent.

- `description`: string = none — A description of the purpose of the API key.

- `value`: string = none — The value of the API key.

  Must be at least 20 characters long.
