{"id":33312592,"url":"https://github.com/aws/aws-lambda-rust-runtime","last_synced_at":"2026-01-06T21:22:35.399Z","repository":{"id":37334084,"uuid":"156752158","full_name":"aws/aws-lambda-rust-runtime","owner":"aws","description":"A Rust runtime for AWS Lambda","archived":false,"fork":false,"pushed_at":"2025-12-19T21:56:36.000Z","size":10194,"stargazers_count":3559,"open_issues_count":32,"forks_count":380,"subscribers_count":41,"default_branch":"main","last_synced_at":"2025-12-20T16:04:48.590Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aws.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":"NOTICE","maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2018-11-08T18:36:53.000Z","updated_at":"2025-12-19T21:46:28.000Z","dependencies_parsed_at":"2023-02-11T23:30:39.083Z","dependency_job_id":"c2d7d720-1324-4efe-8d8a-f501c1498ccc","html_url":"https://github.com/aws/aws-lambda-rust-runtime","commit_stats":{"total_commits":257,"total_committers":81,"mean_commits":"3.1728395061728394","dds":0.7937743190661479,"last_synced_commit":"3fce312eb77f7ec1722e1c4605b11f770e286ed9"},"previous_names":["aws/aws-lambda-rust-runtime","awslabs/aws-lambda-rust-runtime"],"tags_count":71,"template":false,"template_full_name":null,"purl":"pkg:github/aws/aws-lambda-rust-runtime","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aws%2Faws-lambda-rust-runtime","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aws%2Faws-lambda-rust-runtime/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aws%2Faws-lambda-rust-runtime/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aws%2Faws-lambda-rust-runtime/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aws","download_url":"https://codeload.github.com/aws/aws-lambda-rust-runtime/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aws%2Faws-lambda-rust-runtime/sbom","scorecard":{"id":219573,"data":{"date":"2025-08-11","repo":{"name":"github.com/awslabs/aws-lambda-rust-runtime","commit":"685e81c5d4d0c11f3f816c8f540b196c27173210"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":5.9,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/build-events.yml:1","Warn: no topLevel permission defined: .github/workflows/build-extension.yml:1","Warn: no topLevel permission defined: .github/workflows/build-integration-test.yml:1","Warn: no topLevel permission defined: .github/workflows/build-runtime.yml:1","Warn: no topLevel permission defined: .github/workflows/check-docs.yml:1","Warn: no topLevel permission defined: .github/workflows/check-examples.yml:1","Warn: no topLevel permission defined: .github/workflows/closed-issue-message.yml:1","Warn: no topLevel permission defined: .github/workflows/format.yml:1","Info: topLevel 'contents' permission set to 'read': .github/workflows/run-integration-test.yml:5","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Code-Review","score":9,"reason":"Found 26/28 approved changesets -- score normalized to 9","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Maintained","score":10,"reason":"26 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build-events.yml:43: update your workflow using https://app.stepsecurity.io/secureworkflow/awslabs/aws-lambda-rust-runtime/build-events.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/build-events.yml:45: update your workflow using https://app.stepsecurity.io/secureworkflow/awslabs/aws-lambda-rust-runtime/build-events.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/build-events.yml:51: update your workflow using https://app.stepsecurity.io/secureworkflow/awslabs/aws-lambda-rust-runtime/build-events.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build-events.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/awslabs/aws-lambda-rust-runtime/build-events.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build-events.yml:33: update your workflow using https://app.stepsecurity.io/secureworkflow/awslabs/aws-lambda-rust-runtime/build-events.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/build-events.yml:34: update your workflow using https://app.stepsecurity.io/secureworkflow/awslabs/aws-lambda-rust-runtime/build-events.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/build-events.yml:35: update your workflow using https://app.stepsecurity.io/secureworkflow/awslabs/aws-lambda-rust-runtime/build-events.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build-extension.yml:46: update your workflow using https://app.stepsecurity.io/secureworkflow/awslabs/aws-lambda-rust-runtime/build-extension.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/build-extension.yml:48: update your workflow using https://app.stepsecurity.io/secureworkflow/awslabs/aws-lambda-rust-runtime/build-extension.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/build-extension.yml:54: update your workflow using https://app.stepsecurity.io/secureworkflow/awslabs/aws-lambda-rust-runtime/build-extension.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build-extension.yml:30: update your workflow using https://app.stepsecurity.io/secureworkflow/awslabs/aws-lambda-rust-runtime/build-extension.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build-integration-test.yml:31: update your workflow using https://app.stepsecurity.io/secureworkflow/awslabs/aws-lambda-rust-runtime/build-integration-test.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build-runtime.yml:29: update your workflow using https://app.stepsecurity.io/secureworkflow/awslabs/aws-lambda-rust-runtime/build-runtime.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build-runtime.yml:50: update your workflow using https://app.stepsecurity.io/secureworkflow/awslabs/aws-lambda-rust-runtime/build-runtime.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/build-runtime.yml:52: update your workflow using https://app.stepsecurity.io/secureworkflow/awslabs/aws-lambda-rust-runtime/build-runtime.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/build-runtime.yml:58: update your workflow using https://app.stepsecurity.io/secureworkflow/awslabs/aws-lambda-rust-runtime/build-runtime.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/check-docs.yml:31: update your workflow using https://app.stepsecurity.io/secureworkflow/awslabs/aws-lambda-rust-runtime/check-docs.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/check-docs.yml:32: update your workflow using https://app.stepsecurity.io/secureworkflow/awslabs/aws-lambda-rust-runtime/check-docs.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/check-examples.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/awslabs/aws-lambda-rust-runtime/check-examples.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/check-examples.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/awslabs/aws-lambda-rust-runtime/check-examples.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/check-examples.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/awslabs/aws-lambda-rust-runtime/check-examples.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/closed-issue-message.yml:9: update your workflow using https://app.stepsecurity.io/secureworkflow/awslabs/aws-lambda-rust-runtime/closed-issue-message.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/format.yml:10: update your workflow using https://app.stepsecurity.io/secureworkflow/awslabs/aws-lambda-rust-runtime/format.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/format.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/awslabs/aws-lambda-rust-runtime/format.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/format.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/awslabs/aws-lambda-rust-runtime/format.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/format.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/awslabs/aws-lambda-rust-runtime/format.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/format.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/awslabs/aws-lambda-rust-runtime/format.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/format.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/awslabs/aws-lambda-rust-runtime/format.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/run-integration-test.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/awslabs/aws-lambda-rust-runtime/run-integration-test.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/run-integration-test.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/awslabs/aws-lambda-rust-runtime/run-integration-test.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/run-integration-test.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/awslabs/aws-lambda-rust-runtime/run-integration-test.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/run-integration-test.yml:29: update your workflow using https://app.stepsecurity.io/secureworkflow/awslabs/aws-lambda-rust-runtime/run-integration-test.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/run-integration-test.yml:31: update your workflow using https://app.stepsecurity.io/secureworkflow/awslabs/aws-lambda-rust-runtime/run-integration-test.yml/main?enable=pin","Info:   0 out of  13 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of  20 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Security-Policy","score":10,"reason":"security policy file detected","details":["Info: security policy file detected: github.com/awslabs/.github/SECURITY.md:1","Info: Found linked content: github.com/awslabs/.github/SECURITY.md:1","Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/awslabs/.github/SECURITY.md:1","Info: Found text in security policy: github.com/awslabs/.github/SECURITY.md:1"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 30 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":5,"reason":"5 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-65fc-cr5f-v7r2","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-17T02:13:12.428Z","repository_id":37334084,"created_at":"2025-08-17T02:13:12.429Z","updated_at":"2025-08-17T02:13:12.429Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28000524,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-24T02:00:07.193Z","response_time":83,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-11-19T06:00:48.395Z","updated_at":"2025-12-30T03:03:06.542Z","avatar_url":"https://github.com/aws.png","language":"Rust","funding_links":[],"categories":["Rust","Libraries"],"sub_categories":["Cloud"],"readme":"# Rust Runtime for AWS Lambda\n\n[![Build Status](https://github.com/aws/aws-lambda-rust-runtime/actions/workflows/check-examples.yml/badge.svg)](https://github.com/aws/aws-lambda-rust-runtime/actions)\n\nThis package makes it easy to run AWS Lambda Functions written in Rust. This workspace includes multiple crates:\n\n- [![Docs](https://docs.rs/lambda_runtime/badge.svg)](https://docs.rs/lambda_runtime) **`lambda-runtime`** is a library that provides a Lambda runtime for applications written in Rust.\n- [![Docs](https://docs.rs/lambda_http/badge.svg)](https://docs.rs/lambda_http) **`lambda-http`** is a library that makes it easy to write API Gateway proxy event focused Lambda functions in Rust.\n- [![Docs](https://docs.rs/lambda-extension/badge.svg)](https://docs.rs/lambda-extension) **`lambda-extension`** is a library that makes it easy to write Lambda Runtime Extensions in Rust.\n- [![Docs](https://docs.rs/aws_lambda_events/badge.svg)](https://docs.rs/aws_lambda_events) **`lambda-events`** is a library with strongly-typed Lambda event structs in Rust.\n- [![Docs](https://docs.rs/lambda_runtime_api_client/badge.svg)](https://docs.rs/lambda_runtime_api_client) **`lambda-runtime-api-client`** is a shared library between the lambda runtime and lambda extension libraries that includes a common API client to talk with the AWS Lambda Runtime API.\n\n## Getting started\n\nThe easiest way to start writing Lambda functions with Rust is by using [Cargo Lambda](https://www.cargo-lambda.info/), a related project. Cargo Lambda is a Cargo plugin, or subcommand, that provides several commands to help you in your journey with Rust on AWS Lambda.\n\nThe preferred way to install Cargo Lambda is by using a package manager.\n\n1- Use Homebrew on [MacOS](https://brew.sh/):\n\n```bash\nbrew tap cargo-lambda/cargo-lambda\nbrew install cargo-lambda\n```\n\n2- Use [Scoop](https://scoop.sh/) on Windows:\n\n```bash\nscoop bucket add cargo-lambda https://github.com/cargo-lambda/scoop-cargo-lambda\nscoop install cargo-lambda/cargo-lambda\n```\n\nOr PiP on any system with Python 3 installed:\n\n```bash\npip3 install cargo-lambda\n```\nAlternatively, you can install the pip package as an executable using [uv](https://docs.astral.sh/uv/)\n\n```bash\nuv tool install cargo-lambda\n```\n\nSee other installation options in [the Cargo Lambda documentation](https://www.cargo-lambda.info/guide/installation.html).\n\n## Your first function\n\nTo create your first function, run Cargo Lambda with the [subcommand `new`](https://www.cargo-lambda.info/commands/new.html). This command will generate a Rust package with the initial source code for your function:\n\n```bash\ncargo lambda new YOUR_FUNCTION_NAME\n```\n\n### Example function\n\nIf you'd like to manually create your first function, the code below shows you a simple function that receives an event with a `firstName` field and returns a message to the caller.\n\n```rust,no_run\nuse lambda_runtime::{service_fn, LambdaEvent, Error};\nuse serde_json::{json, Value};\n\n#[tokio::main]\nasync fn main() -\u003e Result\u003c(), Error\u003e {\n    let func = service_fn(func);\n    lambda_runtime::run(func).await?;\n    Ok(())\n}\n\nasync fn func(event: LambdaEvent\u003cValue\u003e) -\u003e Result\u003cValue, Error\u003e {\n    let (event, _context) = event.into_parts();\n    let first_name = event[\"firstName\"].as_str().unwrap_or(\"world\");\n\n    Ok(json!({ \"message\": format!(\"Hello, {}!\", first_name) }))\n}\n```\n\n## Understanding Lambda errors\n\nwhen a function invocation fails, AWS Lambda expects you to return an object that can be serialized into JSON structure with the error information. This structure is represented in the following example:\n\n```json\n{\n  \"error_type\": \"the type of error raised\",\n  \"error_message\": \"a string description of the error\"\n}\n```\n\nThe Rust Runtime for Lambda uses a struct called `Diagnostic` to represent function errors internally. The runtime implements the conversion of several general error types, like `std::error::Error`, into `Diagnostic`. For these general implementations, the `error_type` is the name of the value type returned by your function. For example, if your function returns `lambda_runtime::Error`, the `error_type` will be something like `alloc::boxed::Box\u003cdyn core::error::Error + core::marker::Send + core::marker::Sync\u003e`, which is not very descriptive.\n\n### Implement your own Diagnostic\n\nTo get more descriptive `error_type` fields, you can implement `From` for your error type. That gives you full control on what the `error_type` is:\n\n```rust\nuse lambda_runtime::{Diagnostic, Error, LambdaEvent};\n\n#[derive(Debug)]\nstruct ErrorResponse(\u0026'static str);\n\nimpl From\u003cErrorResponse\u003e for Diagnostic {\n    fn from(error: ErrorResponse) -\u003e Diagnostic {\n        Diagnostic {\n            error_type: \"MyErrorType\".into(),\n            error_message: error.0.to_string(),\n        }\n    }\n}\n\nasync fn handler(_event: LambdaEvent\u003c()\u003e) -\u003e Result\u003c(), ErrorResponse\u003e {\n  Err(ErrorResponse(\"this is an error response\"))\n}\n```\n\nWe recommend you to use the [thiserror crate](https://crates.io/crates/thiserror) to declare your errors. You can see an example on how to integrate `thiserror` with the Runtime's diagnostics in our [example repository](https://github.com/aws/aws-lambda-rust-runtime/tree/main/examples/basic-error-thiserror)\n\n### Anyhow, Eyre, and Miette\n\nPopular error crates like Anyhow, Eyre, and Miette provide their own error types that encapsulate other errors. There is no direct transformation of those errors into `Diagnostic`, but we provide feature flags for each one of those crates to help you integrate them with your Lambda functions.\n\nIf you enable the features `anyhow`, `eyre`, or `miette` in the `lambda_runtime` dependency of your package. The error types provided by those crates can have blanket transformations into `Diagnostic`. These features expose an `From\u003cT\u003e for Diagnostic` implementation that transforms those error types into a `Diagnostic`. This is an example that transforms an `anyhow::Error` into a `Diagnostic`:\n\n```rust\nuse lambda_runtime::{Diagnostic, LambdaEvent};\n\nasync fn handler(_event: LambdaEvent\u003cRequest\u003e) -\u003e Result\u003c(), Diagnostic\u003e {\n  Err(anyhow::anyhow!(\"this is an error\").into())\n}\n```\n\nYou can see more examples on how to use these error crates in our [example repository](https://github.com/aws/aws-lambda-rust-runtime/tree/main/examples/basic-error-error-crates-integration). \n\n### Graceful shutdown\n\n`lambda_runtime` offers a helper to simplify configuring graceful shutdown signal handling, `spawn_graceful_shutdown_handler()`. This requires the `graceful-shutdown` feature flag and only supports Unix systems.\n\nYou can use it by passing a `FnOnce` closure that returns an async block. That async block will be executed\nwhen the function receives a `SIGTERM` or `SIGKILL`.\n\nNote that this helper is opinionated in a number of ways. Most notably:\n1. It spawns a task to drive your signal handlers\n2. It registers a 'no-op' extension in order to enable graceful shutdown signals\n3. It panics on unrecoverable errors\n\nIf you prefer to fine-tune the behavior, refer to the implementation of `spawn_graceful_shutdown_handler()` as a starting point for your own.\n\nFor more information on graceful shutdown handling in AWS Lambda, see: [aws-samples/graceful-shutdown-with-aws-lambda](https://github.com/aws-samples/graceful-shutdown-with-aws-lambda).\n\nComplete example (cleaning up a non-blocking tracing writer):\n\n```rust,no_run\nuse lambda_runtime::{service_fn, LambdaEvent, Error};\nuse serde_json::{json, Value};\n\n#[tokio::main]\nasync fn main() -\u003e Result\u003c(), Error\u003e {\n    let func = service_fn(func);\n\n    let (writer, log_guard) = tracing_appender::non_blocking(std::io::stdout());\n    lambda_runtime::tracing::init_default_subscriber_with_writer(writer);\n\n    let shutdown_hook = || async move {\n      std::mem::drop(log_guard);\n    };\n    lambda_runtime::spawn_graceful_shutdown_handler(shutdown_hook).await;\n\n    lambda_runtime::run(func).await?;\n    Ok(())\n}\n\nasync fn func(event: LambdaEvent\u003cValue\u003e) -\u003e Result\u003cValue, Error\u003e {\n    let (event, _context) = event.into_parts();\n    let first_name = event[\"firstName\"].as_str().unwrap_or(\"world\");\n\n    Ok(json!({ \"message\": format!(\"Hello, {}!\", first_name) }))\n}\n```\n\n## Building and deploying your Lambda functions\n\nIf you already have Cargo Lambda installed in your machine, run the next command to build your function:\n\n```bash\ncargo lambda build --release\n```\n\nThere are other ways of building your function: manually with the AWS CLI, with [AWS SAM](https://github.com/aws/aws-sam-cli), and with the [Serverless framework](https://serverless.com/framework/).\n\n### 1. Cross-compiling your Lambda functions\n\nBy default, Cargo Lambda builds your functions to run on x86_64 architectures. If you'd like to use a different architecture, use the options described below.\n\n#### 1.1. Build your Lambda functions\n\n__Amazon Linux 2023__\n\nWe recommend you to use the Amazon Linux 2023  (such as `provided.al2023`) because it includes a newer version of GLIBC, which many Rust programs depend on. To build your Lambda functions for Amazon Linux 2023 runtimes, run:\n\n```bash\ncargo lambda build --release --arm64\n```\n\n### 2. Deploying the binary to AWS Lambda\n\nFor [a custom runtime](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html), AWS Lambda looks for an executable called `bootstrap` in the deployment package zip. Rename the generated executable to `bootstrap` and add it to a zip archive.\n\nYou can find the `bootstrap` binary for your function under the `target/lambda` directory.\n\n#### 2.1. Deploying with Cargo Lambda\n\nOnce you've built your code with one of the options described earlier, use the `deploy` subcommand to upload your function to AWS:\n\n```bash\ncargo lambda deploy\n```\n\n\u003e **Warning**\n\u003e Make sure to replace the execution role with an existing role in your account!\n\nThis command will create a Lambda function with the same name of your rust package. You can change the name\nof the function by adding the argument at the end of the command:\n\n```bash\ncargo lambda deploy my-first-lambda-function\n```\n\n\u003e **Note**\n\u003e See other deployment options in [the Cargo Lambda documentation](https://www.cargo-lambda.info/commands/deploy.html).\n\nYou can test the function with the [invoke subcommand](https://www.cargo-lambda.info/commands/invoke.html):\n\n```bash\ncargo lambda invoke --remote \\\n  --data-ascii '{\"command\": \"hi\"}' \\\n  --output-format json \\\n  my-first-lambda-function\n```\n\n\u003e **Note**\n\u003e CLI commands in the examples use Linux/MacOS syntax. For different shells like Windows CMD or PowerShell, modify syntax when using nested quotation marks like `'{\"command\": \"hi\"}'`. Escaping with a backslash may be necessary. See [AWS CLI Reference](https://docs.amazonaws.cn/en_us/cli/latest/userguide/cli-usage-parameters-quoting-strings.html#cli-usage-parameters-quoting-strings-containing) for more information.\n\n#### 2.2. Deploying with the AWS CLI\n\nYou can also use the AWS CLI to deploy your Rust functions. First, you will need to create a ZIP archive of your  function. Cargo Lambda can do that for you automatically when it builds your binary if you add the `output-format` flag:\n\n```bash\ncargo lambda build --release --arm64 --output-format zip\n```\n\nYou can find the resulting zip file in `target/lambda/YOUR_PACKAGE/bootstrap.zip`. Use that file path to deploy your function with the [AWS CLI](https://aws.amazon.com/cli/):\n\n```bash\n$ aws lambda create-function --function-name rustTest \\\n  --handler bootstrap \\\n  --zip-file fileb://./target/lambda/basic/bootstrap.zip \\\n  --runtime provided.al2023 \\ # Change this to provided.al2 if you would like to use Amazon Linux 2\n  --role arn:aws:iam::XXXXXXXXXXXXX:role/your_lambda_execution_role \\\n  --environment Variables={RUST_BACKTRACE=1} \\\n  --tracing-config Mode=Active\n```\n\n\u003e **Warning**\n\u003e Make sure to replace the execution role with an existing role in your account!\n\nYou can now test the function using the AWS CLI or the AWS Lambda console\n\n```bash\n$ aws lambda invoke\n  --cli-binary-format raw-in-base64-out \\\n  --function-name rustTest \\\n  --payload '{\"command\": \"Say Hi!\"}' \\\n  output.json\n$ cat output.json  # Prints: {\"msg\": \"Command Say Hi! executed.\"}\n```\n\n\u003e **Note** \n\u003e `--cli-binary-format raw-in-base64-out` is a required argument when using the AWS CLI version 2. [More Information](https://docs.aws.amazon.com/cli/latest/userguide/cliv2-migration.html#cliv2-migration-binaryparam)\n\n#### 2.3. AWS Serverless Application Model (SAM)\n\nYou can use Lambda functions built in Rust with the [AWS Serverless Application Model (SAM)](https://aws.amazon.com/serverless/sam/). To do so, you will need to install the [AWS SAM CLI](https://github.com/aws/aws-sam-cli), which will help you package and deploy your Lambda functions in your AWS account.\n\nYou will need to create a `template.yaml` file containing your desired infrastructure in YAML. Here is an example with a single Lambda function:\n\n```yaml\nAWSTemplateFormatVersion: '2010-09-09'\nTransform: AWS::Serverless-2016-10-31\n\nResources:\n  HelloWorldFunction:\n    Type: AWS::Serverless::Function\n    Properties:\n      MemorySize: 128\n      Architectures: [\"arm64\"]\n      Handler: bootstrap\n      Runtime: provided.al2023\n      Timeout: 5\n      CodeUri: target/lambda/basic/\n\nOutputs:\n  FunctionName:\n    Value: !Ref HelloWorldFunction\n    Description: Name of the Lambda function\n```\n\nYou can then deploy your Lambda function using the AWS SAM CLI:\n\n```bash\nsam deploy --guided\n```\n\nAt the end, `sam` will output the actual Lambda function name. You can use this name to invoke your function:\n\n```bash\n$ aws lambda invoke\n  --cli-binary-format raw-in-base64-out \\\n  --function-name HelloWorldFunction-XXXXXXXX \\ # Replace with the actual function name\n  --payload '{\"command\": \"Say Hi!\"}' \\\n  output.json\n$ cat output.json  # Prints: {\"msg\": \"Command Say Hi! executed.\"}\n```\n\n## Local development and testing\n\n### Testing your code with unit and integration tests\n\nAWS Lambda events are plain structures deserialized from JSON objects.\nIf your function handler uses the standard runtime, you can use `serde` to deserialize\nyour text fixtures into the structures, and call your handler directly:\n\n```rust,no_run\n#[test]\nfn test_my_lambda_handler() {\n  let input = serde_json::from_str(\"{\\\"command\\\": \\\"Say Hi!\\\"}\").expect(\"failed to parse event\");\n  let context = lambda_runtime::Context::default();\n\n  let event = lambda_runtime::LambdaEvent::new(input, context);\n\n  my_lambda_handler(event).await.expect(\"failed to handle event\");\n}\n```\n\nIf you're using `lambda_http` to receive HTTP events, you can also create `http_lambda::Request`\nstructures from plain text fixtures:\n\n```rust,no_run\n#[test]\nfn test_my_lambda_handler() {\n  let input = include_str!(\"apigw_proxy_request.json\");\n\n  let request = lambda_http::request::from_str(input)\n    .expect(\"failed to create request\");\n\n  let response = my_lambda_handler(request).await.expect(\"failed to handle request\");\n}\n```\n\n### Local dev server with Cargo Lambda\n\n[Cargo Lambda](https://www.cargo-lambda.info) provides a local server that emulates the AWS Lambda control plane. This server works on Windows, Linux, and MacOS. In the root of your Lambda project. You can run the following subcommand to compile your function(s) and start the server.\n\n```bash\ncargo lambda watch\n```\n\nNow you can use the `cargo lambda invoke` to send requests to your function. For example:\n\n```bash\ncargo lambda invoke \u003clambda-function-name\u003e --data-ascii '{ \"command\": \"hi\" }'\n```\n\nRunning the command on a HTTP function (Function URL, API Gateway, etc) will require you to use the appropriate scheme. You can find examples of these schemes [here](https://github.com/aws/aws-lambda-rust-runtime/tree/main/lambda-http/tests/data). Otherwise, you will be presented with the following error.\n\n```rust,no_run\nError: serde_json::error::Error\n\n  × data did not match any variant of untagged enum LambdaRequest\n```\n\nAn simpler alternative is to cURL the following endpoint based on the address and port you defined. For example:\n\n```bash\ncurl -v -X POST \\\n  'http://127.0.0.1:9000/lambda-url/\u003clambda-function-name\u003e/' \\\n  -H 'content-type: application/json' \\\n  -d '{ \"command\": \"hi\" }'\n```\n\n\u003e **Warning** \n\u003e Do not remove the `content-type` header. It is necessary to instruct the function how to deserialize the request body.\n\nYou can read more about how [cargo lambda watch](https://www.cargo-lambda.info/commands/watch.html) and [cargo lambda invoke](https://www.cargo-lambda.info/commands/invoke.html) work on the project's [documentation page](https://www.cargo-lambda.info).\n\n### Local testing with Runtime Interface Emulator (RIE)\n\nFor testing with the official AWS Lambda Runtime Interface Emulator, use the provided RIE testing infrastructure:\n\n```bash\nmake test-rie\n```\n\nBy default, this uses the `basic-lambda` example. To test a different example:\n\n```bash\nmake test-rie EXAMPLE=basic-sqs\nmake test-rie EXAMPLE=http-basic-lambda\n```\n\nThis command will:\n1. Build a Docker image with Rust toolchain and RIE\n2. Compile the specified example inside the Linux container\n3. Start the RIE container on port 9000\n4. Display the appropriate curl command for testing\n\nDifferent examples expect different payload formats. Check the example's source code in `examples/EXAMPLE_NAME/src/main.rs`\n\nThis provides automated testing with Docker and RIE, ensuring your Lambda functions work in a Linux environment identical to AWS Lambda.\n\n### Lambda Debug Proxy\n\nLambdas can be run and debugged locally using a special [Lambda debug proxy](https://github.com/rimutaka/lambda-debug-proxy) (a non-AWS repo maintained by @rimutaka), which is a Lambda function that forwards incoming requests to one AWS SQS queue and reads responses from another queue. A local proxy running on your development computer reads the queue, calls your Lambda locally and sends back the response. This approach allows debugging of Lambda functions locally while being part of your AWS workflow. The Lambda handler code does not need to be modified between the local and AWS versions.\n\n## Tracing and Logging\n\nThe Rust Runtime for Lambda integrates with the [Tracing](https://tracing.rs) libraries to provide tracing and logging.\n\nBy default, the runtime emits `tracing` events that you can collect via `tracing-subscriber`. It also enabled a feature called `tracing` that exposes a default subscriber with sensible options to send logging information to AWS CloudWatch. Follow the next example that shows how to enable the default subscriber:\n\n```rust\nuse lambda_runtime::{run, service_fn, tracing, Error};\n\n#[tokio::main]\nasync fn main() -\u003e Result\u003c(), Error\u003e {\n    tracing::init_default_subscriber();\n    run(service_fn(|event| tracing::info!(?event))).await\n}\n```\n\nThe subscriber uses `RUST_LOG` environment variable to determine the log level for your function. It also uses [Lambda's advanced logging controls](https://aws.amazon.com/blogs/compute/introducing-advanced-logging-controls-for-aws-lambda-functions/), if configured.\n\nBy default, the log level to emit events is `INFO`. Log at `TRACE` level for more detail, including a dump of the raw payload.\n\n## AWS event objects\n\nThis project includes Lambda event struct definitions, [`aws_lambda_events`](https://crates.io/crates/aws_lambda_events). This crate can be leveraged to provide strongly-typed Lambda event structs. You can create your own custom event objects and their corresponding structs as well.\n\n### Custom event objects\n\nTo serialize and deserialize events and responses, we suggest using the [`serde`](https://github.com/serde-rs/serde) library. To receive custom events, annotate your structure with Serde's macros:\n\n```rust,no_run\nuse serde::{Serialize, Deserialize};\nuse serde_json::json;\nuse std::error::Error;\n\n#[derive(Serialize, Deserialize)]\npub struct NewIceCreamEvent {\n  pub flavors: Vec\u003cString\u003e,\n}\n\n#[derive(Serialize, Deserialize)]\npub struct NewIceCreamResponse {\n  pub flavors_added_count: usize,\n}\n\nfn main() -\u003e Result\u003c(), Box\u003cError\u003e\u003e {\n    let flavors = json!({\n      \"flavors\": [\n        \"Nocciola\",\n        \"抹茶\",\n        \"आम\"\n      ]\n    });\n\n    let event: NewIceCreamEvent = serde_json::from_value(flavors)?;\n    let response = NewIceCreamResponse {\n        flavors_added_count: event.flavors.len(),\n    };\n    serde_json::to_string(\u0026response)?;\n\n    Ok(())\n}\n```\n\n## Supported Rust Versions (MSRV)\n\nThe AWS Lambda Rust Runtime requires a minimum of Rust 1.82.0, and is not guaranteed to build on compiler versions earlier than that.\n\n## Security\n\nSee [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.\n\n## License\n\nThis project is licensed under the Apache-2.0 License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faws%2Faws-lambda-rust-runtime","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faws%2Faws-lambda-rust-runtime","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faws%2Faws-lambda-rust-runtime/lists"}