Search code examples
amazon-web-servicesaws-sdkamazon-efsaws-php-sdk

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


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?


Solution

  • 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