Skip to content

Incompatible with lambda environment simulation by SAM #271

@ichyo

Description

@ichyo

Using lambda_http from the master branch, Invoking sam local invoke or sam local start-api returns the following error.

$ sam local generate-event apigateway aws-proxy | sam local invoke HelloWorldFunction
Invoking not.used (provided)
Skip pulling image and use local one: amazon/aws-sam-cli-emulation-image-provided:rapid-1.13.2.

Mounting /home/***/dev/src/github.com/ichyo/aws-sam-rust-hello-world/.aws-sam/build/HelloWorldFunction as /var/task:ro,delegated inside runtime container
START RequestId: 14785d12-91f4-4630-a9ba-1d5bc88a0d86 Version: $LATEST
thread 'main' panicked at 'no entry found for key "lambda-runtime-invoked-function-arn"', /home/***/.cargo/git/checkouts/aws-lambda-rust-runtime-7c865cce90132439/13aa8f0/lambda/src/types.rs:131:35
stack backtrace:
   0: rust_begin_unwind
             at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/panicking.rs:483
   1: std::panicking::begin_panic_fmt
             at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/panicking.rs:437
   2: <lambda::types::Context as core::convert::TryFrom<http::header::map::HeaderMap>>::try_from
   3: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
   4: std::thread::local::LocalKey<T>::with
   5: tokio::runtime::enter::Enter::block_on
   6: tokio::runtime::thread_pool::ThreadPool::block_on
   7: tokio::runtime::context::enter
   8: hello::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
END RequestId: 14785d12-91f4-4630-a9ba-1d5bc88a0d86
REPORT RequestId: 14785d12-91f4-4630-a9ba-1d5bc88a0d86  Init Duration: 0.16 ms  Duration: 37.97 ms      Billed Duration: 100 ms Memory Size: 128 MB     Max Memory Used: 128 MB

It seems the lambda simulation provided by AWS SAM doesn't pass several response headers including Lambda-Runtime-Invoked-Function-Arn from /runtime/invocation/next.
dumping headers at this point shows

[/home/***/dev/src/github.com/awslabs/aws-lambda-rust-runtime/lambda/src/types.rs:122] &headers = {
    "content-type": "application/json",
    "lambda-runtime-aws-request-id": "8c65869a-e73e-42fa-9195-b6887b3597f8",
    "lambda-runtime-deadline-ms": "3214327342525",
    "date": "Sun, 06 Dec 2020 06:43:19 GMT",
    "content-length": "2",
}

Steps to reproduce

  1. Clone https://github.com/ichyo/aws-sam-rust-hello-world
  2. (Install SAM CLI and rustup target add x86_64-unknown-linux-musl if you haven't)
  3. sam build
  4. sam local generate-event apigateway aws-proxy | sam local invoke HelloWorldFunction (or sam local start-api and access http://127.0.0.1:3000/)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions