AWS EFS - 创建文件系统后创建挂载目标的脚本

AWS EFS - Script to create mount target after creating the file system

我正在编写一个脚本,该脚本将使用输入的名称创建一个 EFS 文件系统。我正在为 PHP 版本 3 使用 AWS SDK。

我可以使用 createFileSystem 命令创建文件系统。这个新文件系统只有在创建挂载目标后才能使用。如果我在 createFileSystem 命令之后 运行 CreateMountTarget 命令,那么我会收到一个错误,指出文件系统的生命周期状态不在 'available' 状态。

我已尝试使用 createFileSystemAsync 创建承诺并调用该承诺的等待函数以强制脚本同步 运行。但是,当文件系统仍处于 'creating' 生命周期状态时,承诺总是会兑现。

有没有办法使用 AWS SDK 强制脚本等待文件系统处于可用状态?

一种方法是使用 DescribeFileSystems API. In the response look at the LifeCycleState 检查文件系统的状态,如果可用则启动 CreateMountTarget API。您可以在循环中持续检查 DescribeFileSystems,延迟几秒,直到 LifeCycleState 为 Available

您似乎希望 waiter for FileSystemAvailable, but the elasticfilesystem files don't specify one. I'd file an issue on GitHub asking for one. You'd need to wait for DescribeFileSystems 具有 availableLifeCycleState

与此同时,您可能可以使用类似以下内容和 following the waiters guide.

编写自己的内容
{
  "version":2,
  "FileSystemAvailable": {
    "delay": 15,
    "operation": "DescribeFileSystems",
    "maxAttempts": 40,
    "acceptors": [
      {
        "expected": "available",
        "matcher": "pathAll",
        "state": "success",
        "argument": "FileSystems[].LifeCycleState"
      },
      {
        "expected": "deleted",
        "matcher": "pathAny",
        "state": "failure",
        "argument": "FileSystems[].LifeCycleState"
      },
      {
        "expected": "deleting",
        "matcher": "pathAny",
        "state": "failure",
        "argument": "FileSystems[].LifeCycleState"
      }
    ]
  },
}

Promises in the AWS SDK for PHP 用于并发发起 HTTP 请求。这在这种情况下没有帮助,因为 API 调用的行为是在 EFS 中启动异步任务。