Open Bryson14 opened 1 year ago
Hey @Bryson14, 👋 thank you for reaching out. Wanted to confirm some information. To understand the push using Amplify CLI was successfully but the call from the API gateway endpoint provided a response with a error message? Could you check the lambda logs for any additional information on the run?
additionally, I was unable to reproduce the error message this when creating an API with a lambda function and adding the provided code. The lambda function received a validation error but did not experience the error provided. Could you let us know any additional information that would assist us in reproducing this issue?
@ykethan Can you confirm what local version of GLIBC you are using? I think the problem here is that when you push locally, Amazon Linux does not come with the latest GLIBC version. As such we need to compile with CGO_ENABLED=0
. How are we able to add this flag to the amplify build
stage?
Hey @benjamindoe, thank you for the information. For the reproduction I created the Lambda function in my project on MacOS and pushed it to git. Then connected to Amplify hosting which should contain the default linux 2 instance to reproduce. The local go.mod file contained the version 1.19
in the hosting build settings, i then installed go with the following settings
the backend build did not experience an issue with GLIBC.
additionally, tested using a Amazon linux 2 instance
ldd --version
ldd (GNU libc) 2.26
created a go lambda function and did a push but did not experience a issue.
Hi @ykethan
So the issue is NOT to do with CI CD. The reason your local amplify push
worked is because Macos doesn't use GLIBC. The AL2 instance worked because I assume AL1 instances also have GLIBC_2.26. Later GLIBC versions do not work. We need a way of setting CGO_ENABLED=0
during the build stage locally with amplify CLI.
See this issue for lambda go:
Hey @benjamindoe, thank you for the information. noticed Amplify does set this as env variable on windows: https://github.com/aws-amplify/amplify-cli/blob/947b23f1be982d4823df413cbe5595131f101ce7/packages/amplify-go-function-runtime-provider/src/runtime.ts#LL97C1-L97C1
Marking this as bug for further investigation.
Hey @ykethan,
Thanks for the link to the source, really useful. I can see there's no way of actually setting CGO_ENABLED=0
however as it's using execa
which does extend process.env
meaning we could set CGO_ENABLED=0
globally by running export CGO_ENABLED=0
before running amplify push
. Alternatively we could put it in .zshrc/.bashrc
.
Although it does detected Windows as you stated, this doesn't work for WSL (which is what @Bryson14 is said to be running) as this is a Ubuntu box under the hood and process.platform
reports linux
. Personally, I am on Manjaro so my process.plaform
reports linux
as well.
Hey @benjamindoe, as you have pointed using a subsystem for linux such as WSL would report the system as linux. The Amplify CLI team has been made aware into the behaviour and will be discussed as part of our triage meetings.
Do let us if setting the CGO_ENABLED=0
globally mitigates the issue as well as I am currently investigating to see using Amazon Linux 2023 would reproduce this behaviour as this does not contain the amazon-extras with golang and then try exporting the CGO_ENABLED=0
. If utilizing this does mitigate the issue, we could try utilizing pre-push hook to set the export.
Hi @ykethan, I can confirm export CGO_ENABLED=0
does work. I've added it to a pre-build hook (pre-build-function.sh
) until an official solution is found.
# amplify/hooks/pre-build-function.sh
export CGO_ENABLED=0
that does appear to work. As stated above, I'm running ubuntu on WSL 2. Running export CGO_ENABLED=0
before running amplify push
did fix the issue.
I was having this issue intermittently for some reason during the build process (not on amplify push
) and added the following to the amplify.yml, which fixed the problem
backend:
phases:
preBuild:
commands:
- export CGO_ENABLED=0
Hi @ykethan, I can confirm
export CGO_ENABLED=0
does work. I've added it to a pre-build hook (pre-build-function.sh
) until an official solution is found.# amplify/hooks/pre-build-function.sh export CGO_ENABLED=0
that works for me! :)
How did you install the Amplify CLI?
npm
If applicable, what version of Node.js are you using?
v18.14.0
Amplify CLI Version
11.1.1
What operating system are you using?
Windows WSL 2
Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.
No
Describe the bug
I created a go function, then ran
amplify push
to compile and create the lambda function. Everything went smoothly until the function was executed by API Gateway and failed with the error:Expected behavior
The API gateway should return a 200 but instead returns 502 since the lambda function fails.
Reproduction steps
create a api and lambda function with
amplify add api
. Create an api with/search
path. create a new go function then replace the contents with 👍amplify push
This will cause the error.
However, I also have CICD setup with a github repo with the following build settings:
when I run
git push
, and the CICD build starts, the error caused byamplify push
from my local machine is fixedProject Identifier
b2a8e45f990b09821ed3bcbcf1838fbc
Log output
Additional information
No response
Before submitting, please confirm: