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

Update lambda runtime to allow undefined traceId #17449

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

LeviTrammell
Copy link

@LeviTrammell LeviTrammell commented Feb 19, 2025

What does this PR do?

The amazon trace id isn't necessarily guaranteed and isn't necessary to perform, so it should not fatally exit. Found the issue while running locally via amazon's ric. All this change does is removes the exit in the lambda runtime code.

  • Documentation or TypeScript types (it's okay to leave the rest blank in this case)
  • Code changes

How did you verify your code works?

I compiled the modified runtime.ts and placed it into an al2023 lambda container runtime :

ARG BUN_VERSION=1.2.2
ARG AL2023_VERSION=al2023.2025.01.24.10

FROM oven/bun:${BUN_VERSION}-debian as bun

ARG BUN_VERSION

RUN apt-get update && \
    apt-get install -y wget unzip && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

WORKDIR /tmp/

# Download lambda runtime layer from bun and compile it for use with al2023
RUN wget "https://github.com/oven-sh/bun/archive/refs/tags/bun-v${BUN_VERSION}.zip" && \
  unzip ./bun-v${BUN_VERSION}.zip && \
  mv ./bun-bun-v${BUN_VERSION}/packages/bun-lambda/runtime.ts . && \
  rm -rf ./bun-bun-v${BUN_VERSION} && \
  bun install aws4fetch && \
  bun build --compile runtime.ts --outfile bootstrap

COPY runtime.ts runtime.ts # Overrode here
RUN bun build --compile runtime.ts --outfile bootstrap

# Final image using AL2023 version
FROM public.ecr.aws/lambda/provided:${AL2023_VERSION}

# Copy the built bootstrap binary from the previous stage
COPY --from=bun /tmp/bootstrap ${LAMBDA_RUNTIME_DIR}
RUN chmod +x ${LAMBDA_RUNTIME_DIR}/bootstrap

I then created a simple typescript file for a handler :

export async function test(request: Request): Promise<Response> {
  const event = await request.json();
  console.log("Event", event);
  return new Response();
}

And set up a different Containerfile

ARG BUN_VERSION=1.2.2
FROM oven/bun:${BUN_VERSION}-debian as builder
WORKDIR /app

COPY index.ts index.ts

RUN bun build --target=bun index.ts --outfile index

FROM localhost/test # The local tag I used

COPY --from=builder /app/index ${LAMBDA_TASK_ROOT}

CMD [ "index.test" ]

I then ran it via podman with -p 9000:8080 and in a separate process ran :
curl -X POST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}'

This produced a result that did not result in an exit.

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

Successfully merging this pull request may close these issues.

2 participants