1
votes

I can deploy an EB environment via CloudFormation with AWS::ElasticBeanstalk::Environment and AWS::ElasticBeanstalk::ApplicationVersion in the same template

That's great but if the beanstalk app deployment fails CloudFormation doesn't fail- the stack/environment is usually created successfully. So CloudFormation deploys successfully, the Beanstalk app version deploy fails, Beanstalk rolls back to the previous version, and returns to a healthy state and the only way I know it failed is to view the console or doing something wonky like try to check the current app version after the deployment.

The nested stack AWS::ElasticBeanstalk::Environment creates however does seem to fail if the app version deployment fails, but I can find no way of linking the two which is very annoying.

I need to programmatically identify the nested stack AWS::ElasticBeanstalk::Environment creates so after CloudFormation finishes and can check the status of that nested stack to see if the Beanstalk deploy was actually successful

Edit

At least they are tagged with the environment name. I really don't love this but it seems to work, curious about better options though:

aws cloudformation describe-stacks --query 'Stacks[?Tags[?Key == `elasticbeanstalk:environment-name` && Value == `myenvname`]].{StackName: StackName}' --output text
1

1 Answers

0
votes

Its technically not a nested stack, but a fully independent stack from AWS::ElasticBeanstalk::Environment.

Nevertheless, one way to get the stack name, would be through custom resource in CFN.

In the CFN you would have a lambda which would use describe-environments using your environment, get the EB stack name, and return it to your stack for further processing.

One of the outcomes of the query is EnvironmentId. For example

"EnvironmentId": "e-ctpmqpqwjm"

The stack that EB produces has name in the format:

awseb-<EnvironmentId>-stack

Sadly, I can't find any reference for this. This is based on my own observations. Thus, if you would choose to explore this option, you would have to verify if the naming convention is same for you.