
From Localhost to Production: Deploying ContextForge on AWS
A practical look at taking ContextForge from a working local FastAPI application to a production AWS deployment, including the deployment challenges, CloudFormation issues, debugging process, and lessons learned along the way.
From Localhost to Production: Deploying ContextForge on AWS
Getting ContextForge to work locally was one problem. Getting it to run reliably in production was another.
ContextForge is a knowledge management system that lets users organize information, retrieve relevant context, and ask questions over it using retrieval and LLM-based synthesis. Our backend was built with FastAPI, and locally everything was working as expected.
The plan for production was straightforward:
API Gateway would receive requests, Lambda would run the FastAPI application, DynamoDB would store application data, and Amazon Bedrock would handle embeddings and LLM responses.
AWS SAM gave us a single infrastructure template and a deployment script. So we ran the deployment.
It failed.
And that was when the interesting part of the deployment actually started.
The first lesson: local success is not production readiness
The first deployment failure came from something that looked completely reasonable.
Our Lambda configuration explicitly defined:
AWS_REGION: !Ref AWS::RegionThe application needed to know which AWS region it was running in, so setting the variable seemed natural.
Lambda disagreed.
AWS_REGION is provided automatically by the Lambda runtime and is a reserved environment variable. AWS therefore rejected the deployment before the function could even be created.The fix was simple: remove the variable and let Lambda provide it.
Fortunately, our application was already reading the value through:
os.getenv("AWS_REGION")so we didn't need to change the application code.
This was a small error, but it highlighted an important difference between local development and managed infrastructure.
Locally, we control almost everything around the application. In AWS, the platform itself provides configuration, permissions, networking, environment variables, and other runtime behavior.
The application needs to fit into that environment rather than assuming it owns everything.
Then we found another problem
After fixing the first issue, we looked more closely at the SAM template.
There was another problem around the Lambda Function URL.
The template was trying to expose the URL using:
!GetAtt ApiFunction.FunctionUrlThe problem was that
FunctionUrl wasn't an attribute available on the function resource in the way we were referencing it.This time, SAM linting helped us catch the problem before wasting another deployment cycle.
Instead of relying on an implicit resource, we explicitly declared the Lambda URL:
ContextForgeFunctionUrl: Type: AWS::Lambda::Url Properties: TargetFunctionArn: !GetAtt ApiFunction.Arn AuthType: NONEWe also added the required Lambda permission and referenced the URL resource directly in the CloudFormation outputs.
The lesson here was simple:
When infrastructure becomes important to the application, it helps to understand the actual resources being created rather than treating the infrastructure definition as magic.
The stack was now stuck
The first failed deployment left our CloudFormation stack in:
ROLLBACK_COMPLETEAt first, the obvious thought was:
"We fixed the template. Just deploy again."
But CloudFormation doesn't work that way once a stack reaches this state.
The failed stack couldn't simply be updated, so we had to delete it and create it again after fixing the configuration.
After deleting the failed stack, we validated the corrected template and deployed again.
This time, the infrastructure was created successfully.
A successful deployment isn't the same as a working application
Seeing
CREATE_COMPLETE would have been easy to treat as the finish line.It wasn't.
A CloudFormation stack being healthy only tells us that the infrastructure exists. It doesn't prove that the application can actually use it.
So we ran our smoke test against the production API.
The test exercised the real application flow:
API status ↓Register user ↓Create project ↓Ingest knowledge ↓Generate embeddings with Titan ↓Retrieve relevant context ↓Ask a question ↓Generate answer with Bedrock ClaudeEvery step succeeded.
The backend successfully connected API Gateway, Lambda, DynamoDB, and Bedrock into one working application.
That was the point where the deployment became more than "AWS resources were created."
We had a working production backend.
What the deployment taught us
Before this experience, it was easy to think of deployment as the final step:
Build → Deploy → DoneIn reality, it looked much more like:
Build ↓Understand the platform ↓Define infrastructure ↓Validate ↓Deploy ↓Find assumptions ↓Fix ↓Deploy again ↓Test the complete applicationThe
AWS_REGION issue taught us that managed platforms already provide functionality that we might otherwise try to configure ourselves.The Function URL issue taught us to understand the resources behind our infrastructure definitions.
The
ROLLBACK_COMPLETE state taught us that deployment failures have their own lifecycle and recovery process.And the smoke test reminded us that infrastructure being deployed and an application actually working are two different things.
From localhost to production
After the fixes, ContextForge was running on AWS using API Gateway, Lambda, DynamoDB, Amazon Bedrock, IAM, and SAM/CloudFormation.
The final smoke test successfully registered a user, created a project, ingested knowledge, generated embeddings, retrieved relevant information, and generated an answer through Bedrock.
The biggest lesson wasn't a particular AWS command.
It was realizing that deployment is where the assumptions made during development meet the constraints of the real environment.
The code got us to the starting line.
Understanding the platform got us the rest of the way.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article