Brian
Brian

Reputation: 13571

How to terminate and restore Elastic Beanstalk environment at a scheduled time?

I want to terminate one of my Elastic Beanstalk Environments at midnight and restore it at the morning every day.

So I followed this tutorial to setup lambda functions and CloudWatch events.

There's one thing that I find strange inside the tutorial. The tutorial uses rebuild_environment function to restore the EB environment. The document of this function says that rebuild_environment would first deletes the EB environment, than creates all of the resources associated with the EB environment.

When I run rebuild_environment, I got No Environment found for EnvironmentName = 'my-eb-environment-name' error. This is because my-eb-environment-name has already been terminated at midnight.

What's the correct way to restore terminated EB environment using boto3?

Upvotes: 1

Views: 1811

Answers (1)

qkhanhpro
qkhanhpro

Reputation: 5220

Terminate your Elastic Beanstalk Environment and call the rebuild function of boto3 with EnvironmentId instead of EnvironmentName

It should work. I think EnvironmentName is used for rebuild on non-terminated Elastic Beanstalk Environment only

You can also rebuild terminated environments within six weeks (42 days) of their termination. When you rebuild, Elastic Beanstalk attempts to create a new environment with the same name, ID, and configuration.

Just beware of the rare case

Unless you are using your own custom domain name with your terminated environment, the environment uses a subdomain of elasticbeanstalk.com. These subdomains are shared within an Elastic Beanstalk region. Therefore, they can be used by any environment created by any customer in the same region. While your environment was terminated, another environment could use its subdomain. In this case, the rebuild would fail.

Upvotes: 1

Related Questions