Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amplify Function for Go: Runtime error #13658

Closed
2 tasks done
MarlonJD opened this issue Mar 18, 2024 · 8 comments
Closed
2 tasks done

Amplify Function for Go: Runtime error #13658

MarlonJD opened this issue Mar 18, 2024 · 8 comments
Assignees
Labels
bug Something isn't working functions Issues tied to the functions category p1

Comments

@MarlonJD
Copy link

MarlonJD commented Mar 18, 2024

How did you install the Amplify CLI?

curl

If applicable, what version of Node.js are you using?

v18.15.0

Amplify CLI Version

12.10.1

What operating system are you using?

MacOS 14.3.1 (23D60)

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

No Manuel changes made

Describe the bug

I create new function with amplify add function select Go then made amplify push.

Unexpected error occurred:

Resource handler returned message: "The runtime parameter of go1.x is no longer supported for creating or updating AWS Lambda functions. We recommend you use the new runtime (provided.al2023) while creating or updating functions.

I replaced all go1.x to provided.al2023.
These are on the
amplify/function/*function_name*/amplify.stateand
amplify/function/*function_name*/*function_name*-cloudformation-template.json

I could push successfully with amplify push but then lambda started to gave error,

INIT_REPORT Init Duration: 0.35 ms	Phase: init	Status: error	Error Type: Runtime.InvalidEntrypoint
INIT_REPORT Init Duration: 0.22 ms	Phase: invoke	Status: error	Error Type: Runtime.InvalidEntrypoint
RequestId: ee586a2a-2263-4723-b8d1-3556316dfef6 Error: Couldn't find valid bootstrap(s): [/var/task/bootstrap /opt/bootstrap]
Runtime.InvalidEntrypoint

Expected behavior

I solved this issue like this, build function with GOOS=linux GOARCH=amd64 go build -tags lambda.norpc -o bootstrap main.go this will compiled codes to named bootstrap old amplify push build made main for names so we have to change build go to this. If we can create bootstrap file for amd64 it will solve the error.

Reproduction steps

  1. Create new function with amplify add function
  2. Select Go
  3. Then push with amplify push

Project Identifier

No response

Log output

# Put your logs below this line


Additional information

No response

Before submitting, please confirm:

  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • I have removed any sensitive information from my code snippets and submission.
@hunterhug
Copy link

I change

amplify/function/function_name/amplify.state

{
  "pluginId": "amplify-go-function-runtime-provider",
  "functionRuntime": "provided.al2023",
  "useLegacyBuild": false,
  "defaultEditorFile": "src/main.go"
}

amplify/function/function_name/function_name-cloudformation-template.json

"Runtime": "provided.al2023",

then:

amplify push

push successfully.

but then lambda started get the same err.

@MarlonJD
Copy link
Author

I change

amplify/function/function_name/amplify.state

{
  "pluginId": "amplify-go-function-runtime-provider",
  "functionRuntime": "provided.al2023",
  "useLegacyBuild": false,
  "defaultEditorFile": "src/main.go"
}

amplify/function/function_name/function_name-cloudformation-template.json

"Runtime": "provided.al2023",

then:

amplify push

push successfully.

but then lambda started get the same err.

You have to build your code with named object bootstrap, amplify_cli already built with named main that's causing error. I made changed about it in PR,

you can run GOOS=linux GOARCH=amd64 go build -tags lambda.norpc -o bootstrap main.go on src folder, then zip bootstrap file upload to lambda, it should work.

@josefaidt
Copy link
Contributor

josefaidt commented Mar 19, 2024

Hey @MarlonJD 👋 thanks for raising this and taking the time to file a PR! I'll mark this as a bug to address the behavior of creating and distributing Go-based Functions 🙂

@josefaidt josefaidt added functions Issues tied to the functions category feature-request Request a new feature bug Something isn't working and removed pending-triage Issue is pending triage feature-request Request a new feature labels Mar 19, 2024
@RalphKemp
Copy link

Yep I've got about 10 go functions in my amplify project and I'm trying to update to 12.10.1 but stuck because of this. Don't want to manually do this process as I'm guessing any subsequent pushes via CLI will override changes, and trying the instruction mentioned (zipping bootstrap file) isn't currently working for me. Thanks @MarlonJD for submitting a PR, hopefully it's merged soon.

@MarlonJD
Copy link
Author

MarlonJD commented Mar 20, 2024

Yep I've got about 10 go functions in my amplify project and I'm trying to update to 12.10.1 but stuck because of this. Don't want to manually do this process as I'm guessing any subsequent pushes via CLI will override changes, and trying the instruction mentioned (zipping bootstrap file) isn't currently working for me. Thanks @MarlonJD for submitting a PR, hopefully it's merged soon.

I tried these steps and works, did you tried renamed main file and upload it ? These are the steps:

  1. build main.go file and create bootstrap compiled file with this command:
    GOOS=linux GOARCH=amd64 go build -tags lambda.norpc -o bootstrap main.go (macOS and GNU/Linux),
    $env:GOOS = "linux" $env:GOARCH = "amd64" $env:CGO_ENABLED = "0" go build -tags lambda.norpc -o bootstrap main.go ~\Go\Bin\build-lambda-zip.exe -o myFunction.zip bootstrap (on Windows Powershell)
  2. zip bootstrap file with this command: zip myFunction.zip bootstrap
  3. Upload to Lambda function. Your zip file should contains following only bootstrap file.
  4. Be sure your lambda's Runtime settings just like these: Runtime: Amazon Linux 2023, Handler:main and Architecture:x86_64
  5. Test your function, it won't work please paste your response of your test

@netmarkjp
Copy link

I'm looking forward to be fixed this issue 😄

This is my temporal workaround. Run below on background (or on another terminal) of amplify push .
I do this in amplify/backend/function/xxxfunc/src .

while true; do [[ -f ../bin/bootstrap ]] || GOOS=linux GOARCH=amd64 go build -tags lambda.norpc -o ../bin/bootstrap ; sleep 0.1 ; done

@MarlonJD
Copy link
Author

I closed my PR (#13659) the official team prefers to do it themselves, This issue has resolved after released version (v12.11.0) with merged PR (#13671 )

Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working functions Issues tied to the functions category p1
Projects
None yet
Development

No branches or pull requests

7 participants