How to create more than one environment under a single Elasticbeanstalk application, using cloudformation.
I have a created a cloudformation template which basically creates a CI/CD pipeline on AWS by provisioning necessary resources. I have a problem when it comes to creating multiple environments(e.g staging and prod) under same elastic beanstalk application using the template. When I deploy the template for the first time, say a staging environment, it works perfectly, but when I redeploy it in this case for production environment, it fails with the error that the application name already exists. I have tried to use cloudformation conditions but wasn't successful. I was wondering if there's a way I can have a condition to check if a similar ApplicationName
exist, it skips creation of the application name and creates an environment under the name.
WebApplication:
Type: AWS::ElasticBeanstalk::Application
Properties:
ApplicationName: !Sub "${GithubRepo}"
Description: "Application Description"
WebApplicationEnvironment:
Type: AWS::ElasticBeanstalk::Environment
Properties:
ApplicationName: !Ref WebApplication
EnvironmentName: !Sub "${GithubRepo}-${Stage}"
TemplateName: !Ref WebApplicationTemplate
I expect when I create when I run the template the second time, a new environment should be created in the specified application.