Home Gen AI News Talk Accelerating your marketing ideation with generative AI – Part 2: Generate custom...

Accelerating your marketing ideation with generative AI – Part 2: Generate custom marketing images from historical references

3

Marketing teams face major challenges creating campaigns in today’s digital environment. They must navigate through complex data analytics and rapidly changing consumer preferences to produce engaging, personalized content across multiple channels while maintaining brand consistency and working within tight deadlines. Using generative AI can streamline and accelerate the creative process while maintaining alignment with business objectives. Indeed, according to McKinsey’s “The State of AI in 2023” report, 72% of organizations now integrate AI into their operations, with marketing emerging as a key area of implementation.

Building upon our earlier work of marketing campaign image generation using Amazon Nova foundation models, in this post, we demonstrate how to enhance image generation by learning from previous marketing campaigns. We explore how to integrate Amazon Bedrock, AWS Lambda, and Amazon OpenSearch Serverless to create an advanced image generation system that uses reference campaigns to maintain brand guidelines, deliver consistent content, and enhance the effectiveness and efficiency of new campaign creation.

The value of previous campaign information

Historical campaign data serves as a powerful foundation for creating effective marketing content. By analyzing performance patterns across past campaigns, teams can identify and replicate successful creative elements that consistently drive higher engagement rates and conversions. These patterns might include specific color schemes, image compositions, or visual storytelling techniques that resonate with target audiences. Previous campaign assets also serve as proven references for maintaining consistent brand voice and visual identity across channels. This consistency is crucial for building brand recognition and trust, especially in multi-channel marketing environments where coherent messaging is essential.

In this post, we explore how to use historical campaign assets in marketing content creation. We enrich reference images with valuable metadata, including campaign details and AI-generated image descriptions, and process them through embedding models. By integrating these reference assets with AI-powered content generation, marketing teams can transform past successes into actionable insights for future campaigns. Organizations can use this data-driven approach to scale their marketing efforts while maintaining quality and consistency, resulting in more efficient resource utilization and improved campaign performance. We’ll demonstrate how this systematic method of using previous campaign data can significantly enhance marketing strategies and outcomes.

Solution overview

In our previous post, we implemented a marketing campaign image generator using Amazon Nova Pro and Amazon Nova Canvas. In this post, we explore how to enhance this solution by incorporating a reference image search engine that uses historical campaign assets to improve generation results. The following architecture diagram illustrates the solution:

Architecture diagram for AI-powered marketing content generation and semantic image search on AWS

The main architecture components are explained in the following list:

  1. Our system begins with a web-based UI that users can access to start the creation of new marketing campaign images. Amazon Cognito handles user authentication and management, helping to ensure secure access to the platform.
  2. The historical marketing assets are uploaded to Amazon Simple Storage Service (Amazon S3) to build a relevant reference library. This upload process is initiated through Amazon API Gateway. In this post, we use the publicly available COCO (Common Objects in Context) dataset as our source of reference images.
  3. The image processing AWS Step Functions workflow is triggered through API Gateway and processes images in three steps:
    1. A Lambda function (DescribeImgFunction) uses the Amazon Nova Pro model to describe the images and identify their key elements.
    2. A Lambda function (EmbedImgFunction) transforms the images into embeddings using the Amazon Titan Multimodal Embeddings foundation model.
    3. A Lambda function (IndexDataFunction) stores the reference image embeddings in an OpenSearch Serverless index, enabling quick similarity searches.
  4. This step bridges asset discovery and content generation. When users initiate a new campaign, a Lambda function (GenerateRecommendationsFunction) transforms the campaign requirements into vector embeddings and performs a similarity search in the OpenSearch Serverless index to identify the most relevant reference images. The descriptions of selected reference images are then incorporated into an enhanced prompt through a Lambda function (GeneratePromptFunction). This prompt powers the creation of new campaign images using Amazon Bedrock through a Lambda function (GenerateNewImagesFunction). For detailed information about the image generation process, see our previous blog.

Our solution is available in GitHub. To deploy this project, follow the instructions available in the README file.

Procedure

In this section, we examine the technical components of our solution, from reference image processing through final marketing content generation.

Analyzing the reference image dataset

The first step in our AWS Step Functions workflow is analyzing reference images using the Lambda Function DescribeImgFunction. This resource uses Amazon Nova Pro 1.0 to generate two key components for each image: a detailed description and a list of elements present in the image. These metadata components will be integrated into our vector database index later and used for creating new campaign visuals.

For implementation details, including the complete prompt template and Lambda function code, see our GitHub repository. The following is the structured output generated by the function when presented with an image:

Baseball outfielder in white uniform catching a ball during a game with coach nearby on a natural field with trees in background

{
  "statusCode": 201,
  "body": {
    "labels_list": [
      "baseball player in white t-shirt",
      "baseball player in green t-shirt",
      "blue helmet",
      "green cap",
      "baseball glove",
      "baseball field",
      "trees",
      "grass"
    ],
    "description": "An image showing two people playing baseball. The person in front, wearing a white t-shirt and blue helmet, is running towards the base. The person behind, wearing a green t-shirt and green cap, is holding a baseball glove in his right hand, possibly preparing to catch the ball. The background includes a lush green area with trees and a dirt baseball field.",
    "msg": "success"
  }
}

Generating reference image embeddings

The Lambda function EmbedImgFunction encodes the reference images into vector representations using the Amazon Titan Multimodal Embeddings model. This model can embed both modalities into a joint space where text and images are represented as numerical vectors in the same dimensional space. In this unified representation, semantically similar objects (whether text or images) are positioned closer together. The model preserves semantic relationships within and across modalities, enabling direct comparisons between any combination of images and text. This enables powerful capabilities such as text-based image search, image similarity search, and combined text and image search.

The following code demonstrates the essential logic for converting images into vector embeddings. For the complete implementation of the Lambda function, see our GitHub repository.

with open(image_path, "rb") as image_file:
    input_image = base64.b64encode(image_file.read()).decode('utf8')

response = bedrock_runtime.invoke_model(
    body=json.dumps({
        "inputImage": input_image,
        "embeddingConfig": {
            "outputEmbeddingLength": dimension
        }
    }),
    modelId=model_id
)
json.loads(response.get("body").read())

The function outputs a structured response containing the image details and its embedding vector, as shown in the following example.

{
    'filename': '000000000872.jpg',
    'file_path': '{AMAZON_S3_PATH}',
    'embedding': [
        0.040705927,
        -0.007597826,
        -0.013537944,
        -0.038679842,
        ... // 1,024-dimensional vector by default, though this can be adjusted
    ]
}

Index reference images with Amazon Bedrock and OpenSearch Serverless

Our solution uses OpenSearch Serverless to enable efficient vector search capabilities for reference images. This process involves two main steps: setting up the search infrastructure and then populating it with reference image data.

Creation of the search index

Before indexing our reference images, we need to set up the appropriate search infrastructure. When our stack is deployed, it provisions a vector search collection in OpenSearch Serverless, which automatically handles scaling and infrastructure management. Within this collection, we create a search index using the Lambda function CreateOpenSearchIndexFn.

Our index mappings configuration, shown in the following code, defines the vector similarity algorithm and the campaign metadata fields for filtering. We use the Hierarchical Navigable Small World (HNSW) algorithm, providing an optimal balance between search speed and accuracy. The campaign metadata includes an objective field that captures campaign goals (such as clicks, awareness, or likes) and a node field that identifies target audiences (such as followers, customers, or new customers). By filtering search results using these fields, we can help ensure that reference images come from campaigns with matching objectives and target audiences, maintaining alignment in our marketing approach.

{
    "mappings": {
        "properties": {
            "results": {"type": "float"},
            "node": {"type": "keyword"},
            "objective": {"type": "keyword"},
            "image_s3_uri": {"type": "text"},
            "image_description": {"type": "text"},
            "img_element_list": {"type": "text"},
            "embeddings": {
                "type": "knn_vector",
                "dimension": 1024,
                "method": {
                    "engine": "nmslib",
                    "space_type": "cosinesimil",
                    "name": "hnsw",
                    "parameters": {"ef_construction": 512, "m": 16}
                }
            }
        }
    }
}

For the complete implementation details, including index settings and additional configurations, see our GitHub repository.

Indexing reference images

With our search index in place, we can now populate it with reference image data. The Lambda function IndexDataFunction handles this process by connecting to the OpenSearch Serverless index and storing each image’s vector embedding alongside its metadata (campaign objectives, target audience, descriptions, and other relevant information). We can use this indexed data later to quickly find relevant reference images when creating new marketing campaigns. Below is a simplified implementation, with the complete code available in our GitHub repository:

# Initialize the OpenSearch client
oss_client = OpenSearch(
    hosts=[{'host': OSS_HOST, 'port': 443}],
    http_auth=AWSV4SignerAuth(boto3.Session().get_credentials(), region, 'aoss'),
    use_ssl=True,
    verify_certs=True,
    connection_class=RequestsHttpConnection
)
# Prepare document for indexing
document = {
    "id": image_id,
    "node": metadata['node'],
    "objective": metadata['objective'],
    "image_s3_uri": s3_url,
    "image_description": description,
    "img_element_list": elements,
    "embeddings": embedding_vector
}
# Index document in OpenSearch
oss_response = oss_client.index(
    index=OSS_EMBEDDINGS_INDEX_NAME,
    body=document
)

Integrate the search engine into the marketing campaigns image generator

The image generation workflow combines campaign requirements with insights from previous reference images to create new marketing visuals. The process begins when users initiate a new campaign through the web UI. Users provide three key inputs: a text description of their desired campaign, its objective, and its node. Using these inputs, we perform a vector similarity search in OpenSearch Serverless to identify the most relevant reference images from our library. For these selected images, we retrieve their descriptions (created earlier through Lambda function DescribeImgFunction) and incorporate them into our prompt engineering process. The resulting enhanced prompt serves as the foundation for generating new campaign images that align with both: the user’s requirements and successful reference examples. Let’s examine each step of this process in detail.

Get image recommendations

When a user defines a new campaign description, the Lambda function GetRecommendationsFunction transforms it into a vector embedding using the Amazon Titan Multimodal Embeddings model. By transforming the campaign description into the same vector space as our image library, we can perform precise similarity searches and identify reference images that closely align with the campaign’s objectives and visual requirements.

The Lambda function configures the search parameters, including the number of results to retrieve and the k value for the k-NN algorithm. In our sample implementation, we set k to 5, retrieving the top five most similar images. These parameters can be adjusted to balance result diversity and relevance.

To help ensure contextual relevance, we apply filters to match both the node (target audience) and objective of the new campaign. This approach guarantees that recommended images are not only visually similar but also aligned with the campaign’s specific goals and target audience. We showcase a simplified implementation of our search query, with the complete code available in our GitHub repository.

body = {
    "size": k,
    "_source": {"exclude": ["embeddings"]},
    "query":
        {
            "knn":
                {
                    "embeddings": {
                        "vector": embedding,
                        "k": k,
                    }
                }
        },
    "post_filter": {
        "bool": {
            "filter": [
                {"term": {"node": node}},
                {"term": {"objective": objective}}
            ]
        }
    }
}
res = oss_client.search(index=OSS_EMBEDDINGS_INDEX_NAME, body=body)

The function processes the search results, which are stored in Amazon DynamoDB to maintain a persistent record of campaign-image associations for efficient retrieval. Users can access these recommendations through the UI and select which reference images to use for their new campaign creation.

Enhancing the meta-prompting technique with reference images

The prompt generation phase builds upon our meta-prompting technique introduced in our previous blog. While maintaining the same approach with Amazon Nova Pro 1.0, we now enhance the process by incorporating descriptions from user-selected reference images. These descriptions are integrated into the template prompt using XML tags (<related_images>), as shown in the following example.

You are a graphics designer named Joe that specializes in creating visualizations aided by text-to-image foundation models. Your colleagues come to you whenever they want to craft efficient prompts for creating images with text-to-image foundation models such as Stable Difussion or Dall-E. 

You always respond to your colleagues requests with a very efficient prompt for creating great visualizations using text-to-image foundation models.

These are some rules you will follow when interacting with your colleagues:

* Your colleagues will discuss their ideas using either Spanish or English, so please be flexible.
* Your answers will always be in English regardless of the language your colleague used to communicate.
* Your prompt should be at most 512 characters. You are encouraged to use all of them.
* Do not give details about or resolution of the images in the prompt you will generate.
* You will always say out loud what you are thinking
* You always reason only once before creating a prompt
* No matter what you always provide a prompt to your colleagues
* You will create only one prompt
* If provided with reference image descriptions (will be in between <related_images> XML tags) carefully balance the contributions of the campaigns description with the reference images to create the prompt
* Never suggest to add text to the images

Here are some guidelines you always follow when crafting effective image prompts:

* Start with a clear vision: Have a clear idea of the image you want the AI to generate, picturing the scene or concept in your mind in detail.
* Choose your subject: Clearly state the main subject of your image, ensuring it is prominently mentioned in the prompt.
* Set the scene: Describe the setting or background, including the environment, time of day, or specific location.
* Specify lighting and atmosphere: Use descriptive phrases for lighting and mood, like "bathed in golden hour light" or "mystical atmosphere".
* Incorporate details and textures: Enrich your prompt with descriptions of textures, colors, or specific objects to add depth.
* Use negative keywords wisely: Include specific elements you want the AI to avoid to refine the output.
* Be mindful of length and clarity: Effective prompts tend to be detailed but not overly long, providing key visual features, styles, emotions or other descriptive elements.
* Special tokens can be added to provide higher-level guidance like "photorealistic", "cinematic lighting" etc. These act like keywords for the model.
* Logically order prompt elements and use punctuation to indicate relationships. For example, use commas to separate independent clauses or colons to lead into a description.
* Review and revise: Check your prompt for accuracy and clarity, revising as needed to better capture your idea.

Here are some examples of prompts you have created previously to help your colleagues:

{Text to image prompt examples}

A colleague of yours has come to you for help in creating a prompt for:

{text}

He also found the following image descriptions that match what he would like to create and he wants you to consider the for crafting your prompt:

<related_images>
{Descriptions of related reference images}
</related_images>
Using your knowledge in text-to-image foundation models craft a prompt to generate an image for your colleague. You are encouraged to think out loud in your creative process but please write it down in a scratchpad.

Structure your output in a JSON object with the following structure:

{json_schema}

The prompt generation is orchestrated by the Lambda function GeneratePromptFunction. The function receives the campaign ID and the URLs of selected reference images, retrieves their descriptions from DynamoDB, and uses Amazon Nova Pro 1.0 to create an optimized prompt from the previous template. This prompt is used in the subsequent image generation phase. The code implementation of the Lambda function is available in our GitHub repository.

Image generation

After obtaining reference images and generating an enhanced prompt, we use the Lambda function GenerateNewImagesFunction to create the new campaign image. This function uses Amazon Nova Canvas 1.0 to generate a final visual asset that incorporates insights from successful reference campaigns. The implementation follows the image generation process we detailed in our previous blog. For the complete Lambda function code, see our GitHub repository.

Creating a new marketing campaign: An end-to-end example

We developed an intuitive interface that guides users through the campaign creation process. The interface handles the complexity of AI-powered image generation, only requiring users to provide their campaign description and basic details. We walk through the steps to create a marketing campaign using our solution:

  1. Users begin by defining three key campaign elements:
    1. Campaign description: A detailed brief that serves as the foundation for image generation.
    2. Campaign objective: The marketing aim (for example, Awareness) that guides the visual strategy.
    3. Target node: The specific audience segment (for example, Customers) for content targeting.

Definition of campaign elements

  1. Based on the campaign details, the system presents relevant images from previous successful campaigns. Users can review and select the images that align with their vision. These selections will guide the image generation process.

Suggestions of relevant images from previous marketing campaigns

  1. Using the campaign description and selected reference images, the system generates an enhanced prompt that serves as the input for the final image generation step.

AI-generated prompt for marketing image creation

  1. In the final step, our system generates visual assets based on the prompt that could potentially be used as inspiration for a complete campaign briefing.

AI-generated marketing campaign images

How Bancolombia is using Amazon Nova to streamline their marketing campaign assets generation

Bancolombia, one of Colombia’s leading banks, has been experimenting with this marketing content creation approach for more than a year. Their implementation provides valuable insights into how this solution can be integrated into established marketing workflows. Bancolombia has been able to streamline their creative workflow while ensuring that the generated visuals align with the campaign’s strategic intent. Juan Pablo Duque, Marketing Scientist Lead at Bancolombia, shares his perspective on the impact of this technology:

“For the Bancolombia team, leveraging historical imagery was a cornerstone in building this solution. Our goal was to directly tackle three major industry pain points:

  • Long and costly iterative processes: By implementing meta-prompting techniques and ensuring strict brand guidelines, we’ve significantly reduced the time users spend generating high-quality images.
  • Difficulty maintaining context across creative variations: By identifying and locking in key visual elements, we ensure seamless consistency across all graphic assets.
  • Lack of control over outputs: The suite of strategies integrated into our solution provides users with much greater precision and control over the results.

And this is just the beginning. This exercise allows us to validate new AI creations against our current library, ensuring we don’t over-rely on the same visuals and keeping our brand’s look fresh and engaging.”

Clean up

To avoid incurring future charges, you should delete all the resources used in this solution. Because the solution was deployed using multiple AWS CDK stacks, you should delete them in the reverse order of deployment to properly remove all resources. Follow these steps to clean up your environment:

  1. Delete the frontend stack:
cd frontend
cdk destroy
  1. Delete the image generation backend stack:
cd ../backend-img-generation
cdk destroy
  1. Delete the image indexing backend stack:
cd ../backend-img-indexing
cdk destroy
  1. Delete the OpenSearch roles stack:
cd ../create-opensearch-roles
cdk destroy

The cdk destroy command will remove most resources automatically, but there might be some resources that require manual deletion such as S3 buckets with content and OpenSearch collections. Make sure to check the AWS Management Console to verify that all resources have been properly removed. For more information about the cdk destroy command, see the AWS CDK Command Line Reference.

Conclusion

This post has presented a solution that enhances marketing content creation by combining generative AI with insights from historical campaigns. Using Amazon OpenSearch Serverless and Amazon Bedrock, we built a system that efficiently searches and uses reference images from previous marketing campaigns. The system filters these images based on campaign objectives and target audiences, helping to ensure strategic alignment. These references then feed into our prompt engineering process. Using Amazon Nova Pro, we generate a prompt that combines new campaign requirements with insights from successful past campaigns, providing brand consistency in the final image generation.

This implementation represents an initial step in using generative AI for marketing. The complete solution, including detailed implementations of the Lambda functions and configuration files, is available in our GitHub repository for adaptation to specific organizational needs.

For more information, see the following related resources:


About the authors

María Fernanda Cortés is a Senior Data Scientist at the Professional Services team of AWS. She’s focused on designing and developing end-to-end AI/ML solutions to address business challenges for customers globally. She’s passionate about scientific knowledge sharing and volunteering in technical communities.

David Laredo is a Senior Applied Scientist at Amazon, where he helps innovate on behalf of customers through the application of state-of-the-art techniques in ML. With over 10 years of AI/ML experience David is a regional technical leader for LATAM who constantly produces content in the form of blogposts, code samples and public speaking sessions. He currently leads the AI/ML expert community in LATAM.

Adriana Dorado is a Computer Engineer and Machine Learning Technical Field Community (TFC) member at AWS, where she has been for 5 years. She’s focused on helping small and medium-sized businesses and financial services customers to architect on the cloud and leverage AWS services to derive business value. Outside of work she’s passionate about serving as the Vice President of the Society of Women Engineers (SWE) Colombia chapter, reading science fiction and fantasy novels, and being the proud aunt of a beautiful niece.

Yunuen Piña is a Solutions Architect at AWS, specializing in helping small and medium-sized businesses across Mexico to transform their ideas into innovative cloud solutions that drive business growth.

Juan Pablo Duque is a Marketing Science Lead at Bancolombia, where he merges science and marketing to drive efficiency and effectiveness. He transforms complex analytics into compelling narratives. Passionate about GenAI in MarTech, he writes informative blog posts. He leads data scientists dedicated to reshaping the marketing landscape and defining new ways to measure.