aws-amplify / amplify-hosting

AWS Amplify Hosting provides a Git-based workflow for deploying and hosting fullstack serverless web applications.
https://aws.amazon.com/amplify/hosting/
Apache License 2.0
456 stars 115 forks source link

Go is not installed on AmazonLinux 2 when trying to build a Go function #1084

Open maximelebastard opened 4 years ago

maximelebastard commented 4 years ago

Please describe which feature you have a question about?

I've created a GoLang function as documented. I can push it sucessfully from my computer. But when running amplifyPush from the console it seems it cannot build the function as go isn't available on the machine.

I have to install golang everytime which consumes time and money. It is akward that amplify console cannot natively build a go function.

Amplify version latest 4.29.3

20-09-25T07:22:20.865Z [INFO]: # Ensuring NPM package '@aws-amplify/cli' is version: 'latest'
2020-09-25T07:22:27.719Z [INFO]: # Patching NPM package '@aws-amplify/cli' from 1.12.0 to 4.29.3...

amplify.yml

version: 0.1
backend:
  phases:
    build:
      commands:
        - "# Execute Amplify CLI with the helper script"
        - amplifyPush --simple
frontend:
  phases: [...]

Build settings image

Console output for the backend step

2020-09-25T07:24:20.968Z [WARNING]: ✖ There was an error initializing your environment.
2020-09-25T07:24:20.970Z [INFO]: init failed
                                 Error: Missing required dependencies to package myapp
                                 at buildResource (/root/.nvm/versions/node/v10.16.0/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/lib/build-resources.js:25:15)
                                 at process._tickCallback (internal/process/next_tick.js:68:7)
2020-09-25T07:24:21.975Z [INFO]: Note: It is recommended to run this command from the root of your app directory
2020-09-25T07:24:25.676Z [WARNING]: - Initializing your environment: prhc
2020-09-25T07:24:25.697Z [WARNING]: (node:2066) ExperimentalWarning: The fs.promises API is experimental
2020-09-25T07:24:25.804Z [WARNING]: ✔ Initialized provider successfully.
2020-09-25T07:24:26.772Z [INFO]: go executable was not found in PATH, make sure it's available. It can be installed from https://golang.org/doc/install
2020-09-25T07:24:26.778Z [WARNING]: ✖ An error occurred when pushing the resources to the cloud
2020-09-25T07:24:26.778Z [WARNING]: ✖ There was an error initializing your environment.
2020-09-25T07:24:26.779Z [INFO]: init failed
2020-09-25T07:24:26.780Z [INFO]: Error: Missing required dependencies to package myapp
                                 at buildResource (/root/.nvm/versions/node/v10.16.0/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/lib/build-resources.js:25:15)
                                 at process._tickCallback (internal/process/next_tick.js:68:7)
2020-09-25T07:24:26.792Z [ERROR]: !!! Build failed
2020-09-25T07:24:26.865Z [ERROR]: !!! Non-Zero Exit Code detected
2020-09-25T07:24:26.865Z [INFO]: # Starting environment caching...
2020-09-25T07:24:26.865Z [INFO]: # Environment caching completed

Workaround

As a workaround, I install go by running this code. But that's not ideal.

backend:
  phases:
    preBuild:
      commands:
        - "# Install required dependencies"
        - "# jq is to create a proper parameters.json file"
        - amazon-linux-extras enable golang1.11
        - yum clean metadata
        - yum -y install golang jq
MauricioPaez commented 3 years ago

Hi there! I am experiencing the same issue, but the thing is that if I use the amazon linux extras golang topic (v 1.11) then I would need to downgrade the github.com/aws/aws-lambda-go v1.XX dependency to whatever version is compatible with 1.11. This seems kind of hacky and forces us to use a quite old version of Go. Any updates on this issue?

finaptic-am-gh commented 2 years ago

I am getting the same issue when trying to build using the CI/CD of amplify. Everything works fine locally, but won't build when commit to github->amplify.

error .."executable was not found in PATH, make sure it's available. It can be installed from https://golang.org/doc/install"

aniketsingh30 commented 2 years ago

I am also getting same issue when trying to build using the CI/CD of amplify. Everything works fine locally, but won't build when commit to aws codecommit. I am getting below error. go executable was not found in PATH, make sure it's available. It can be installed from https://golang.org/doc/install

tmli3b3rm4n commented 1 year ago

This is still an issue as of 10.6.1. When deploying from hook all is well till

                                # Starting phase: build
2023-01-11T15:35:22.890Z [INFO]: Amplify AppID found: d3np8nesr47z3c. Amplify App name is:
2023-01-11T15:35:22.937Z [INFO]: Backend environment develop found in Amplify Console app:
2023-01-11T15:35:27.205Z [WARNING]: - Fetching updates to backend environment: develop from the cloud.
2023-01-11T15:35:30.062Z [WARNING]: - Building resource api/
2023-01-11T15:35:31.190Z [INFO]: ⚠️  WARNING: your GraphQL API currently allows public create, read, update, and delete access to all models via an API Key. To configure PRODUCTION-READY authorization rules, review: https://docs.amplify.aws/cli/graphql/authorization-rules
2023-01-11T15:35:36.385Z [INFO]: ✅ GraphQL schema compiled successfully.
                                 Edit your schema at /codebuild/output/src618941925/src//amplify/backend/api//schema.graphql or place .graphql files in a directory at /codebuild/output/src618941925/src//amplify/backend/api//schema
2023-01-11T15:35:36.387Z [WARNING]: - Building resource auth/
2023-01-11T15:35:36.494Z [WARNING]: - Building resource auth/userPoolGroups
2023-01-11T15:35:36.784Z [WARNING]: - Building resource storage/
2023-01-11T15:35:36.821Z [WARNING]: ✔ Successfully pulled backend environment develop from the cloud.
2023-01-11T15:35:37.436Z [INFO]: ✅
2023-01-11T15:35:38.921Z [INFO]: Note: It is recommended to run this command from the root of your app directory
2023-01-11T15:35:40.362Z [WARNING]: - Initializing your environment: develop
2023-01-11T15:35:43.084Z [WARNING]: - Building resource api/
2023-01-11T15:35:44.346Z [INFO]: ⚠️  WARNING: your GraphQL API currently allows public create, read, update, and delete access to all models via an API Key. To configure PRODUCTION-READY authorization rules, review: https://docs.amplify.aws/cli/graphql/authorization-rules
2023-01-11T15:35:48.274Z [INFO]: ✅ GraphQL schema compiled successfully.
                                 Edit your schema at /codebuild/output/src618941925/src//amplify/backend/api//schema.graphql or place .graphql files in a directory at /codebuild/output/src618941925/src//amplify/backend/api/battlegi/schema
2023-01-11T15:35:48.276Z [WARNING]: - Building resource auth/
2023-01-11T15:35:48.357Z [WARNING]: - Building resource auth/userPoolGroups
2023-01-11T15:35:48.582Z [WARNING]: - Building resource storage/
2023-01-11T15:35:48.609Z [WARNING]: ✔ Initialized provider successfully.
2023-01-11T15:35:49.571Z [INFO]: go executable was not found in PATH, make sure it's available. It can be installed from https://golang.org/doc/install
2023-01-11T15:35:49.571Z [INFO]: go executable was not found in PATH, make sure it's available. It can be installed from https://golang.org/doc/install
2023-01-11T15:35:49.571Z [WARNING]: ✖ There was an error initializing your environment.
2023-01-11T15:35:49.572Z [INFO]: 🛑 Missing required dependencies to package
2023-01-11T15:35:49.572Z [INFO]: Learn more at: https://docs.amplify.aws/cli/project/troubleshooting/
2023-01-11T15:35:49.575Z [INFO]: 
2023-01-11T15:35:49.575Z [INFO]: Session Identifier: de2d11af-8e4e-4e88-8318-ca3bb5188ee0
2023-01-11T15:35:49.576Z [WARNING]: - Creating Zip
2023-01-11T15:35:49.625Z [INFO]: ✅ Report saved: /tmp//report-1673451349584.zip
2023-01-11T15:35:49.625Z [INFO]: 
2023-01-11T15:35:49.625Z [WARNING]: - Sending zip
2023-01-11T15:35:50.738Z [WARNING]: ✔ Done
2023-01-11T15:35:50.739Z [INFO]: Project Identifier: 333a9cfc635640cfaec2a93c7b0bbe98
2023-01-11T15:35:50.773Z [ERROR]: !!! Build failed
2023-01-11T15:35:50.773Z [ERROR]: !!! Non-Zero Exit Code detected
2023-01-11T15:35:50.774Z [INFO]: # Starting environment caching...
2023-01-11T15:35:50.774Z [INFO]: # Environment caching completed
Terminating logging...
ghost commented 1 year ago

Still no solution...

MtthwBrwng commented 1 year ago

@Mr-Raian I believe the solution is the workaround. If you could update your build settings by going to AWS Amplify -> App Settings -> Build Settings with something that looks similar. It should work, though note that your Go lambda functions cannot be greater than version 1.18 due to another bug preventing 1.18+ Go modules from compiling.

version: 1
backend:
  phases:
    preBuild:
      commands:
        - yum install -y golang
    build:
      commands:
        - '# Execute Amplify CLI with the helper script'
        - amplifyPush --simple
frontend:
  phases:
    preBuild:
      commands:
        - npm ci
    build:
      commands:
        - npm run build
  artifacts:
    baseDirectory: .next
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*
ghost commented 1 year ago

I wasn't aware of the existence of the preBuild phase, thanks to @MtthwBrwng for pointing it out. I got it working, and with go 1.20, this is how my amplify.yml looks

...
  phases:
    preBuild:
      commands:
        - wget --no-verbose https://go.dev/dl/go1.20.5.linux-amd64.tar.gz
        - rm -rf /usr/local/go 
        - tar -C /usr/local -xzf go1.20.5.linux-amd64.tar.gz
    build:
      commands:
        - '# Execute Amplify CLI with the helper script'
        - export PATH=$PATH:/usr/local/go/bin
        - go version
        - amplifyPush --simple
...