To use the Compose Environments API, first run eb init from the project folder, specifying each component by the name of the folder that contains it with the --modules option, configure each component, and then create the .elasticbeanstalkdirectory in each component folder.
For detailed explanantion have a look at the this blog.