Code Monkey home page Code Monkey logo

rust-transformer-docker-lambda's Introduction

Rust Transformer Lambda Function

This project contains a Rust AWS Lambda function that uses the rust-bert library for sequence classification. It utilizes the Lambda Runtime and Simple Logger to facilitate interaction with AWS Lambda and logging capabilities, respectively.

Project Overview

The Lambda function processes input text for sequence classification using a pre-trained BERT model from the rust-bert library. The input is expected to be a JSON object containing a text field.

Prerequisites

  • Rust and Cargo (latest stable version)
  • Docker
  • AWS CLI configured with appropriate permissions

Installation

Clone the repository and navigate into the project directory:

git clone [URL_TO_REPOSITORY]
cd [PROJECT_DIRECTORY]

Building the Project

Local Build

To build the project locally, run:

cargo build --release

Building with Docker

To build the Lambda function for deployment, use the provided Dockerfile:

docker build -t rust-transformer-lambda .

This Dockerfile is configured to build the Rust project in a containerized environment, ensuring compatibility with the AWS Lambda execution environment.

Deployment

Creating a Lambda Function

Create an AWS Lambda function using the AWS CLI:

aws lambda create-function --function-name rust-transformer-lambda \
--handler doesnt.matter \
--zip-file fileb://./target/lambda/release/bootstrap.zip \
--runtime provided.al2 \
--role arn:aws:iam::[ACCOUNT_ID]:role/[LAMBDA_EXEC_ROLE] \
--environment Variables={RUST_BACKTRACE=1} \
--memory-size 1024 \
--timeout 15

Updating the Lambda Function

To update the function code, build the Docker image and extract the binary to upload to AWS Lambda:

docker run --rm --entrypoint cat rust-transformer-lambda /home/rust/src/target/x86_64-unknown-linux-musl/release/bootstrap > bootstrap
zip lambda.zip bootstrap

aws lambda update-function-code --function-name rust-transformer-lambda \
--zip-file fileb://lambda.zip

Usage

To invoke the Lambda function, you can use the AWS CLI:

aws lambda invoke --function-name rust-transformer-lambda \
--payload '{"text":"example"}' response.json

Check response.json for the output.

Function Behavior

The Lambda function my_handler expects an event with a JSON object containing a "text" key. It uses this text for sequence classification and returns the model's predictions as JSON.

rust-transformer-docker-lambda's People

Contributors

sanjeev-one avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.