> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Application Development Requirements Marketing Email Generator

> Serverless application design for generating marketing emails using Amazon Bedrock, with secure Lambda invocation, predictable JSON output, and frontend integration via API Gateway and S3

This lesson describes a serverless marketing email generator that uses Amazon Bedrock. The application creates marketing email copy from structured user inputs (product name, target audience, features, tone) by invoking a Bedrock foundation model from a Lambda function. The design focuses on a minimal, secure serverless architecture with predictable output formatting so the front-end can render results reliably.

The core functional requirement:

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

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/BVCvDn4rl3j0TCQq/images/Introduction-to-Amazon-Bedrock/Build-a-Marketing-Email-Generation-Application/Application-Development-Requirements-Marketing-Email-Generator/serverless-marketing-email-bedrock.jpg?fit=max&auto=format&n=BVCvDn4rl3j0TCQq&q=85&s=b91fe4632176c0c9f167cb7fef4cbc03" alt="A presentation slide titled &#x22;Marketing Email Generator — Application Requirements&#x22; with a teal rounded box that reads: &#x22;Build a serverless application that generates a marketing email based on structured user input using Amazon Bedrock.&#x22;" width="1920" height="1080" data-path="images/Introduction-to-Amazon-Bedrock/Build-a-Marketing-Email-Generation-Application/Application-Development-Requirements-Marketing-Email-Generator/serverless-marketing-email-bedrock.jpg" />
</Frame>

## 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)

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/BVCvDn4rl3j0TCQq/images/Introduction-to-Amazon-Bedrock/Build-a-Marketing-Email-Generation-Application/Application-Development-Requirements-Marketing-Email-Generator/marketing-user-product-audience-features-tone.jpg?fit=max&auto=format&n=BVCvDn4rl3j0TCQq&q=85&s=2c093db12464cc74bdbe81ccfa61f48c" alt="A dark presentation slide titled &#x22;A Marketing User provides...&#x22; showing four blue circular icons labeled Product Name, Target Audience, Key Features, and Tone. Each icon contains a simple white line illustration representing its concept." width="1920" height="1080" data-path="images/Introduction-to-Amazon-Bedrock/Build-a-Marketing-Email-Generation-Application/Application-Development-Requirements-Marketing-Email-Generator/marketing-user-product-audience-features-tone.jpg" />
</Frame>

This generator is industry-agnostic — the same front-end UI and prompt structure can support multiple verticals by changing the input values.

## 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 `maxTokens` and `temperature` to bound response length and variability.
* Consistent output formatting: enforce a predictable schema or template (for example, JSON with `subject`, `body`, and `cta`) so the UI can parse and display results reliably.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/BVCvDn4rl3j0TCQq/images/Introduction-to-Amazon-Bedrock/Build-a-Marketing-Email-Generation-Application/Application-Development-Requirements-Marketing-Email-Generator/nonfunctional-requirements-serverless-bedrock-iam-formatting.jpg?fit=max&auto=format&n=BVCvDn4rl3j0TCQq&q=85&s=6eba02dff7fc0919f87803a2ba5dba8f" alt="A presentation slide titled &#x22;Non-Functional Requirements&#x22; with four colored panels listing: &#x22;Use a Serverless Architecture&#x22;, &#x22;Invoke Bedrock securely using IAM&#x22;, &#x22;Control response length using model parameters&#x22;, and &#x22;Produce consistent formatting.&#x22; Each panel has a matching icon (cloud, lock, gauge, documents) and colored borders." width="1920" height="1080" data-path="images/Introduction-to-Amazon-Bedrock/Build-a-Marketing-Email-Generation-Application/Application-Development-Requirements-Marketing-Email-Generator/nonfunctional-requirements-serverless-bedrock-iam-formatting.jpg" />
</Frame>

<Callout icon="lightbulb" color="#1CB2FE">
  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.
</Callout>

## 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.

Why use S3 to host the UI?

* 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.

<Callout icon="warning" color="#FF6B6B">
  S3 website endpoints do not provide HTTPS by default. Put CloudFront in front of S3 when you require TLS or a custom domain.
</Callout>

Why Lambda + API Gateway?

* 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

| Layer | AWS Service | Purpose |
| - | - | - |
| Static UI | `S3 (+ CloudFront)` | Hosts HTML/CSS/JS for the client app |
| API | `API Gateway (REST)` | Accepts client POST requests and proxies to Lambda |
| Compute | `Lambda` | Builds prompt, sets model params, calls Bedrock SDK |
| Model | `Amazon Bedrock` | Generates email content using a foundation model |
| Auth & Permissions | `IAM` | Lambda execution role with least-privilege to call Bedrock |

## 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):

```json theme={null}
System: You are an expert marketing copywriter. Produce concise, persuasive marketing emails.

User:
{
  "productName": "Acme Smart Mug",
  "audience": "office workers who commute",
  "features": [
    "keeps coffee hot for 4 hours",
    "built-in temperature display",
    "lightweight, leak-proof"
  ],
  "tone": "friendly and professional",
  "sections": ["subject", "intro", "body", "cta"],
  "format": "json"
}
Instructions: Output a single JSON object with keys: "subject", "intro", "body", "cta". Keep each field under 120 words.
```

Example model parameters (provider-specific; adjust for Bedrock client):

```json theme={null}
{
  "maxTokens": 512,
  "temperature": 0.6,
  "stopSequences": ["\n\n"]
}
```

Note: When you require strict schema output, include explicit formatting instructions (e.g., "Return only JSON, no extra commentary"). If the model supports system messages vs. user messages, place the formatting rules in the system message.

## Example Lambda flow (pseudocode)

This snippet shows the conceptual flow inside your Lambda handler:

```javascript theme={null}
// Lambda handler (conceptual)
exports.handler = async (event) => {
  const input = JSON.parse(event.body);
  const prompt = buildPromptFromInput(input); // merge product, audience, features, tone
  const modelParams = { maxTokens: 512, temperature: 0.6 };

  // Call Bedrock via AWS SDK (pseudocode)
  const response = await bedrockClient.invokeModel({
    modelId: "your-model-id",
    prompt,
    ...modelParams
  });

  const generated = parseModelResponse(response); // enforce schema
  return {
    statusCode: 200,
    body: JSON.stringify(generated)
  };
};
```

Ensure the Lambda execution role has only the Bedrock permissions it needs. Example minimal permission statements should be scoped to the Bedrock API actions and the specific model(s) used.

## Typical UI flow (end-to-end)

1. User fills text fields: product name, short description, audience, tone, and optional desired length.
2. User clicks Generate — the client sends a POST request to the API Gateway endpoint.
3. API Gateway invokes Lambda with the structured input.
4. Lambda assembles the prompt, sets model parameters, and calls Amazon Bedrock.
5. Bedrock returns generated text in the expected format.
6. Lambda returns the structured output to API Gateway.
7. 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 `temperature` when you need consistent messaging.
* Use `maxTokens` to 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](https://docs.aws.amazon.com/bedrock/latest/userguide/what-is-bedrock.html)
* AWS Lambda: [https://docs.aws.amazon.com/lambda/latest/dg/welcome.html](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html)
* Amazon API Gateway: [https://docs.aws.amazon.com/apigateway/latest/developerguide/welcome.html](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](https://docs.aws.amazon.com/AmazonS3/latest/userguide/WebsiteHosting.html)
* CloudFront: [https://docs.aws.amazon.com/cloudfront/index.html](https://docs.aws.amazon.com/cloudfront/index.html)

Now that the application design and architecture are defined, you can proceed to implement the marketing email generator with the security, formatting, and model controls outlined above. Good luck.

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/introduction-to-amazon-bedrock/module/3cdbebe8-02b3-4e8c-91e1-112596fef875/lesson/29952b72-a0df-478c-8933-cefeb46bf344" />

  <Card title="Practice Lab" icon="flask-conical" cta="Learn more" href="https://learn.kodekloud.com/user/courses/introduction-to-amazon-bedrock/module/3cdbebe8-02b3-4e8c-91e1-112596fef875/lesson/5e81cd99-c4f8-48ff-840c-8d174cd21cdd" />
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.