A fully serverless, cloud-native pipeline that enables you to enrich prompts with contextual data stored in S3 and send them to an LLM (Large Language Model) for inference.
Built using AWS Lambda, IAM, S3, and pluggable LLM providers such as SageMaker, Together.ai, Gemini, or Mistral.
Created with ❤️ by Om Sharma
LambdaLLMOps Pipeline is a production-ready, serverless framework designed to integrate dynamic context retrieval from AWS S3 with cloud-hosted LLMs. The project enables developers to securely orchestrate prompt generation and inference using modern AI APIs or AWS-native models. It is highly extensible and supports cost-effective migration from SageMaker to third-party LLM providers.
- Serverless & Scalable: Built on AWS Lambda for automatic scaling and zero server management.
- Contextual LLM Prompts: Dynamically fetches JSON-based context from S3 to augment prompts.
- Pluggable LLM Backend: Easily switch from SageMaker to Together.ai, Gemini, Hugging Face, or Mistral by editing a single handler.
- Security Best Practices: Implements least-privilege IAM roles, environment variable-based secrets, and CloudWatch observability.
- Infrastructure as Code: Deployed using AWS SAM/CloudFormation for repeatable, version-controlled provisioning.
- Developer-Friendly: Modular structure with example context, test files, and deployment script.
LambdaLLMOps-Pipeline/
.
├── backend
│ ├── app
│ │ ├── context_loader.js # Loads context JSON from S3
│ │ ├── handler.js # Lambda entrypoint – orchestrates flow, input/output
│ │ ├── llm_client.js # Handles LLM API calls (Together, OpenRouter, etc.)
│ │ ├── prompt_builder.js # Composes user input/context as prompt for LLM
│ │ └── utils.js # Shared helpers (Secrets fetch, logging, error utils)
│ └── test_event.json # Example Lambda event for dev/test
├── context
│ └── demo_context.json # Example context file (upload to S3 bucket)
├── frontend
│ └── frontend
│ ├── ... # Next.js app files (React pages, public, package.json, etc)
├── infra
│ └── template.yaml # AWS SAM/CloudFormation - infra as code
├── LLMOps.png # Architecture diagram or project logo
├── Readme.md # Full docs, setup, tips, API docs, etc
├── scripts
│ ├── cleanup.sh # Deletes/removes stack/resources
│ └── deploy.sh # Wrapper for building & deploying SAM stack
└── tests
└── test_handler.js # Node Lambda unit/integration test
- A request is triggered (via API Gateway or manually) to Lambda.
- Lambda reads the context file (JSON) from the specified S3 bucket.
- Combines base prompt with context data to form a complete prompt.
- Sends the prompt to an LLM endpoint (SageMaker or any API provider).
- Returns the inference response to the caller.
- Logs all operations and errors in CloudWatch.
- AWS Account (with required IAM permissions)
- AWS CLI (configured using
aws configure) - AWS SAM CLI
- Python 3.11+
git clone https://github.com/i-OmSharma/LambdaLLMOps-Pipeline.git
cd LambdaLLMOps-Pipelinesam build
sam deploy --guided-
Answer prompts to configure stack, region, and IAM roles.
-
This creates:
- Lambda function
- IAM role with minimal permissions
- S3 bucket for context files
aws s3 cp context/sample-context.json s3://<your-bucket-name>/sample-context.jsonUpdate LLM_ENDPOINT, API_KEY, and other variables for your chosen LLM provider (e.g., Together.ai, Gemini, etc.).
aws lambda invoke \
--function-name <LambdaFunctionName> \
--payload '{"prompt": "Summarize this context.", "context_file": "sample-context.json"}' output.jsonYou can easily replace SageMaker with any LLM provider:
-
Edit
src/lambda_function/app.py- Replace SageMaker invoke code with a POST request to your LLM API (Together.ai, Gemini, Mistral, etc.).
-
Update environment variables:
LLM_ENDPOINT,API_KEY,MODEL_NAME, etc. -
No need to redeploy infrastructure—just modify code and redeploy Lambda.
- IAM Roles: Lambda granted only
s3:GetObject,logs:*, and (optionally)sagemaker:InvokeEndpoint. - Secrets Management: API keys and sensitive config stored as environment variables.
- CloudWatch: Logs for all actions and exceptions for debugging and monitoring.
src/lambda_function/app.py— main Python handler (modular, editable)context/sample-context.json— demo context filetemplate.yaml— annotated CloudFormation templatetests/test_app.py— basic unit test sample
- Add logic to
app.pyfor advanced prompt engineering or multi-LLM routing. - Extend
template.yamlfor VPC access, layers, or API Gateway triggers. - Add
.envsupport for local development/testing. - Use
scripts/deploy.shto automate CI/CD deployment.
Pull requests and issue reports are welcome!
Licensed under the MIT License.
For help or questions, feel free to open an issue. For enterprise-grade deployments or LLM tuning, please consult the official documentation of your chosen LLM provider and AWS best practices.
Build AI pipelines that scale securely and cost-efficiently—on your cloud terms.
⭐ Star this repo if you found it helpful!
