By using AWS re:Post, you agree to the AWS re:Post Terms of Use

Help getting a Flask App to run on Elastic Beanstalk under new Launch Configuration

0

Hiya, I'm just trying to get a very simple flask app to run on Elastic Beanstalk, but it won't work no matter how I do it.

When trying to run from the command terminal using "eb init -p "64bit Amazon Linux 2023 v4.2.0 running Python 3.11" flask_app.py" I get errors like "Creating Auto Scaling launch configuration failed Reason: Resource handler returned message: "The Launch Configuration creation operation is not available in your account. Use launch templates to create configuration templates for your Auto Scaling groups. ".

More recently I've been trying to use CloudFormation with eb referenced in a template yaml file e.g. "aws cloudformation create-stack --stack-name FlaskAppLaunchTemplateStack4 --template-body file://launch-template-asg4.yaml". This fail at the same stage, without any meaningful error message: it just says "CREATE_FAILED" at the "MyAutoScalingGroup" stage.

Any help very much appreciated as I've been pulling my hair out with this for 24 hours now.

2 Answers
1

Hello.

After running "eb init", create a directory called ".ebextensions" within the directory.
Please create a file called "options.config" in the ".ebextensions" directory.
Please try creating the resource with "eb create" after changing the file as shown below.
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/command-options-general.html#command-options-general-autoscalinglaunchconfiguration

option_settings:
  aws:autoscaling:launchconfiguration:
    DisableIMDSv1: True

The "eb init" command answered by AWS re:Post Agent does not have the option "--option-settings".
AI is giving an incorrect answer.
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-init.html

profile picture
EXPERT
answered a month ago
AWS
EXPERT
reviewed a month ago
-2

The issue you're experiencing is related to recent changes in AWS Elastic Beanstalk regarding the use of launch configurations. AWS is phasing out launch configurations and replacing them with launch templates. This transition means that creating new launch configurations is no longer possible in accounts and regions where Elastic Beanstalk environments don't already exist.

To resolve this issue and successfully deploy your Flask application on Elastic Beanstalk, you need to signal to Elastic Beanstalk to use launch templates instead of launch configurations. You can do this by setting at least one of the following options in your environment configuration:

  1. DisableIMDSv1
  2. RootVolumeType
  3. BlockDeviceMappings
  4. EnableSpot

When using the EB CLI, you can set these options by adding them to your command. For example:

eb init -p "64bit Amazon Linux 2023 v4.2.0 running Python 3.11" flask_app.py --option-settings Namespace=aws:autoscaling:launchconfiguration,OptionName=RootVolumeType,Value=gp2

If you're using CloudFormation, make sure to include one of these options in your template YAML file.

For the Flask application itself, ensure that your main application file is named application.py or that you've set the appropriate environment variables for Elastic Beanstalk to find your application entry point.

Also, make sure you have a requirements.txt file in your project directory listing all the necessary dependencies, including Flask.

By implementing these changes, you should be able to successfully deploy your Flask application on Elastic Beanstalk using the new launch template system.
Sources
Creating an Elastic Beanstalk without success | AWS re:Post
Setting up your Python development environment for Elastic Beanstalk - AWS Elastic Beanstalk
Deploying a Flask application to Elastic Beanstalk - AWS Elastic Beanstalk

profile picture
answered a month ago
  • The recommended code "eb init -p "64bit Amazon Linux 2023 v4.2.0 running Python 3.11" flask_app.py --option-settings Namespace=aws:autoscaling:launchconfiguration,OptionName=RootVolumeType,Value=gp2" generates the error "usage: eb init <application_name> [options ...] eb: error: unrecognized arguments: --option Namespace=aws:autoscaling:launchconfiguration,OptionName=RootVolumeType,Value=gp2".

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions