AWS Builder Center

Build a Personalised Diwali Greeting Generator with Amazon Bedrock and AWS Lambda

Diwali falls on November 8 this year, which makes this a good weekend project. In this post you’ll build a small serverless app that generates warm, personalised Diwali wishes in English or Hinglish and serves them as shareable cards.

Hostel A Thapar university
Every Diwali our phones fill up with identical forwarded messages. With a few lines of code, you can generate a wish that uses the person's name, your relationship, and the tone you pick (funny, emotional, formal).
Flow: Request → Lambda Function URL → Lambda → Bedrock → wish
Services: AWS Lambda, Amazon Bedrock, IAM

Prerequisites

  • An AWS account with access enabled for a text model in Amazon Bedrock
  • Python 3.12 Lambda runtime

Step 1: The Lambda function

import json, os
import boto3

bedrock = boto3.client("bedrock-runtime")
MODEL_ID = os.environ["MODEL_ID"] # a model enabled in your Region

TONES = {"funny", "formal", "emotional", "poetic"}
LANGS = {"English", "Hinglish"}

def handler(event, context):
body = json.loads(event.get("body") or "{}")
name = str(body.get("name", "")).strip()[:40]
relation = str(body.get("relation", "friend")).strip()[:30]
tone = body.get("tone", "emotional")
lang = body.get("language", "English")

if not name or tone not in TONES or lang not in LANGS:
return {"statusCode": 400,
"body": json.dumps({"error": "Need name, valid tone and language"})}

prompt = (f"Write a 3-4 sentence Diwali greeting for my {relation} named {name}. "
f"Tone: {tone}. Language: {lang} (Roman script only if Hinglish). "
"Mention light or togetherness. Output only the greeting.")

res = bedrock.converse(
modelId=MODEL_ID,
messages=[{"role": "user", "content": [{"text": prompt}]}],
inferenceConfig={"maxTokens": 300, "temperature": 0.8},
)
wish = res["output"]["message"]["content"][0]["text"].strip()
return {"statusCode": 200,
"headers": {"Content-Type": "application/json"},
"body": json.dumps({"wish": wish}, ensure_ascii=False)}
Two small choices matter here:
  • Allow-lists and length limits on the inputs keep the prompt predictable and reduce prompt-injection risk.
  • The Converse API uses one request format across Bedrock models, so you can swap  MODEL_ID  without touching the code.

Step 2: Permissions

Give the Lambda role only what it needs:
{
"Effect": "Allow",
"Action": "bedrock:InvokeModel",
"Resource": "arn:aws:bedrock:<region>::foundation-model/<your-model-id>"
}
If your model uses a cross-Region inference profile, the Resource list also needs that profile's ARN (check the Bedrock docs). Set the  MODEL_ID  environment variable and raise the timeout to about 15 seconds.

Step 3: Expose and test

Enable a Function URL (auth  NONE  is fine for a quick demo), then run:
curl -X POST "$FUNCTION_URL" -H "Content-Type: application/json" \
-d '{"name":"Aarav","relation":"best friend","tone":"funny","language":"Hinglish"}'

Before you share the URL

A public GenAI endpoint can get expensive if someone spams it. Set reserved concurrency (say 5) on the function and add an AWS Budgets alert. For anything beyond a demo, put API Gateway with rate limiting in front.

Ideas to extend

  • Save a styled HTML card to S3 and share it through a presigned link
  • Add Bedrock Guardrails to filter unwanted content
  • Generate a rangoli image with an image model
  • Send wishes through a WhatsApp or Telegram bot

Clean up

Delete the function, its URL, and the IAM role when you're done.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article