dherault / serverless-offline

Emulate AWS λ and API Gateway locally when developing your Serverless project
MIT License
5.16k stars 794 forks source link

feat: update docker images and add support for different architectures #1755

Closed BenjaminBergerM closed 2 months ago

BenjaminBergerM commented 5 months ago

Description

Since https://github.com/lambci/docker-lambda lambda docker images are deprecated, serverless offline using docker was not working with many languages. So I changes de docker image source from lambci/docker-lambda to public.ecr.aws/lambda/{runtime}.

Also added support to diffrent architectures, now works with all runtimes and architectures that aws has a public image con ecr.

Also change docker configuration so it could be run with the new images.

Follow https://github.com/serverless/serverless/issues/10797#issuecomment-1544922990 this instructions.

Motivation and Context

I have many services running with Serverless and Golang, i use this plugin to run them locally and since 29 of January i want able to run muy code.

Related issues: #1754 #1750

How Has This Been Tested?

I run all test, and also imported the package to deferent serverless applications i have using docker.

Screenshots (if appropriate):

BenjaminBergerM commented 5 months ago

It sorta works using java11 runtime after changing this import line, but still not 100% on first run.

On first run, calling some REST API, the runtime gives an error ✖ Failed to fetch from http://localhost:50257/2018-06-01/ping with Not Found

But when I request the same REST API, it works (and all subsequently requests)

On this aws docker images i could find ping endpoint, so i remove ping function.

manfioLP commented 5 months ago

apparently this would solve a lot of issues

1754

1750

other issues mentioned on serverless repos too

LeoNero commented 5 months ago

Tested with a project using golang, provided.al2, and an M1 Mac and it seems to work well. No errors found so far.

ncostamagna commented 5 months ago

I am testing in Go and it works!

dOrgJelli commented 5 months ago

Tested this using python3.10 functions on linux and works great, thank you for this fix!

BenjaminBergerM commented 5 months ago

@dnalborczyk i just fix the lint error, can run again the actions workflow?

dnalborczyk commented 5 months ago

thank you for the PR @BenjaminBergerM !

I just de-activated the docker tests because of the failures. I suppose we should activate those again. could you do this in this PR? https://github.com/dherault/serverless-offline/commit/0e883f75627d6d88297e0faf0e98b47e2e4a2499

BenjaminBergerM commented 4 months ago

thank you for the PR @BenjaminBergerM !

I just de-activated the docker tests because of the failures. I suppose we should activate those again. could you do this in this PR? 0e883f7

Hi @dnalborczyk, thanks you for the review!

I rebase the branch and activated the tests you de-activate previously.

Waiting for the final review!

LuidmilaDezhkina commented 4 months ago

Hello everyone! I want to express my appreciation for your PR contributions. While deploying the code to the cloud seems to be successful, I've encountered an error locally: '/lambda-entrypoint.sh: line 14: /var/runtime/bootstrap: No such file or directory.' Interestingly, I can see that the zip file was unpacked, and for each invocation, I can locate it at a path similar to '../.serverless-offline/...../fe9fdf79-23ca-49d6-9d1c-162876a7960b/code/bootstrap.' Any insights on what might be causing this issue?

DorianMazur commented 2 months ago

There are some issues on ubuntu:

× 19 Apr 2024 19:54:44,280 [INFO] (rapid) INIT START(type: on-demand, phase: init)
  19 Apr 2024 19:54:44,280 [INFO] (rapid) The extension's directory "/opt/extensions" does not exist, assuming no extensions to be loaded.
  19 Apr 2024 19:54:44,280 [INFO] (rapid) Starting runtime without AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN , Expected?: false
Warning:  Apr 2024 19:54:44,281 [WARNING] (rapid) First fatal error stored in appctx: Runtime.InvalidEntrypoint
  19 Apr 2024 19:54:44,281 [INFO] (rapid) INIT RTDONE(status: error)
  19 Apr 2024 19:54:44,281 [INFO] (rapid) INIT REPORT(durationMs: 0.416000)
Error: 19 Apr 2024 19:54:44,281 [ERROR] (rapid) Init failed error=fork/exec /var/runtime/bootstrap: no such file or directory InvokeID=
Warning:  Apr 2024 19:54:44,281 [WARNING] (rapid) Shutdown initiated: spindown
  19 Apr 2024 19:54:44,281 [INFO] (rapid) Waiting for runtime domain processes termination
  19 Apr 2024 19:54:44,281 [INFO] (rapid) INIT START(type: on-demand, phase: invoke)
  19 Apr 2024 19:54:44,281 [INFO] (rapid) The extension's directory "/opt/extensions" does not exist, assuming no extensions to be loaded.
  19 Apr 2024 19:54:44,281 [INFO] (rapid) Starting runtime without AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN , Expected?: false
Warning:  Apr 2024 19:54:44,281 [WARNING] (rapid) First fatal error stored in appctx: Runtime.InvalidEntrypoint
  19 Apr 2024 19:54:44,281 [INFO] (rapid) INIT RTDONE(status: error)
  19 Apr 2024 19:54:44,281 [INFO] (rapid) INIT REPORT(durationMs: 0.298000)
  19 Apr 2024 19:54:44,281 [INFO] (rapid) INVOKE START(requestId: cd2d4f30-d5ad-4f38-bd05-bc9574b90d13)
Error: 19 Apr 2024 19:54:44,281 [ERROR] (rapid) Invoke failed error=fork/exec /var/runtime/bootstrap: no such file or directory InvokeID=cd2d4f30-d5ad-4f38-bd05-bc9574b90d13
Error: 19 Apr 2024 19:54:44,281 [ERROR] (rapid) Invoke DONE failed: Runtime.InvalidEntrypoint
Warning:  Apr 2024 19:54:44,281 [WARNING] (rapid) Reset initiated: ReleaseFail
  19 Apr 2024 19:54:44,281 [INFO] (rapid) Waiting for runtime domain processes termination

Maybe this issue is related, it's hard to say (I need to dig deeper) -> https://github.com/aws/aws-lambda-base-images/issues/26

There is also another alternative to lambci/lambda images (but they are not official docker images) -> https://github.com/mLupine/docker-lambda Someone created a PR with mLupine/docker-lambda images for a serverless repo -> https://github.com/serverless/serverless/pull/12348

DorianMazur commented 2 months ago

Okay, it should be fixed now. I will wait for tests and probably merge it. Thank you @BenjaminBergerM