Skip to content

AWS App Runner not passing health check for a simple python application

0

I am trying app runner for the first time, but even a simple python application is not running. I followed the example in the startup guide https://docs.aws.amazon.com/apprunner/latest/dg/getting-started.html and followed it exactly, I tried a simple server.py that exposes a simple hello world on "server = make_server('0.0.0.0', port, app)" I ran it using source code setup, I ran it as an image from ECR. Nothing works. All the attempts fail at the same step -

01-01-2025 10:50:18 AM [AppRunner] Successfully pulled your application image from ECR.
01-01-2025 10:50:29 AM [AppRunner] Provisioning instances and deploying image for publicly accessible service.
01-01-2025 10:50:39 AM [AppRunner] Performing health check on protocol `HTTP` [Path: '/'], [Port: '8080'].
01-01-2025 10:56:47 AM [AppRunner] Health check failed on protocol `HTTP`[Path: '/'], [Port: '8080']. Check your configured port number. For more information, see the application logs.
01-01-2025 10:57:01 AM [AppRunner] Deployment with ID : ee8bc5fac41e4e00abd65a1475cee89e failed. Failure reason : Health check failed.

I tried to add EXPOSE port on docker file, setting up the port in the app runner configuration directly. Tried, 80, 8080, 8000 all different ports. The same docker image runs on my local, the only additional step is I add -p 8080:8080 to enable port forwarding when running docker run command. I tried adding python server.py in the start up command, as entry point in docker file, all give the same above error. Also I am not seeing any application logs on server start up.. these are the logs that I see in local when I run docker,

INFO:__main__:running main application and listening on port 8080
INFO:__main__:value of my port None
INFO:__main__:configuring apis
INFO:__main__:starting server

So,

  • does app runner really support python application ? is there any working example or sample I can refer ?
  • how can I see these application logs in app runner ?
  • what is missing and why my health check is failing with all different configurations ? TCP or http both fails
  • Is there any other way for me to troubleshoot this issue at all ?
asked a year ago1.3K views
4 Answers
1

Hello.

I was able to confirm that the application works properly by following the AppRunner tutorial and linking with the GitHub repository.
https://docs.aws.amazon.com/apprunner/latest/dg/getting-started.html
a

I also tried deploying from ECR using the Dockerfile in the GitHub repository you created, and confirmed that it could be deployed successfully.
https://github.com/Sathyvs/apprunner/tree/main

By the way, your Dockerfile installs python3.7, but in the case of Amazon Linux 2023, an error occurs because python3.7 is not included in the default repository.
So I modified it to install python3.11.

FROM public.ecr.aws/amazonlinux/amazonlinux:latest
RUN yum install python3.11 -y && curl -O https://bootstrap.pypa.io/get-pip.py && python3 get-pip.py && yum update -y
COPY . /app
WORKDIR /app
RUN pip3 install -r requirements.txt
CMD python3 server.py
EXPOSE 8080

By the way, where did you execute the "docker build" command?
Please note that using a container image created on M1 Mac as is will result in an error.
https://stackoverflow.com/questions/77822116/exec-sbin-tini-exec-format-error-running-meilisearch-on-aws-app-runner

Also, if you run your "server.py" as is, the following error occurred, so I modified the code.

SyntaxError: f-string: unmatched '('

An f-string error occurred, so I fixed it as follows.
Also, since we did not import "sys", we added an import.

from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response
import os, logging, sys # edit

logging.basicConfig(level=logging.INFO, stream=sys.stdout)
logger = logging.getLogger(__name__)

def hello_world(request):
    name = os.environ.get('NAME')
    if name == None or len(name) == 0:
        name = "world"
    message = "Hello, " + name + "!\n"
    logger.info("api called")
    return Response(message)

if __name__ == '__main__':
    port = int(os.environ.get("PORT"))
    logger.info(f"running main application and listening on port {os.environ.get('PORT')}") # edit
    logger.info(f"value of my port {os.environ.get('MY_PORT')}") # edit
    with Configurator() as config:
        logger.info("configuring apis")
        config.add_route('hello', '/')
        config.add_view(hello_world, route_name='hello')
        app = config.make_wsgi_app()
    server = make_server('0.0.0.0', 8080, app)
    logger.info("starting server")
    server.serve_forever()

Once the application has been successfully deployed, access the AppRunner URL directly and the screen will be displayed.

https://yyyyyyy.ap-northeast-1.awsapprunner.com/
EXPERT
answered a year ago
  • Thank you for checking this out. I have been messing around that dockerfile and tried different dockerfiles from different blogs... this is the one I used from ECR https://github.com/Sathyvs/apprunner/blob/main/Dockerfile

    I tried this get started guide as well, but I couldn't get that running as well... https://docs.aws.amazon.com/apprunner/latest/dg/getting-started.html

    I am on an older mac, which still has intel processor, not M1... however can you help me with these questions ?

    1. from the get started guide - there is a prerequisite about enabling IAM Identity Center - is this mandatory ? I have not done this.. and will check this enabled
    2. how did you find the issue in the python file ? were you able to see any application logs about the failure ? did you see any logs elsewhere other than cloudwatch log group for app runner ? am I missing any other log groups to check the application logs ?
    3. did you add any other configurations ? or update the port or health check from the default settings ? anything I should change in network configurations or other settings ?

    Sorry for the questions, I have tried more than 20-30 deployments with different setups, and trying to follow the exact same steps you followed so I can get this working. Thank you in advance.

    1. from the get started guide - there is a prerequisite about enabling IAM Identity Center - is this mandatory ? I have not done this.. and will check this enabled

    If you are just using AppRunner, you do not need to set up IAM Identity Center.

    1. how did you find the issue in the python file ? were you able to see any application logs about the failure ? did you see any logs elsewhere other than cloudwatch log group for app runner ? am I missing any other log groups to check the application logs ?

    I was able to check the log from the AppRunner screen. a

    1. did you add any other configurations ? or update the port or health check from the default settings ? anything I should change in network configurations or other settings ?

    No, I did not change any network settings or port numbers from the defaults. Only environment variables are added. a

    1. was this a ECR deployment that worked for you ?

    Yes, I was able to deploy it without any problems. I have confirmed that it can be deployed using ECR and Github integration. By the way, I've submitted a pull request to your Github repository, so please check it out. https://github.com/Sathyvs/apprunner/pull/1

  • Thank you, I will try again with the github source with the pull request you added, thank you... however I am not sure of the application logs that you see there.. I couldnt get to see that

  • Hi Riku, I tried again from the source code repo... with the PR merged... and used the configure all settings on the console... I am unable to update any screen shot in the comment box,

    used the below: Runtime: Python 3 Build Command: pip install -r requirements.txt start command: python server.py port: 8080

    but still failing health check

    01-01-2025 08:53:20 PM [AppRunner] Performing health check on protocol `TCP` [Port: '8080']. 01-01-2025 08:59:33 PM [AppRunner] Health check failed on protocol `TCP` [Port: '8080']. Check your configured port number. For more information, see the application logs. 01-01-2025 08:59:46 PM [AppRunner] Deployment with ID : 4db6391893e24a7da9f98c72437d262f failed. Failure reason : Health check failed.

  • Is it possible for you to share all the settings screens as screenshots? By the way, my settings when testing were as follows. a
    a
    a
    a

    Also, if you check "Create service" in Deployment logs, you can check the build logs, etc., so please check to see if any errors have occurred. a
    a

0
Accepted Answer

Basically the problem was something with the account. As all the attempts failed, I reached out to AWS customer support and they said they did something called account refresh and I can try afterwards, which actually did help and I was able to deploy the sample applications without any issue. Here is the explanation from aws customer support when I asked what account refresh meant

I would like to inform you that Based on your account usage, the quotas related to Apprunner service were restricted for your AWS Account due to which Apprunner instances were not getting launched in Apprunner service due to which the application wasn't getting started (consequently not generating application logs), as a result, the healthchecks were getting failed. Also, your account activity is constantly monitored within each Region, and these quotas are automatically increased based on your usage.

Thank you Riku_Kobayashi for your time and help in confirming and leading me towards the solution.

answered 10 months ago
0

Sorry, I can't post a comment due to an error, so I'm going to separate the thread.

Thats the other thing I have been telling about, I dont see any application logs at all.. I can also try in a different region to see if there is anything wrong with us-east-1
https://jumpshare.com/s/Sk6wo3USjbY20rTn2dpX. ---> this is what I see, the application logs section is just empty

Umm...Please try deploying in the Tokyo region just to be sure.
Please try both GitHub integration and deployment from ECR.
By the way, when trying to deploy from ECR, please use CloudShell to build the container image.
https://docs.aws.amazon.com/cloudshell/latest/userguide/welcome.html

EXPERT
answered a year ago
  • Okay, I will try the cloud shell for ECR, and give it a try

-1

AWS App Runner does indeed support Python applications, but it seems you're encountering some issues with your health check configuration. Let's address your concerns and provide some troubleshooting steps:

  1. Python Support: App Runner fully supports Python applications. It offers managed runtimes for building and running web applications based on Python.

  2. Application Logs: To view your application logs in App Runner, you can check the Logs tab on your service page in the AWS console. If you're not seeing the startup logs, it might indicate that your application isn't starting correctly.

  3. Health Check Issues: The health check is failing, which suggests that App Runner can't reach your application on the specified port and path. Here are some things to check:

    • Ensure your application is listening on 0.0.0.0 (all interfaces) and not just localhost.
    • Verify that the port your application is listening on matches the port specified in your App Runner configuration.
    • Make sure your application is actually starting and not crashing on startup.
  4. Troubleshooting Steps:

    • Double-check your App Runner configuration, especially the port and health check settings.
    • Review your Dockerfile to ensure it's correctly set up for App Runner.
    • Try using the TCP protocol for health checks instead of HTTP initially, as it's less likely to fail due to application-specific issues.
    • Examine the full application logs for any error messages or unexpected behavior.
  5. Configuration File: Consider using an App Runner configuration file (apprunner.yaml) to specify your build and run commands. For a Python application, it might look like this:

    version: 1.0
    runtime: python3
    build:
      commands:
        build:
          - pip install -r requirements.txt
    run:
      command: python server.py
    
  6. Port Configuration: Ensure that the port your application is listening on (in your code) matches the port specified in your App Runner configuration. App Runner typically expects your application to listen on port 8080 by default.

  7. Health Check Configuration: You can customize the health check settings in App Runner. Try adjusting the path, interval, or timeout settings to see if it resolves the issue.

If you've tried these steps and are still encountering issues, you may need to review your application code to ensure it's compatible with the App Runner environment. Also, consider starting with a very simple Python application that just returns a basic HTTP response to isolate whether the problem is with your application or the App Runner configuration.
Sources
Troubleshooting - AWS App Runner
Configuring health checks for your service - AWS App Runner
HealthCheckConfiguration - AWS App Runner
AWS App Runner Features – Fully managed container application service – Amazon Web Services
Using the Python platform - AWS App Runner

answered a year ago
  • All these are generic steps right ? I have tried them all. I created a separate new repo to just try this apprunner with a hello world and here is the code... does any of these look incorrect ? https://github.com/Sathyvs/apprunner/blob/main/server.py Also if you can see the server.py , it has the log lines I shared above from my local docker run. Now in app runner, I dont see them in application logs tab, event or deployment log groups, no where. And by that if I conclude the application has not started properly, what does the app runner log mean when it says application is deploy and its trying to perform health check ?

    The only thing I have not tried with this sample hello world application is using apprunner yaml and I will try that as well. (but the apprunner didnt do any good for the actual application I was trying to deploy.

    A couple of more questions, when I say public end point access and expose this application on port 8080, i should be able to see the page when I hit the apprunner url right ? I dont see the application running there too, so something is wrong, not sure if its the port forwarding or any vps settings that is not allowing my requests and the health check requests to go through or the application is failing to start

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.