lifadev / archive_aws-lambda-go-shim

Author your AWS Lambda functions in Go, effectively.
https://github.com/eawsy/aws-lambda-go-shim
Apache License 2.0
789 stars 66 forks source link

Unable to import module 'lambda': plugin.Open: /var/task/lambda.so: invalid ELF header #13

Closed lbailly closed 7 years ago

lbailly commented 7 years ago

Hello,

I've updated both go package and docker image.

Below the content of my zip file: zipinfo -m lambda.zip Archive: lambda.zip 2860048 bytes 5 files -rw-r--r-- 2.0 unx 72464 b- 0% stor 9-Apr-17 17:09 lambda.so -rw-r--r-- 2.0 unx 928 b- 0% stor 8-Apr-17 00:18 lambda/init.pyc -rw-r--r-- 2.0 unx 1800 b- 0% stor 8-Apr-17 00:18 lambda/proxy.pyc -rw-r--r-- 2.0 unx 2782688 b- 0% stor 8-Apr-17 00:18 lambda/runtime.so -rw-r--r-- 3.0 unx 2126 tx 26% defN 6-Apr-17 16:30 config.json 5 files, 2860006 bytes uncompressed, 2859450 bytes compressed: 0.0%

My go file got a simple Handle method: func Handle(evt s3evt.Event, ctx runtime.Context) (interface{}, error) { ... }

But when I test my lambda, I got this error: START RequestId: 6b614679-1d47-11e7-acac-6309a8d92cc6 Version: $LATEST Unable to import module 'lambda': plugin.Open: /var/task/lambda.so: invalid ELF header

END RequestId: 6b614679-1d47-11e7-acac-6309a8d92cc6 REPORT RequestId: 6b614679-1d47-11e7-acac-6309a8d92cc6 Duration: 0.33 ms Billed Duration: 100 ms

Any idea ?

Thanks,

Ludovic

fsenart commented 7 years ago

Can you please provide the exact source code of the handler you've compiled.

lbailly commented 7 years ago

I reduce it to the minimum: func Handle(evt s3evt.Event, ctx runtime.Context) (interface{}, error) { return "OK", nil }

And still got the same error

Thanks,

Ludovic

fsenart commented 7 years ago

The exact source code allows me to see what you are trying to do "exactly":

docker run --rm -it eawsy/aws-lambda-go-shim version
# 2017-04-08
package main

import (
    "github.com/eawsy/aws-lambda-go-core/service/lambda/runtime"
    "github.com/eawsy/aws-lambda-go-event/service/lambda/runtime/event/s3evt"
)

func Handle(evt *s3evt.Event, ctx *runtime.Context) (interface{}, error) {
    return "OK", nil
}
wget -O Makefile https://git.io/vytH8
make

The above scenario works perfectly. I have "OK" after executing the lambda function.

Please double check you imports, docker image and your lambda configuration. The handler is handler.Handle.

lbailly commented 7 years ago

Hi,

I created a new directory and a new go file:

Same code than yours: cat handler.go

package lambdatest

import (
        "github.com/eawsy/aws-lambda-go-event/service/lambda/runtime/event/s3evt"
        "github.com/eawsy/aws-lambda-go-core/service/lambda/runtime"
)

func Handle(evt *s3evt.Event, ctx *runtime.Context) (interface{}, error) {
        return "OK", nil
}

same Makefile than yours: ludo:lambdatest Ludovic$ cat Makefile

#
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
#
# In jurisdictions that recognize copyright laws, the author or authors
# of this software dedicate any and all copyright interest in the
# software to the public domain. We make this dedication for the benefit
# of the public at large and to the detriment of our heirs and
# successors. We intend this dedication to be an overt act of
# relinquishment in perpetuity of all present and future rights to this
# software under copyright law.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
# For more information, please refer to <http://unlicense.org/>
#

HANDLER ?= handler
PACKAGE ?= $(HANDLER)
GOPATH  ?= $(HOME)/go

WORKDIR = $(CURDIR:$(GOPATH)%=/go%)
ifeq ($(WORKDIR),$(CURDIR))
        WORKDIR = /tmp
endif

docker:
        @docker run --rm                                                             \
          -e HANDLER=$(HANDLER)                                                      \
          -e PACKAGE=$(PACKAGE)                                                      \
          -v $(GOPATH):/go                                                           \
          -v $(CURDIR):/tmp                                                          \
          -w $(WORKDIR)                                                              \
          eawsy/aws-lambda-go-shim:latest make all

all: build pack perm

build:
        @go build -buildmode=plugin -ldflags='-w -s' -o $(HANDLER).so

pack:
        @pack $(HANDLER) $(HANDLER).so $(PACKAGE).zip

perm:
        @chown $(shell stat -c '%u:%g' .) $(HANDLER).so $(PACKAGE).zip

clean:
        @rm -rf $(HANDLER) $(HANDLER).so $(PACKAGE).zip

.PHONY: docker all build pack perm clean

same docker than yours:

ludo:lambdatest Ludovic$ docker run -it --rm -it eawsy/aws-lambda-go-shim version
2017-04-08

Lambda configuration:

Runtime: Python 2.7
Handler: handler.Handler

And still got the error:

START RequestId: b3ad78eb-1d57-11e7-b2c9-137e696e8d25 Version: $LATEST
Unable to import module 'handler': plugin.Open: /var/task/handler.so: invalid ELF header

END RequestId: b3ad78eb-1d57-11e7-b2c9-137e696e8d25
REPORT RequestId: b3ad78eb-1d57-11e7-b2c9-137e696e8d25  Duration: 0.27 ms   Billed Duration: 100 ms     Memory Size: 1536 MB    Max Memory Used: 9 MB

I'm using MacOS 10.11.6

Thanks for your help,

Ludovic

fsenart commented 7 years ago

@LBailly I see that you use a custom package called lambdatest. Currently Golang allows only main as package for plugins. Can you please verify by changing the package to main.

lbailly commented 7 years ago

@fsenart you got it !

I did that for other lambda but not for the latest one ...

I don't know if it's possible to add a warning or an error during the build process but that would avoid such dumb error.

Anyway thanks for your great support and so cool way to run GO code as AWS lambda function :-)

Ludovic

fsenart commented 7 years ago

Sorry, but at our level we can't add such warning. This is something that should be verified/enforced by the Go compiler. Feel free to follow such issues golang/go#19882 or golang/go#19023.

For the rest, you're welcome :wink: