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

Emulate Development with lambda runtime interface emulator #19

Closed
jpaulolins opened this issue Feb 23, 2022 · 9 comments
Closed

Emulate Development with lambda runtime interface emulator #19

jpaulolins opened this issue Feb 23, 2022 · 9 comments

Comments

@jpaulolins
Copy link

Hi Guys,

I'm trying to emulate lambda in a local development environment using lambda runtime interface emulator[1]. When making the invocation to lambda runtime, the adapter attempts to find something on /var/task instead of passing the event request to my HTTP daemon running at the same container.

I tried to create /var/task/ into the container. After that, the adapter tried to find a bootstrap script without success.

I started my daemon and runtime emulator using bash script in the ENTRYPOINT container.

Any idea how I can use lambda runtime to test lambda in a development environment without deployment?

Regards.

[1] - https://github.com/aws/aws-lambda-runtime-interface-emulator

@bnusunny
Copy link
Contributor

bnusunny commented Feb 23, 2022 via email

@jpaulolins
Copy link
Author

jpaulolins commented Feb 23, 2022

Hi Harold,

Thank you so much for your response.

I understand that the adapter could work transparently, but for our pipeline, we would have the opportunity to do some tests on the local environment without making Deploy.

Today we use serverlessish, and we want to migrate to lambda-adapter because the code is well sustained and robust.

We want to maintain our pipeline from development to production with local tests through the emulator for simulating some events coming from APIGW or ALB, for example.

Below I'll share my docker file, entry-point file, and one main.go file with a simple http-server to understand how we are working today.

I'll be very grateful if you could suggest or advise how to use the emulator with lambda-adapter.

Tks.

Dockerfile

FROM golang:1.15 AS build
WORKDIR /teste
COPY . .
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o main

#FROM public.ecr.aws/c2t6n2x5/serverlessish:2 AS s

COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:0.2.0 /opt/extensions/lambda-adapter /opt/extensions/lambda-adapter

FROM alpine

RUN apk add --no-cache bash

ADD https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie /usr/bin/aws-lambda-rie

RUN chmod 755 /usr/bin/aws-lambda-rie
COPY ./entry.sh /
RUN chmod 755 /entry.sh

COPY --from=build /teste/main /main

ENV PORT=8081 

ENTRYPOINT ["/entry.sh"]

entry.sh

#!/bin/sh

# Start the first process
./main &
status=$?
if [ $status -ne 0 ]; then
  echo "Failed to start my server: $status"
  exit $status
fi


if [ -z "${AWS_LAMBDA_RUNTIME_API}" ]; then
  exec /usr/bin/aws-lambda-rie "$@"
else
  exec "$@"
fi 

maing.go

package main

import (
	"net/http"
	"net/http/httputil"
)

func main() {
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		dump, _ := httputil.DumpRequest(r, true)
		w.Write(append([]byte("this is what i received on port 8081:\n\n"), dump...))
	})

	http.HandleFunc("/ping", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte(`ok`))
	})

	err := http.ListenAndServe(":8081", nil)
	if err != nil {
		panic(err)
	}
}

@bnusunny
Copy link
Contributor

I see. Let me check how to do this.

@bnusunny
Copy link
Contributor

bnusunny commented Feb 23, 2022

The Dockerfile needs a bit of changes. Here is the updated version. But I discovered an issue awslabs/aws-lambda-rust-runtime#365 with aws rust runtime that breaks this emulation. This issue is fixed in aws rust runtime v0.5.0 release a few days ago. I will update the adapter to use that version and release a new version.

FROM golang:1.15 AS build
WORKDIR /teste
COPY . .
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o main

#FROM public.ecr.aws/c2t6n2x5/serverlessish:2 AS s

FROM alpine

RUN apk add --no-cache bash

COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:0.2.0 /opt/extensions/lambda-adapter /opt/extensions/lambda-adapter

ADD https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie /usr/bin/aws-lambda-rie

RUN chmod 755 /usr/bin/aws-lambda-rie
COPY ./entry.sh /
RUN chmod 755 /entry.sh

COPY --from=build /teste/main /main

ENV PORT=8081 READINESS_CHECK_PORT=8081 READINESS_CHECK_PATH=/ping

ENTRYPOINT ["/entry.sh"]

@jpaulolins
Copy link
Author

Great! Thank you very much! I'll do new test as soon you release adjustments.

@jpaulolins
Copy link
Author

Hi, did you have any idea when this improvement could be made?

is necessary only update lambda runtime package in cargo to use new package or is necessary make changes on code?

@bnusunny
Copy link
Contributor

It's not a simple update. Rust Runtime 0.5.0 has major breaking changes. I'm working on it. Hopefully to get the new release out soon.

@bnusunny
Copy link
Contributor

@jpaulolins I just released Adapter v0.3.0. Could you check if the new version solve this issue?

@bnusunny
Copy link
Contributor

@jpaulolins I will close this issue for now. If you still see issues, please reopen this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants