# ProductStackHistory

A Construct that contains a Service Catalog product stack with its previous deployments maintained.

Extends: [Construct](https://docs.aws.amazon.com/cdk/api/v2/docs/constructs.Construct.html) › ProductStackHistory
Implements: [IConstruct](https://docs.aws.amazon.com/cdk/api/v2/docs/constructs.IConstruct.html), [IDependable](https://docs.aws.amazon.com/cdk/api/v2/docs/constructs.IDependable.html)

- Source: [`aws-servicecatalog/lib/product-stack-history.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-servicecatalog/lib/product-stack-history.ts#L54)
- Type last changed: v2.196.0 · 16 May 2025

## Example

TypeScript:

```ts
class S3BucketProduct extends servicecatalog.ProductStack {
  constructor(scope: Construct, id: string) {
    super(scope, id);

    new s3.Bucket(this, 'BucketProductV2');
  }
}

const productStackHistory = new servicecatalog.ProductStackHistory(this, 'ProductStackHistory', {
  productStack: new S3BucketProduct(this, 'S3BucketProduct'),
  currentVersionName: 'v2',
  currentVersionLocked: true
});

const product = new servicecatalog.CloudFormationProduct(this, 'MyFirstProduct', {
  productName: "My Product",
  owner: "Product Owner",
  productVersions: [
    productStackHistory.currentVersion(),
  ],
});
```

Python:

```python
class S3BucketProduct(servicecatalog.ProductStack):
    def __init__(self, scope, id):
        super().__init__(scope, id)

        s3.Bucket(self, "BucketProductV2")

product_stack_history = servicecatalog.ProductStackHistory(self, "ProductStackHistory",
    product_stack=S3BucketProduct(self, "S3BucketProduct"),
    current_version_name="v2",
    current_version_locked=True
)

product = servicecatalog.CloudFormationProduct(self, "MyFirstProduct",
    product_name="My Product",
    owner="Product Owner",
    product_versions=[
        product_stack_history.current_version()
    ]
)
```

Java:

```java
public class S3BucketProduct extends ProductStack {
    public S3BucketProduct(Construct scope, String id) {
        super(scope, id);

        new Bucket(this, "BucketProductV2");
    }
}

ProductStackHistory productStackHistory = ProductStackHistory.Builder.create(this, "ProductStackHistory")
        .productStack(new S3BucketProduct(this, "S3BucketProduct"))
        .currentVersionName("v2")
        .currentVersionLocked(true)
        .build();

CloudFormationProduct product = CloudFormationProduct.Builder.create(this, "MyFirstProduct")
        .productName("My Product")
        .owner("Product Owner")
        .productVersions(List.of(productStackHistory.currentVersion()))
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
class S3BucketProduct : ProductStack
{
    public S3BucketProduct(Construct scope, string id) : base(scope, id)
    {

        new Bucket(this, "BucketProductV2");
    }
}

var productStackHistory = new ProductStackHistory(this, "ProductStackHistory", new ProductStackHistoryProps {
    ProductStack = new S3BucketProduct(this, "S3BucketProduct"),
    CurrentVersionName = "v2",
    CurrentVersionLocked = true
});

var product = new CloudFormationProduct(this, "MyFirstProduct", new CloudFormationProductProps {
    ProductName = "My Product",
    Owner = "Product Owner",
    ProductVersions = new [] { productStackHistory.CurrentVersion() }
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
type s3BucketProduct struct {
	ProductStack
}

func newS3BucketProduct(scope Construct, id *string) *s3BucketProduct {
	this := &s3BucketProduct{}
	servicecatalog.NewProductStack_Override(this, scope, id)

	s3.NewBucket(this, jsii.String("BucketProductV2"))
	return this
}

productStackHistory := servicecatalog.NewProductStackHistory(this, jsii.String("ProductStackHistory"), &ProductStackHistoryProps{
	ProductStack: newS3BucketProduct(this, jsii.String("S3BucketProduct")),
	CurrentVersionName: jsii.String("v2"),
	CurrentVersionLocked: jsii.Boolean(true),
})

product := servicecatalog.NewCloudFormationProduct(this, jsii.String("MyFirstProduct"), &CloudFormationProductProps{
	ProductName: jsii.String("My Product"),
	Owner: jsii.String("Product Owner"),
	ProductVersions: []CloudFormationProductVersion{
		productStackHistory.CurrentVersion(),
	},
})
```

## Initializer

TypeScript:

```ts
new ProductStackHistory(scope: Construct, id: string, props: ProductStackHistoryProps)
```

Python:

```python
ProductStackHistory(scope: Construct, id: str, props: ProductStackHistoryProps)
```

Java:

```java
new ProductStackHistory(Construct scope, String id, ProductStackHistoryProps props)
```

C# / .NET:

```csharp
new ProductStackHistory(Construct scope, string id, ProductStackHistoryProps props)
```

Golang:

```go
NewProductStackHistory(Scope Construct, Id *string, Props ProductStackHistoryProps)
```

## Construct Props

- `currentVersionLocked`: boolean (required) — If this is set to true, the ProductStack will not be overwritten if a snapshot is found for the currentVersionName.

- `currentVersionName`: string (required) — The current version name of the ProductStack.

- `description`: string — The description of the product version.

  **Default:** No description provided

- `directory`: string = 'product-stack-snapshots' — The directory where template snapshots will be stored.

- `productStack`: [ProductStack](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_servicecatalog.ProductStack.html) (required) — The ProductStack whose history will be retained as a snapshot.

- `validateTemplate`: boolean = true — Whether the specified product template will be validated by CloudFormation.

  If turned off, an invalid template configuration can be stored.

## Properties

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

- `PROPERTY_INJECTION_ID`: string (static) — Uniquely identifies this class.

## Methods

- `currentVersion(): CloudFormationProductVersion` — Retains product stack template as a snapshot when deployed and retrieves a CloudFormationProductVersion for the current product version.

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

- `versionFromSnapshot(productVersionName: string): CloudFormationProductVersion` — Retrieves a CloudFormationProductVersion from a previously deployed productVersionName.

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