# SecretRotation

Secret rotation for a service or database.

Extends: Construct › SecretRotation
Implements: IConstruct, IDependable

- Source: [`aws-secretsmanager/lib/secret-rotation.ts`](https://github.com/aws/aws-cdk/blob/v2.274.0/packages/aws-cdk-lib/aws-secretsmanager/lib/secret-rotation.ts#L373)

## Example

```ts
declare const myUserSecret: secretsmanager.Secret;
declare const myMasterSecret: secretsmanager.Secret;
declare const myDatabase: ec2.IConnectable;
declare const myVpc: ec2.Vpc;

new secretsmanager.SecretRotation(this, 'SecretRotation', {
  application: secretsmanager.SecretRotationApplication.MYSQL_ROTATION_MULTI_USER,
  secret: myUserSecret, // The secret that will be rotated
  masterSecret: myMasterSecret, // The secret used for the rotation
  target: myDatabase,
  vpc: myVpc,
});
```

## Initializer

```ts
new SecretRotation(scope: Construct, id: string, props: SecretRotationProps)
```

## Construct Props

- `application`: [SecretRotationApplication](/cdk/api/v2/docs/aws-cdk-lib.aws_secretsmanager.SecretRotationApplication.html) (required) — The serverless application for the rotation.

- `automaticallyAfter`: [Duration](/cdk/api/v2/docs/aws-cdk-lib.Duration.html) = Duration.days(30) — Specifies the number of days after the previous rotation before Secrets Manager triggers the next automatic rotation.

- `endpoint`: [IInterfaceVpcEndpoint](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.IInterfaceVpcEndpoint.html) — The VPC interface endpoint to use for the Secrets Manager API.

  **Default:** https://secretsmanager.<region>.amazonaws.com

  If you enable private DNS hostnames for your VPC private endpoint (the default), you don't
  need to specify an endpoint. The standard Secrets Manager DNS hostname the Secrets Manager
  CLI and SDKs use by default (https://secretsmanager.<region>.amazonaws.com) automatically
  resolves to your VPC endpoint.

- `excludeCharacters`: string — Characters which should not appear in the generated password.

  **Default:** no additional characters are explicitly excluded

- `masterSecret`: [ISecret](/cdk/api/v2/docs/aws-cdk-lib.aws_secretsmanager.ISecret.html) — The master secret for a multi user rotation scheme.

  **Default:** single user rotation scheme

- `rotateImmediatelyOnUpdate`: boolean = true — Specifies whether to rotate the secret immediately or wait until the next scheduled rotation window.

- `secret`: [ISecret](/cdk/api/v2/docs/aws-cdk-lib.aws_secretsmanager.ISecret.html) (required) — The secret to rotate. It must be a JSON string with the following format:.

  ```
  {
    "engine": <required: database engine>,
    "host": <required: instance host name>,
    "username": <required: username>,
    "password": <required: password>,
    "dbname": <optional: database name>,
    "port": <optional: if not specified, default port will be used>,
    "masterarn": <required for multi user rotation: the arn of the master secret which will be used to create users/change passwords>
  }
  ```

  This is typically the case for a secret referenced from an `AWS::SecretsManager::SecretTargetAttachment`
  or an `ISecret` returned by the `attach()` method of `Secret`.

- `securityGroup`: [ISecurityGroup](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.ISecurityGroup.html) — The security group for the Lambda rotation function.

  **Default:** a new security group is created

- `target`: [IConnectable](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.IConnectable.html) (required) — The target service or database.

- `vpc`: [IVpc](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.IVpc.html) (required) — The VPC where the Lambda rotation function will run.

- `vpcSubnets`: [SubnetSelection](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.SubnetSelection.html) — The type of subnets in the VPC where the Lambda rotation function will run.

  **Default:** the Vpc default strategy if not specified.

## Properties

- `node`: [Node](/cdk/api/v2/docs/constructs.Node.html) (required) — The tree node.

## Methods

- `isConstruct(x: any): boolean` (static) — Checks if `x` is a construct.

  Use this method instead of `instanceof` to properly detect `Construct`
  instances, even when the construct library is symlinked.

  Explanation: in JavaScript, multiple copies of the `constructs` library on
  disk are seen as independent, completely different libraries. As a
  consequence, the class `Construct` in each copy of the `constructs` library
  is seen as a different class, and an instance of one class will not test as
  `instanceof` the other class. `npm install` will not create installations
  like this, but users may manually symlink construct libraries together or
  use a monorepo tool: in those cases, multiple copies of the `constructs`
  library can be accidentally installed, and `instanceof` will behave
  unpredictably. It is safest to avoid using `instanceof`, and using
  this type-testing method instead.

  **Parameters**

  - `x` — Any object.

  **Returns:** true if `x` is an object created from a class which extends `Construct`.

- `toString(): string` — Returns a string representation of this construct.

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.
  Use multiple `with()` calls if subsequent mixins should apply to added
  constructs.

  **Parameters**

  - `mixins` — The mixins to apply.

  **Returns:** This construct for chaining
