Application Version Issue with Elastic Beanstalk restart-app-server action on Lambda

0

I am attempting to deploy a Flask (python3.8) application via AWS Elastic Beanstalk (EB). I was able to successfully deploy the application on a --single EC2 instance configuration in the public subnet on my VPC. I have a backend data pipeline that generates a serve.json file, which contains metadata about the S3 prefix to use for serving up data on the frontend. serve.json is updated and overwritten everyday, and I have an S3 trigger on the prefix containing serve.json that is to call a Lambda function which will restart the WSGI web-app server managing the Flask app, which is running on the EC2 instances created by EB. After each restart, my Flask app reads in data from .parquet files on the S3 prefix specified in the updated serve.json and serves a RESTful app.

Problem: When I restart-app-server via boto3/Lambda, although the application restarts, my EB environment (my-eb-environment) gets degraded (Health: Red) with cause = Incorrect application version found on all instances. Expected version n/a..

CLI Route: The CLI action works as expected. The effect of the action can be seen in the eb health console below:

$    aws elasticbeanstalk restart-app-server --environment-name "my-eb-environment"

Enter image description here

Lambda Route: An S3 trigger calls the Lambda function below when serve.json is uploaded to the trigger prefix.

Lambda function:

from datetime import datetime
import boto3

def lambda_handler(event, context):
    """
    restart the WSGI App Server running on EC2 instance(s) associated with an Elastic Beanstalk Environment
    """
    print(str(datetime.now()))
    EB_ENV_NAME = 'my-eb-environment'
    try:
        eb_client = boto3.client('elasticbeanstalk')
        eb_response = eb_client.restart_app_server(EnvironmentName=EB_ENV_NAME)
        print('SUCCESS! RESTARTED WEB SERVER FOR EnvironmentName {}'.format(EB_ENV_NAME))
        response = 200
        return (eb_response, response)
    except Exception as e:
        print('BAD REQUEST: COULD NOT RESTART WEB SERVER\nMESSAGE: {}'.format(e))
        response = 400
        return (None, response)

I can describe-log-streams and get-log-events to view logs of the Lambda function. It is clear that the app has refreshed: Enter image description here

But, eb health reveals that the environment is now degraded: Enter image description here

Running the CLI command on my terminal again refreshes the application server and makes the environment healthy:

$    aws elasticbeanstalk restart-app-server --environment-name "my-eb-environment"

Enter image description here

  1. How do I resolve the application version issue on the Lambda route to perform restart-app-server with this pipeline, so I can automate app refreshing with each uploaded serve.json?
  2. Any alternative solutions for automated EB application refreshing based on S3 triggers are also appreciated. I do not wish to reboot the EC2 instances, because I would like to avoid the downtime if I can.
No Answers

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