3

I am writing a script that will create an EFS file system with a name from input. I am using the AWS SDK for PHP Version 3.

I am able to create the file system using the createFileSystem command. This new file system is not usable until it has a mount target created. If I run the CreateMountTarget command after the createFileSystem command then I receive an error that the file system's life cycle state is not in the 'available' state.

I have tried using createFileSystemAsync to create a promise and calling the wait function on that promise to force the script to run synchronously. However, the promise is always fulfilled while the file system is still in 'creating' life cycle state.

Is there a way to force the script to wait for the file system to be in the available state using the AWS SDK?

Jessie Edmisten
  • 240
  • 1
  • 2
  • 11

2 Answers2

2

One way is to check the status of the file system using DescribeFileSystems API. In the response look at the LifeCycleState, if it is available fire the CreateMountTarget API. You can keep checking the DescribeFileSystems in a loop with a few seconds delay until the LifeCycleState is Available

titogeo
  • 2,156
  • 2
  • 24
  • 41
2

It looks like you want a 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 to have a LifeCycleState of available.

In the mean time, you can probably write your own with something like the following and 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 are used for making the HTTP request concurrently. This doesn't help in this case because the behavior of the API call is to start an asynchronous task in EFS.

Kevin Stich
  • 773
  • 1
  • 8
  • 24