Skip to content

Commit

Permalink
feat: availabilityZoneName
Browse files Browse the repository at this point in the history
  • Loading branch information
badmintoncryer committed Dec 26, 2023
1 parent 607dccb commit ee95f04
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion packages/aws-cdk-lib/aws-efs/lib/efs-file-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,13 @@ export interface FileSystemProps {
* or set `@aws-cdk/aws-efs:denyAnonymousAccess` feature flag, otherwise true
*/
readonly allowAnonymousAccess?: boolean;

/**
* For One Zone file systems, specify the AWS Availability Zone in which to create the file system.
*
* @default undefiend - The filesystem is deployed as regional.
*/
readonly availabilityZoneName?: string;
}

/**
Expand Down Expand Up @@ -478,6 +485,10 @@ export class FileSystem extends FileSystemBase {
constructor(scope: Construct, id: string, props: FileSystemProps) {
super(scope, id);

if (props.performanceMode === PerformanceMode.MAX_IO && props.availabilityZoneName) {
throw new Error('AvailabilityZoneName is not supported for file systems with performanceMode MAX_IO');
}

if (props.throughputMode === ThroughputMode.PROVISIONED && props.provisionedThroughputPerSecond === undefined) {
throw new Error('Property provisionedThroughputPerSecond is required when throughputMode is PROVISIONED');
}
Expand Down Expand Up @@ -531,6 +542,7 @@ export class FileSystem extends FileSystemBase {
return this._fileSystemPolicy;
},
}),
availabilityZoneName: props.availabilityZoneName,
});
this._resource.applyRemovalPolicy(props.removalPolicy);

Expand All @@ -549,7 +561,19 @@ export class FileSystem extends FileSystemBase {
defaultPort: ec2.Port.tcp(FileSystem.DEFAULT_PORT),
});

const subnets = props.vpc.selectSubnets(props.vpcSubnets ?? { onePerAz: true });
// When availabilityZoneName is specified, to avoid deployment failure, mountTarget should also be created only in the specified AZ.
let subnetSelection: ec2.SubnetSelection;
if (props.availabilityZoneName) {
subnetSelection = { availabilityZones: [props.availabilityZoneName] };
if (props.vpcSubnets) {
subnetSelection = { ...props.vpcSubnets, ...subnetSelection };
}
} else if (props.vpcSubnets) {
subnetSelection = props.vpcSubnets;
} else {
subnetSelection = { onePerAz: true };
}
const subnets = props.vpc.selectSubnets(subnetSelection);

// We now have to create the mount target for each of the mentioned subnet

Expand Down

0 comments on commit ee95f04

Please sign in to comment.