Skip to content

In Amplify, we get Invalid argument when calling swapon /swapfile

0

Executing command: fallocate -l 8G /swapfile

2025-02-13T00:32:24.673Z [INFO]: # Executing command: chmod 600 /swapfile

2025-02-13T00:32:24.674Z [INFO]: # Executing command: mkswap /swapfile

2025-02-13T00:32:24.684Z [INFO]: Setting up swapspace version 1, size = 8 GiB (8589930496 bytes)

no label, UUID=8333583e-8140-4d4a-b416-669c9a8007df

2025-02-13T00:32:24.684Z [INFO]: # Executing command: swapon /swapfile

**2025-02-13T00:32:24.691Z [WARNING]: swapon: /swapfile: swapon failed:

2025-02-13T00:32:24.692Z [WARNING]: Invalid argument**

here is our amplify.yml and it was working fine 2 days ago (Feb 10) and today we got the Invalid argument on** swapon /swapfile** version: 1

frontend:

phases:

preBuild:

  commands:

    - fallocate -l 8G /swapfile

    - chmod 600 /swapfile

    - mkswap /swapfile

    - swapon /swapfile

    - swapon -s

    - npm ci

asked 2 years ago322 views

2 Answers
1

The issue you're experiencing with the "Invalid argument" error when calling swapon /swapfile in your Amplify build process is likely related to changes in the underlying build environment or system configurations.

Amplify's build process runs in a managed environment, and it's possible that recent updates or changes to this environment have affected the ability to create and enable swap space. Creating swap files and enabling them typically requires root privileges, which may not be available in the standard Amplify build environment.

It's important to note that manually modifying system-level configurations like swap space in the Amplify build process is not a recommended practice. Amplify is designed to manage resources and configurations automatically, and attempting to make such low-level changes can lead to unexpected issues.

Instead of trying to manage swap space manually, you should consider the following alternatives:

  1. Review your application's memory requirements and optimize your code to reduce memory usage if possible.

  2. If your build process requires more memory, you may need to upgrade to a larger instance type for your Amplify builds. This can typically be configured in your Amplify app settings.

  3. Contact AWS support to inquire about the recent changes that might have affected your build process and ask for guidance on how to proceed with your specific requirements.

  4. Remove the swap file creation commands from your amplify.yml file, as they are not typically necessary for most Amplify builds and may be causing issues.

Remember, it's crucial to work within the constraints and best practices of the Amplify environment. Avoid making direct system-level modifications unless explicitly supported by Amplify documentation or recommended by AWS support.
Sources
Troubleshooting - Flutter - AWS Amplify Documentation

answered 2 years ago

EXPERT

reviewed 2 years ago

0

we fixed the error by using this command instead dd if=/dev/zero of=/swapfile bs=1M count=8192

however, we got the same error ( swapon: /swapfile: swapon failed: Invalid argument) today. Anyone has any idea??

answered 2 years ago

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.