Skip to content

AppRunner deployment fails with `/usr/bin/cd: line 2: cd: too many arguments`

0

Here is my apprunner.yaml:

version: 1.0
runtime: nodejs22
build:
  commands:
    build:
      - npm install && npm run build
      - cd showcase && npm install && npm run build
run:
  command: "cd showcase && npm run serve"
  network:
    port: 8080

Here are the scripts from package.json:

  "scripts": {
    "dev": "vite",
    "build": "tsc -b && vite build",
    "lint": "eslint .",
    "preview": "vite preview",
    "serve": "vite preview --host --port 8080"
  },

Here are the last few lines of my build log:

	
2025-09-23T01:24:54.755Z [PostBuild] Successfully built 92b991e45f4d
2025-09-23T01:25:17.492Z [AppRunner] Successfully built your application source code.
2025-09-23T01:27:02.783Z [AppRunner] Failed to deploy your application source code.

And here is the entire deployment log:

2025-09-23T01:26:18.269Z /usr/bin/cd: line 2: cd: too many arguments

I cannot find anything else to help me diagnose what's wrong. Can anyone offer any suggestions?

Thanks

asked a year ago187 views

3 Answers
0
Accepted Answer

I found a somewhat amusing workaround that outputs a run.sh file during the build, then executes that in the run phase.

version: 1.0
runtime: nodejs22
build:
  commands:
    pre-build:
      - echo -e '#!/bin/sh\\ncd showcase\\nnpm run serve' > ./run.sh
      - chmod +x ./run.sh
    build:
      - npm install && npm run build
      - cd showcase && npm install && npm run build
run:
  command: ./run.sh
  network:
    port: 8080

This is, of course, bonkers. But I've tried all the obvious alternatives, and they all result in some kind of parsing/shell issue.

answered a year ago

0

Hello.

How about creating a shell script file with the build and execution commands as shown below?

version: 1.0
runtime: nodejs22
build:
  commands:
    build:
      - build.sh
run:
  command: entrypoint.sh
  network:
    port: 8080

build.sh

#!/usr/bin/env bash

npm install
npm run build
cd showcase
npm install
npm run build

entrypoint.sh

#!/usr/bin/env bash

cd showcase
npm run serve
EXPERT

answered a year ago

-2

The error you're encountering with AWS App Runner is related to the run command in your apprunner.yaml file. The issue is with how the cd command is being interpreted.

In your configuration, you have:

run:
command: "cd showcase && npm run serve"

The error message /usr/bin/cd: line 2: cd: too many arguments suggests that the cd command is not being processed correctly. This is likely because App Runner is trying to execute the entire string as a single command rather than as separate commands.

To fix this issue, try modifying your apprunner.yaml file to use one of these approaches:

Option 1: Use the working directory setting:

run:
command: "npm run serve"
working-directory: "showcase"

Option 2: Use a shell to execute the commands:

run:
command: "sh -c 'cd showcase && npm run serve'"

Option 3: Use the full path to the directory:

run:
command: "cd /app/showcase && npm run serve"

The apprunner.yaml configuration file is used to instruct App Runner on how to build and start your service, and sometimes the way commands are interpreted can cause issues like this. Making one of these changes should resolve the deployment failure.
Sources
Setting App Runner service options using a configuration file - AWS App Runner
Troubleshooting - AWS App Runner

answered a year ago

  • There is no such thing as a "working-directory" in the "run" section. https://docs.aws.amazon.com/apprunner/latest/dg/config-file-ref.html#config-file-ref.run

  • None of these suggestions helped.

    Option 1: Hallucination. working-directory is not supported under run: Failed to build your application source code. Reason: Failed to validate configuration file. Check the file's content. Details: fail to read bullet config file: Unrecognized field "working-directory"

    Option 2: invalid syntax leads to: showcase: -c: line 1: unexpected EOF while looking for matching ''. So I tried with escaped double quotes but that leads to showcase: -c: line 1: unexpected EOF while looking for matching "'

    Option 3: doesn't make any sense. If running cd in the command is the problem then this also clearly won't work

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.