How to separate Elastic Beanstalk environments?

Solution for How to separate Elastic Beanstalk environments?
is Given Below:

I am building a service on top of EB which will host several different applications. I want to be able to separate each application so there is no conflicts between them.

For example, I have app1 and app2 both with staging environments. When I try deploy staging env to app2 I get an error Environment staging already exists because it exists under app1.

Is there a way to create a completely separate instance for each application in order to avoid these kind of conflicts and also perhaps keep things more secure so that applications don’t have access to each others environments?

If it’s of any help, I am using the Javascript aws-sdk to create the environment like so:

const createElasticBeanstalkEnvironment = async  ({
  applicationName,
  versionLabel,
  environmentName
}) => {
  const describeEnvironmentsCommand = new DescribeEnvironmentsCommand({
    EnvironmentNames: [environmentName],
    ApplicationName: applicationName,
    IncludeDeleted: false
  });

  const { Environments = [] } = await elasticBeanstalkClient.send(describeEnvironmentsCommand);

  const isExistingEnvironment = Environments.length > 0;

  if( isExistingEnvironment ) {
    const updateEnvironmentCommand = new UpdateEnvironmentCommand({
      ApplicationName: applicationName,
      EnvironmentName: environmentName,
      VersionLabel: versionLabel,
      // ...
    });

    return elasticBeanstalkClient.send(updateEnvironmentCommand);
  }

  const createEnvironmentCommand = new CreateEnvironmentCommand({
    ApplicationName: applicationName,
    EnvironmentName: environmentName,
    VersionLabel: versionLabel,
    // ...
  });

  return elasticBeanstalkClient.send(createEnvironmentCommand);
}

You can see I am doing a check if the environment exists which if it doesn’t, then I create it. My code to describeEnvironments returns false because it doesn’t exist for that application but when I call CreateEnvironmentCommand I get the error that it already exists (albeit under another env)