In this blog, I’ll walk you through exactly how I created an AI-powered blog generator bot using Amazon Bedrock, Lambda, S3, and API Gateway. This was a mini project to practice serverless architecture using AWS services and AI text generation models to get introduce to Amazon Bedrock.
🔧 I used a non-chat LLaMA model from Amazon Bedrock, because that was available in my region (ap-south-1
) and suited my use case well for blog generation, dont hesitate to use anyother model.
✨ What You’ll Learn
- How to access and use Amazon Bedrock models
- How to prepare a Lambda function with external libraries like
boto3
- How to integrate Lambda with API Gateway for POST requests
- How to store generated blog content into S3 buckets
- How to test the endpoint using free tools like ReqBin
🛠️ Step 1: Enable Amazon Bedrock and Choose Model
🔹 Accessing Bedrock
- Go to AWS Console → Services → Amazon Bedrock.
- Request model access (you may need to request access for models like LLaMA3, Titan, etc.).
- Wait for approval (this can take from minutes to a few hours).
💡 I used
meta.llama3-8b-instruct-v1:0
, which was available in my region. I didn’t choose a chat model specifically — I used what was available for experimentation. If available you should choose a chat based model or any other good text based model.
🧠 Step 2: Write and Prepare the Lambda Function
🔹 Writing the Function
The Lambda function handles:
- Receiving the blog topic from API Gateway
- Sending the prompt to the Bedrock model
- Receiving and parsing the response
- Saving the blog to S3
import boto3
import botocore.config
import json
from datetime import datetime
def blog_generate_using_bedrock(blogtopic:str)->str:
prompt=f"""Write a blog minimum 300 to 500 words(no need to strictly follow) in a professional mammer with only 5 subtopics and a conclusion {blogtopic}"""
body={
"prompt":prompt,
"max_gen_len":600,
"temperature":0.5,
"top_p":0.9
}
try:
bedrock=boto3.client("bedrock-runtime",region_name="ap-south-1",config=botocore.config.Config(read_timeout=300,retries={'max_attempts':3}))
response=bedrock.invoke_model(body=json.dumps(body),modelId="")
response_content=response.get('body').read()
response_data=json.loads(response_content)
print(response_data)
blog_details=response_data['generation']
return blog_details
except Exception as e:
print(f"Error generating the blog:{e}")
return ""
def save_blog_details_s3(s3_key,s3_bucket,generate_blog):
s3=boto3.client('s3')
try:
s3.put_object(Bucket = s3_bucket, Key = s3_key, Body =generate_blog )
print("Code saved to s3")
except Exception as e:
print("Error when saving the code to s3")
def lambda_handler(event, context):
# TODO implement
event=json.loads(event['body'])
blogtopic=event['blog_topic']
generate_blog=blog_generate_using_bedrock(blogtopic=blogtopic)
if generate_blog:
curr_time=datetime.now().strftime('%H%M%S')
s3_key=f"blog-output/{curr_time}.txt"
s3_bucket=''
save_blog_details_s3(s3_key,s3_bucket,generate_blog)
else:
print("No blog was generated ")
return{
'statusCode':200,
'body':json.dumps('Blog Generation is Completed')
}
NOTE: - Replace 'Your_Model_ID' with your bedrock model's ModelID and 'Your_s3_bucket' with your AWS bucket
🔹 Important: Add boto3 Dependency
Amazon Bedrock needs latest boto3 version, which is not included in Lambda by default. You have two options:
✅ Option 1: Create a Lambda Layer with boto3
- On your local system, run:
mkdir python
pip install boto3 -t python/
zip -r boto3_layer.zip python
- Go to AWS Console → Lambda → Layers → Create Layer
- Upload
boto3_layer.zip
and choose compatible runtimes (Python 3.12, 3.11, or 3.10) - Attach the layer to your Lambda function
Your Result should look like this
🧠 Option 2: Include boto3 manually in deployment zip
(Same as above, but upload the entire zipped folder as your Lambda deployment package.)
🔗 Step 3: Setup API Gateway for Integration
🔹 Create an HTTP API
- Go to AWS Console → API Gateway
- Choose HTTP API
- Click “Build” and name it (e.g.,
BlogGenAPI
)
🔹 Configure Routing
- Create a route:
POST /blog-generation
- Add integration target: Your Lambda function
- Deploy the API and create a Stage (in my case:
dev
) - You’ll get
Invoke URL
https://your-api-id.execute-api.region.amazonaws.com/dev/
AND
Route details
POST /blog-generation
🪣 Step 4: Create and Connect S3 Bucket
- Go to AWS Console → S3 → Create a bucket
- Bucket name:
awsbedrocktapas
(you can name it anything but should be unique)
- Bucket name:
- No need to make it public
- Go to IAM role of the Lambda and allow:
-
s3:PutObject
on your bucket
-
In your Lambda code, the S3 upload part looks like this:
s3_key = f"blog-output/{curr_time}.txt"
s3_bucket = 'YOUR Bucket'
s3.put_object(Bucket=s3_bucket, Key=s3_key, Body=generated_blog)
Raplace 'YOUR Bucket' with your bucket name you just created
🧪 Step 5: Test the API using any tool, I am using ReqBin (Free Online Tool)
- Go to reqbin
- Choose method:
POST
- URL: Your deployed API Gateway endpoint
https://your-api-id.execute-api.region.amazonaws.com/dev/blog-generation
- Choose Content-Type:
json
- Add body:
{
"blog_topic": "Benefits of Remote Work in 2025"
}
- Hit “Send” and check the response
You should see:
{
"blog_topic": "Benefits of Remote Work in 2025"
}
Now check your S3 bucket — you’ll find a .txt
file with your freshly AI-generated blog!
🧾 Example Output Blog
✅ Final Flow Diagram (Optional)
🎯 Conclusion
Using just four core AWS services — Bedrock, Lambda, API Gateway, and S3 — we’ve built a complete, serverless AI-powered blog generator.
This project taught me how to:
- Work with LLMs via Bedrock
- Integrate custom code into Lambda
- Manage external Python libraries via Lambda Layers
- Expose a POST API endpoint for external use
- Save data persistently using S3
💬 You can build on top of this by adding:
- A frontend (React/Next.js)
- An email sender to notify when blog is ready
- An admin dashboard for blog management
🌐 My Socials
Feel free to connect with me or collaborate on other serverless & AI projects:
- 🔗 Portfolio: https://tapasenjinia.me
- 💼 LinkedIn: https://www.linkedin.com/in/tapas-singhal/
- 🧠 GitHub: https://github.com/its-tapas
📂 Project Repository
🔗 GitHub: https://github.com/its-tapas/blogGen
🤝 Open to improvements, ideas, and suggestions. Don't hesitate to fork, star, or contribute to this project!
Thanks for reading 🙌 — Tapas Singhal