amazon-app-runner-deploy icon indicating copy to clipboard operation
amazon-app-runner-deploy copied to clipboard

ERROR: Failed to build your application source code. Reason: Failed to execute 'pre_build' command.

Open anauecuri opened this issue 1 year ago • 3 comments

Hi everyone. I created a service in AWS apprunner and I am trying to deploy a python application using the python311 runtime. Whenever I tried to deploy using the code-based approach I got the error Failed to build your application source code. Reason: Failed to execute 'pre_build' command. When I build as a docker image pulling from ECR the deployment is successful.

This is my GitHub actions pipeline:

name: Deploy to App Runner

on:
  push:
    branches: [ccl-develop] # Trigger workflow on git push to ccl-develop branch
  workflow_dispatch: # Allow manual invocation of the workflow

jobs:
  deploy:
    runs-on: ubuntu-latest
    permissions:
      id-token: write
      contents: read

    steps:
      # OIDC Assume Role
      - name: Configure AWS Credentials
        id: configure-aws-credentials
        uses: aws-actions/configure-aws-credentials@v3
        with:
          role-to-assume: ${{ vars.OIDC_ROLE }}
          aws-region: us-east-1

      # Deploy to App Runner
      - name: Deploy to App Runner
        id: deploy-apprunner
        uses: awslabs/amazon-app-runner-deploy@main
        with:
          service: ${{ vars.SERVICE_NAME }}
          source-connection-arn: ${{ vars.SOURCE_CONNECTION_ARN }}
          repo: https://github.com/${{ github.repository }}
          branch: ${{ github.ref }}
          runtime: PYTHON_311
          build-command: "yum --version || echo 'yum not found' && yum search gdal || echo 'gdal not found'"
          start-command: uvicorn app.main:app --host 0.0.0.0 --port 8000
          port: 8000
          region: us-east-1
          cpu: 1
          memory: 2
          wait-for-service-stability-seconds: 600
          copy-env-vars: |
            SERVER_PORT
            CITIES_API_AIRTABLE_KEY
            AIRTABLE_BASE_ID
          copy-secret-env-vars: |
            SECRET_ENV
          instance-role-arn: ${{ vars.INSTANCE_ROLE_ARN }}
          tags: |
            { "env": "test" }
        env:
          SERVER_PORT: 8000
          SECRET_ENV: secret_env
          CITIES_API_AIRTABLE_KEY: ${{ secrets.CITIES_API_AIRTABLE_KEY }}
          AIRTABLE_BASE_ID: ${{ vars.AIRTABLE_BASE_ID }}

      # Log App Runner URL
      - name: Log App Runner URL
        run: | 
          echo "App Runner URL: ${{ steps.deploy-apprunner.outputs.service-url }}"

This is the apprunner log after its execution:

01-08-2025 11:00:29 AM [AppRunner] Deployment with ID : a49e3b46e6a44382959bb20d0cbb15d1 started. Triggering event : SERVICE_CREATE
01-08-2025 11:00:29 AM [AppRunner] Deployment Artifact: [Repo Type: Source], [Repository: MASKED], [Branch: ccl-develop], [SourceDirectory: /]
01-08-2025 11:01:20 AM [AppRunner] Creating pipeline for automatic deployments.
01-08-2025 11:01:20 AM [AppRunner] Successfully created pipeline for automatic deployments.
01-08-2025 11:01:21 AM [AppRunner] Pulling source code from GITHUB Repository ( MASKED).
01-08-2025 11:01:23 AM [AppRunner] Successfully pulled your application source code.
01-08-2025 11:01:24 AM [AppRunner] Successfully validate configuration file.
01-08-2025 11:01:25 AM [AppRunner] Starting source code build.
01-08-2025 11:02:09 AM [AppRunner] Failed to build your application source code. Reason: Failed to execute 'pre_build' command.
01-08-2025 11:02:13 AM [AppRunner] Deployment with ID : a49e3b46e6a44382959bb20d0cbb15d1 failed.

Does anyone know what might be the issue?

anauecuri avatar Jan 08 '25 14:01 anauecuri

Facing the same issue. @anauecuri any luck ?

abdullah-shiwani avatar Feb 11 '25 23:02 abdullah-shiwani

Facing the same issue. @abdullah-shiwani and @anauecuri any updates?

saswattulo avatar Sep 06 '25 17:09 saswattulo

Facing the same issue. @abdullah-shiwani and @anauecuri any updates?

I don’t exactly recall the specific fix. Here’s my repo for the same, it should be in a working state. You can try it out here: https://github.com/abdullah-shiwani/aws-apprunner

abdullah-shiwani avatar Sep 06 '25 18:09 abdullah-shiwani