Skip to content

Commit

Permalink
feat(fsx): support AutoImportPolicy in LustreFilesystem (aws#21301)
Browse files Browse the repository at this point in the history
----
closes aws#21288

The LustreFilesystem construct already supports a backing S3 bucket, through the importPath/exportPath parameters.
CloudFormation supports an AutoImportPolicy parameter, to perform this import automatically and continuously if required.  Currently, the L2 construct does not allow this parameter to be set.  This PR adds that capability.

### All Submissions:

* [yes] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [no] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [yes] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [yes] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
tcutts authored and josephedward committed Aug 30, 2022
1 parent 14f1bc3 commit 9066147
Show file tree
Hide file tree
Showing 12 changed files with 1,725 additions and 3 deletions.
29 changes: 28 additions & 1 deletion packages/@aws-cdk/aws-fsx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ inst.userData.addCommands(
);
```

### Importing
### Importing an existing Lustre filesystem

An FSx for Lustre file system can be imported with `fromLustreFileSystemAttributes(stack, id, attributes)`. The
following example lays out how you could import the SecurityGroup a file system belongs to, use that to import the file
Expand Down Expand Up @@ -163,6 +163,33 @@ const inst = new ec2.Instance(this, 'inst', {
fs.connections.allowDefaultPortFrom(inst);
```

### Lustre Data Repository Association support

The LustreFilesystem Construct supports one [Data Repository Association](https://docs.aws.amazon.com/fsx/latest/LustreGuide/fsx-data-repositories.html) (DRA) to an S3 bucket. This allows Lustre hierarchical storage management to S3 buckets, which in turn makes it possible to use S3 as a permanent backing store, and use FSx for Lustre as a temporary high performance cache.

Note: CloudFormation does not currently support for `PERSISTENT_2` filesystems, and so neither does CDK.

The following example illustrates setting up a DRA to an S3 bucket, including automated metadata import whenever a file is changed, created or deleted in the S3 bucket:

```ts
declare const vpc: ec2.Vpc;
declare const bucket: s3.Bucket;

const lustreConfiguration = {
deploymentType: fsx.LustreDeploymentType.SCRATCH_2,
exportPath: bucket.s3UrlForObject(),
importPath: bucket.s3UrlForObject(),
autoImportPolicy: fsx.LustreAutoImportPolicy.NEW_CHANGED_DELETED,
};

const fs = new fsx.LustreFileSystem(this, "FsxLustreFileSystem", {
vpc: vpc,
vpcSubnet: vpc.privateSubnets[0],
storageCapacityGiB: 1200,
lustreConfiguration,
});
```

## FSx for Windows File Server

The L2 construct for the FSx for Windows File Server has not yet been implemented. To instantiate an FSx for Windows
Expand Down
48 changes: 48 additions & 0 deletions packages/@aws-cdk/aws-fsx/lib/lustre-file-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,27 @@ export enum LustreDeploymentType {
*/
PERSISTENT_2 = 'PERSISTENT_2',
}
/**
* The different auto import policies which are allowed
*/
export enum LustreAutoImportPolicy {
/**
* AutoImport is off. Amazon FSx only updates file and directory listings from the linked S3 bucket when the file system is created. FSx does not update file and directory listings for any new or changed objects after choosing this option.
*/
NONE = 'NONE',
/**
* AutoImport is on. Amazon FSx automatically imports directory listings of any new objects added to the linked S3 bucket that do not currently exist in the FSx file system.
*/
NEW = 'NEW',
/**
* AutoImport is on. Amazon FSx automatically imports file and directory listings of any new objects added to the S3 bucket and any existing objects that are changed in the S3 bucket after you choose this option.
*/
NEW_CHANGED = 'NEW_CHANGED',
/**
* AutoImport is on. Amazon FSx automatically imports file and directory listings of any new objects added to the S3 bucket, any existing objects that are changed in the S3 bucket, and any objects that were deleted in the S3 bucket.
* */
NEW_CHANGED_DELETED = 'NEW_CHANGED_DELETED',
}

/**
* The configuration for the Amazon FSx for Lustre file system.
Expand Down Expand Up @@ -69,6 +90,18 @@ export interface LustreConfiguration {
*/
readonly importPath?: string;

/**
* Available with `Scratch` and `Persistent_1` deployment types. When you create your file system, your existing S3 objects appear as file and directory listings. Use this property to choose how Amazon FSx keeps your file and directory listings up to date as you add or modify objects in your linked S3 bucket. `AutoImportPolicy` can have the following values:
*
* For more information, see [Automatically import updates from your S3 bucket](https://docs.aws.amazon.com/fsx/latest/LustreGuide/autoimport-data-repo.html) .
*
* > This parameter is not supported for Lustre file systems using the `Persistent_2` deployment type.
*
* @link http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-fsx-filesystem-lustreconfiguration.html#cfn-fsx-filesystem-lustreconfiguration-autoimportpolicy
* @default - no import policy
*/
readonly autoImportPolicy?: LustreAutoImportPolicy;

/**
* Required for the PERSISTENT_1 deployment type, describes the amount of read and write throughput for each 1
* tebibyte of storage, in MB/s/TiB. Valid values are 50, 100, 200.
Expand Down Expand Up @@ -222,10 +255,25 @@ export class LustreFileSystem extends FileSystemBase {
this.validateExportPath(lustreConfiguration.exportPath, lustreConfiguration.importPath);

this.validateImportedFileChunkSize(lustreConfiguration.importedFileChunkSizeMiB);
this.validateAutoImportPolicy(deploymentType, lustreConfiguration.importPath, lustreConfiguration.autoImportPolicy);
this.validatePerUnitStorageThroughput(deploymentType, lustreConfiguration.perUnitStorageThroughput);
this.validateStorageCapacity(deploymentType, props.storageCapacityGiB);
}

/**
* Validates the auto import policy
*/

private validateAutoImportPolicy(deploymentType: LustreDeploymentType, importPath?: string, autoImportPolicy?: LustreAutoImportPolicy): void {
if (autoImportPolicy === undefined) { return; }
if (importPath === undefined) {
throw new Error('autoImportPolicy requires importPath to be defined');
}
if (deploymentType === LustreDeploymentType.PERSISTENT_2) {
throw new Error('autoImportPolicy is not supported with PERSISTENT_2 deployments');
}
}

/**
* Validates the export path is in the correct format and matches the import path.
*/
Expand Down
5 changes: 4 additions & 1 deletion packages/@aws-cdk/aws-fsx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,22 @@
"devDependencies": {
"@aws-cdk/assertions": "0.0.0",
"@aws-cdk/cdk-build-tools": "0.0.0",
"@aws-cdk/integ-runner": "0.0.0",
"@aws-cdk/cfn2ts": "0.0.0",
"@aws-cdk/integ-runner": "0.0.0",
"@aws-cdk/integ-tests": "0.0.0",
"@aws-cdk/pkglint": "0.0.0",
"@types/jest": "^27.5.2"
},
"dependencies": {
"@aws-cdk/aws-s3": "0.0.0",
"@aws-cdk/aws-ec2": "0.0.0",
"@aws-cdk/aws-iam": "0.0.0",
"@aws-cdk/aws-kms": "0.0.0",
"@aws-cdk/core": "0.0.0",
"constructs": "^10.0.0"
},
"peerDependencies": {
"@aws-cdk/aws-s3": "0.0.0",
"@aws-cdk/aws-ec2": "0.0.0",
"@aws-cdk/aws-iam": "0.0.0",
"@aws-cdk/aws-kms": "0.0.0",
Expand Down
36 changes: 36 additions & 0 deletions packages/@aws-cdk/aws-fsx/test/integ.lustre-file-system-with-s3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as ec2 from '@aws-cdk/aws-ec2';
import * as s3 from '@aws-cdk/aws-s3';
import { App, RemovalPolicy, Stack } from '@aws-cdk/core';
import * as integ from '@aws-cdk/integ-tests';
import * as fsx from '../lib';

const app = new App();

const stack = new Stack(app, 'AwsCdkFsxLustre');

const vpc = new ec2.Vpc(stack, 'VPC');

const bucket = new s3.Bucket(stack, 'ImportBucket', {
removalPolicy: RemovalPolicy.DESTROY,
});

const storageCapacity = 1200;
const lustreConfiguration = {
deploymentType: fsx.LustreDeploymentType.SCRATCH_2,
importPath: bucket.s3UrlForObject(),
autoImportPolicy: fsx.LustreAutoImportPolicy.NEW_CHANGED_DELETED,
};

new fsx.LustreFileSystem(stack, 'FsxLustreFileSystem', {
lustreConfiguration,
storageCapacityGiB: storageCapacity,
vpc,
vpcSubnet: vpc.privateSubnets[0],
removalPolicy: RemovalPolicy.DESTROY,
});

new integ.IntegTest(app, 'FsxLustreWithS3Test', {
testCases: [stack],
});

app.synth();
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "20.0.0",
"files": {
"e5c2880bdb5feb3722b4fec17f3f9cfbe63b27acf4cf4ef5534d672ad6765484": {
"source": {
"path": "AwsCdkFsxLustre.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "e5c2880bdb5feb3722b4fec17f3f9cfbe63b27acf4cf4ef5534d672ad6765484.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
}
},
"dockerImages": {}
}
Loading

0 comments on commit 9066147

Please sign in to comment.