我有一个CloudFormation脚本具有以下内容:
"Parameters": { "optionalExistingEFSDrive": { "Description": "EFS drive to store client content. If left empty a new drive will be created automatically.", "Type": "String", "Default": "" } }, "Conditions": { "CreateEFSDrive": { "Fn::Equals": [ { "Ref": "optionalExistingEFSDrive" }, "" ] }, }, "Resources": { "WebFileSystem": { "Type": "AWS::EFS::FileSystem", "Condition": "CreateEFSDrive", "DeletionPolicy": "Retain", "Properties": { "FileSystemTags": [ { "Key": "Name", "Value": "WebFileSystem" } ], "PerformanceMode": "generalPurpose" } }, "WebFileSystemMountTarget1": { "Type": "AWS::EFS::MountTarget", "Properties": { "SubnetId": { "Ref": "WebFileSystemSubnet1" }, "SecurityGroups": [ { "Ref": "WebFileSystemSecurityGroup" } ], "FileSystemId": { "Fn::If": [ "CreateEFSDrive", { "Ref": "WebFileSystem" }, { "Ref": "optionalExistingEFSDrive" } ] } } } }
传入作为现有文件系统的文件系统标识的optionalExistingEFSDrive的值时,会创build一个新的文件系统,但挂载目标正确安装到提供的optionalExistingEFSDrive文件系统。
我错过了什么? 我不想创build一个新的EFS,我想重新使用一个现有的。
我无法重现您在使用此模板(您的模板的缩小版本并转换为YAML)时描述的行为:
AWSTemplateFormatVersion: 2010-09-09 Parameters: WebFileSystemSubnet1: Type: String WebFileSystemSecurityGroup: Type: String OptionalExistingEFSDrive: Type: String Conditions: CreateEFSDrive: !Equals - !Ref OptionalExistingEFSDrive - '' Resources: WebFileSystem: Type: 'AWS::EFS::FileSystem' Condition: CreateEFSDrive DeletionPolicy: Retain Properties: FileSystemTags: - Key: Name Value: WebFileSystem PerformanceMode: generalPurpose WebFileSystemMountTarget1: Type: 'AWS::EFS::MountTarget' Properties: SubnetId: !Ref WebFileSystemSubnet1 SecurityGroups: - !Ref WebFileSystemSecurityGroup FileSystemId: !If - CreateEFSDrive - !Ref WebFileSystem - !Ref OptionalExistingEFSDrive
所以,当我使用这个模板并传入一个现有的文件系统ID时,只有挂载目标被创build,正如所料。