- Build a serverless application that generates a marketing email based on structured user input using Amazon Bedrock.

Inputs (structured)
Users provide a small set of structured fields that the Lambda function converts into a prompt for Bedrock:- Product name
- Target audience
- Key product features
- Tone (e.g., professional, casual, enthusiastic)
- Optional: desired length or email sections (subject line, intro, body, CTA)

Non-functional requirements
- Serverless architecture: use AWS Lambda for compute and API Gateway for the REST API.
- Secure Bedrock invocation: Lambda assumes an IAM role with least-privilege permissions limited to the Bedrock actions and specific models.
- Model parameter control: set parameters like
maxTokensandtemperatureto bound response length and variability. - Consistent output formatting: enforce a predictable schema or template (for example, JSON with
subject,body, andcta) so the UI can parse and display results reliably.

Grant the Lambda function an IAM role scoped to only the Bedrock actions and specific models it requires. Avoid broad permissions — follow least-privilege principles and restrict resource ARNs where possible.
Architectural overview (high level)
- Front end: static web UI (HTML, CSS, JS) hosted in an S3 bucket (or S3 + CloudFront). The browser renders the UI and collects user inputs.
- API layer: client-side JavaScript calls a REST API hosted by API Gateway.
- Compute: API Gateway routes requests to Lambda. Lambda assembles the structured prompt, sets model parameters (for example
maxTokens), and calls Amazon Bedrock using the AWS SDK. - Response: Bedrock returns generated text; Lambda returns it to API Gateway, which sends it back to the browser. The browser parses and presents the formatted email.
- S3 website hosting serves static assets (HTML, images, CSS, client-side JS) without provisioning servers. Use CloudFront in front of S3 if you need TLS, custom domains, lower latency, or caching.
S3 website endpoints do not provide HTTPS by default. Put CloudFront in front of S3 when you require TLS or a custom domain.
- This combination creates a fully serverless backend that scales automatically. Keep prompt assembly and Bedrock API calls inside Lambda to protect credentials and enforce IAM controls.
Recommended resource mapping
Prompt structure and model control
Keep prompts modular and explicit. A recommended pattern is to use a short system instruction followed by a structured request block that includes formatting constraints. For predictable parsing, ask the model to return JSON. Example structured prompt (text block sent to the model):Example Lambda flow (pseudocode)
This snippet shows the conceptual flow inside your Lambda handler:Typical UI flow (end-to-end)
- User fills text fields: product name, short description, audience, tone, and optional desired length.
- User clicks Generate — the client sends a POST request to the API Gateway endpoint.
- API Gateway invokes Lambda with the structured input.
- Lambda assembles the prompt, sets model parameters, and calls Amazon Bedrock.
- Bedrock returns generated text in the expected format.
- Lambda returns the structured output to API Gateway.
- The browser receives the JSON and renders the marketing email (subject, intro, body, CTA).
Tips for reliable outputs
- Use explicit output formatting (prefer JSON) to avoid ambiguous plain-text parsing.
- Limit variability with
temperaturewhen you need consistent messaging. - Use
maxTokensto bound response length and protect downstream UI layouts. - If you need multiple variations, request N outputs in one call or call the model multiple times with the same prompt and different seeds.
Links and references
- Amazon Bedrock docs: https://docs.aws.amazon.com/bedrock/latest/userguide/what-is-bedrock.html
- AWS Lambda: https://docs.aws.amazon.com/lambda/latest/dg/welcome.html
- Amazon API Gateway: https://docs.aws.amazon.com/apigateway/latest/developerguide/welcome.html
- Hosting static sites on S3: https://docs.aws.amazon.com/AmazonS3/latest/userguide/WebsiteHosting.html
- CloudFront: https://docs.aws.amazon.com/cloudfront/index.html