To Nha Notes | Aug. 8, 2024, 11:40 a.m.
aws elasticbeanstalk describe-configuration-settings \
--application-name your-application-name \
--environment-name your-existing-environment-name \
--query "ConfigurationSettings[0].OptionSettings" \
> existing-env-config.json
jq '[.[] | select(.Namespace=="aws:elasticbeanstalk:application:environment")]' existing-env-config.json > env-properties.json
aws elasticbeanstalk update-environment \
--environment-name your-new-environment-name \
--option-settings file://env-properties.json
Step 1: Save EB Configuration
Use the Elastic Beanstalk saved configurations blog to save your environment configuration.
Download the saved configuration file from your S3 bucket, typically located at a URI like:
s3://elasticbeanstalk-us-west-2-123456789012/resources/templates/my-app/
Use the following Python script to extract and format the environment variables from the aws:elasticbeanstalk:application:environment section of the downloaded file:
eb_env_options = """
<CONFIGURATION_OPTIONS_IN_DOWNLOAD_FILE_HERE>
"""
eb_env_options = eb_env_options.strip().split('\n')
eb_env_options = [x.split(': ') for x in eb_env_options]
eb_env_options = {f"\"{x[0]}\" = \"{x[1]}\"" for x in eb_env_options}
eb_env_options = '\n'.join(eb_env_options)
print(eb_env_options)
Copy the output from the Python script into the env_vars variable in your terraform.tfvars file:
env_vars = {
<EB_ENV_OPTIONS_OUTPUT>
}