Skip to content

AWS Bedrock Image Generation Setup

Overview

Replace non-AWS image generators (Midjourney, FalAI, DALL-E direct) with AWS Bedrock Stable Diffusion SDXL for 100% AWS compliance.


Current Status

✅ Already Integrated

  • AWS Bedrock SDXL driver exists: app/Domains/Entity/Drivers/StableDiffusion/AwsBedrockDriver.php
  • BedrockEngine enum configured: app/Enums/BedrockEngine.php
  • Model available: STABLE_DIFFUSION_1 = stability.stable-diffusion-xl-v1

❌ Removed (Non-Compliant)

  • Midjourney (via PiAPI)
  • FalAI (Kling, Veo, Flux Pro, Ideogram, etc.)
  • Creatify (ad marketing videos)
  • Standalone image generators

⚠️ Still Available (Other AWS Services)

  • OpenAI DALL-E - If using via AWS integration
  • Together Flux - If hosted on AWS infrastructure

AWS Bedrock Image Generation

Supported Model

Stable Diffusion XL (SDXL) - Model ID: stability.stable-diffusion-xl-v1 - Resolution: 1024x1024, 512x512, or custom - Speed: ~20-30 seconds per image - Cost: ~$0.04-0.05 per image

Features

Text-to-Image - Generate images from text prompts - Support for style presets - Negative prompts for quality control

Image-to-Image - Modify existing images - Style transfer - Upscaling

Inpainting - Edit specific parts of images - Remove/replace objects


Implementation

1. Enable AWS Bedrock SDXL

The driver is already implemented. You need to:

  1. Enable the model in AWS Console:

    AWS Console → Bedrock → Model access → Request access
    Select: Stable Diffusion XL 1.0
    Wait for approval (~5-10 minutes)
    

  2. Configure in your app: Already configured in app/Enums/BedrockEngine.php:

    case STABLE_DIFFUSION_1 = 'stability.stable-diffusion-xl-v1';
    

2. Usage Example

Generate Image via Bedrock:

use App\Domains\Entity\Enums\EntityEnum;
use App\Domains\Entity\Facades\Entity;

// Generate image
$result = Entity::driver(EntityEnum::STABLE_DIFFUSION_XL_1024_V_1_0)
    ->input([
        'prompt' => 'A beautiful sunset over mountains, professional photography',
        'negative_prompt' => 'blurry, low quality, watermark',
        'width' => 1024,
        'height' => 1024,
        'steps' => 30,
        'cfg_scale' => 7.0,
        'samples' => 1,
    ])
    ->generate();

// Save to S3
if ($result->success) {
    $imageData = base64_decode($result->data['artifacts'][0]['base64']);
    $filename = 'generated_' . time() . '.png';
    Storage::disk('s3')->put("images/{$filename}", $imageData, 'public');
    $url = Storage::disk('s3')->url("images/{$filename}");
}

3. Available Entities

Check EntityEnum.php for Stable Diffusion variants: - STABLE_DIFFUSION_XL_1024_V_1_0 - Main SDXL model - STABLE_DIFFUSION_512_V_2_1 - Faster, smaller images - IMAGE_TO_VIDEO - Convert images to video - Other Stable Diffusion variants


Migrating Existing Images from R2 to S3

Migration Script

A migration is included: database/migrations/2025_11_21_000002_migrate_r2_images_to_s3.php

Run migration:

# First, ensure R2 credentials are still in .env (temporarily)
R2_ACCESS_KEY_ID=...
R2_SECRET_ACCESS_KEY=...
R2_BUCKET=...
R2_ENDPOINT=...

# Run migration
php artisan migrate

# After migration completes, remove R2 credentials from .env

What it does: 1. Scans database for R2 image URLs 2. Downloads images from R2 3. Uploads to AWS S3 4. Updates database URLs to point to S3 5. Keeps original R2 files as backup

Tables checked: - user_openai (output, image columns) - user_openai_chat_messages (output) - ai_presentations (pdf_url, pptx_url)


Image Generator Replacement Options

Update your image generation UI:

// OLD (Non-compliant)
$engines = [
    'dalle2' => 'DALL-E 2',
    'dalle3' => 'DALL-E 3',
    'midjourney' => 'Midjourney',
    'stable-diffusion' => 'Stable Diffusion',
];

// NEW (AWS-compliant)
$engines = [
    'aws-bedrock-sdxl' => 'AWS Bedrock SDXL',
    'stable-diffusion' => 'Stable Diffusion (Legacy)',
];

Controller update:

// In AIController or similar
public function generateImage(Request $request)
{
    // Use AWS Bedrock SDXL
    $entity = EntityEnum::STABLE_DIFFUSION_XL_1024_V_1_0;

    $result = Entity::driver($entity)
        ->input([
            'prompt' => $request->prompt,
            'negative_prompt' => $request->negative_prompt ?? 'low quality, blurry',
            'width' => $request->width ?? 1024,
            'height' => $request->height ?? 1024,
            'steps' => 30,
            'cfg_scale' => 7.0,
        ])
        ->generate();

    // Handle result...
}

Option 2: Keep OpenAI DALL-E (If AWS-Hosted)

If you're using OpenAI via an AWS-hosted integration, you can keep it: - Make sure OpenAI API calls go through AWS infrastructure - Document the AWS hosting for compliance

Option 3: Self-Host Open Source Models on AWS

For maximum control: - Deploy Stable Diffusion on AWS SageMaker - Use AWS EC2 with GPU instances - More expensive but fully controlled


Cost Comparison

Service Cost per Image Compliance
Midjourney $0.03-0.10 ❌ Non-AWS
FalAI (Flux, etc.) $0.04-0.08 ❌ Non-AWS
AWS Bedrock SDXL $0.04-0.05 ✅ AWS-compliant
Self-hosted on SageMaker $0.10-0.20 ✅ AWS-compliant

Verdict: AWS Bedrock SDXL has competitive pricing and is fully compliant.


Style Presets (SDXL)

AWS Bedrock SDXL supports these style presets:

  • photographic - Photorealistic images
  • digital-art - Digital artwork style
  • cinematic - Movie/film style
  • anime - Anime/manga style
  • line-art - Line drawing style
  • 3d-model - 3D rendered style
  • analog-film - Vintage film look
  • fantasy-art - Fantasy illustration
  • isometric - Isometric 3D view
  • low-poly - Low polygon 3D art
  • modeling-compound - Clay/sculpture style
  • neon-punk - Cyberpunk neon style
  • origami - Paper folding style
  • pixel-art - Retro pixel art

Usage:

$result = Entity::driver($entity)
    ->input([
        'prompt' => 'A futuristic city',
        'style_preset' => 'neon-punk',
        // ... other params
    ])
    ->generate();


Quality Tips

Better Prompts

Good:

"Professional portrait photo of a business executive,
studio lighting, sharp focus, 4k quality, photorealistic"

Bad:

"person in suit"

Negative Prompts

Always include to improve quality:

"blurry, low quality, distorted, watermark, text,
cropped, out of frame, bad anatomy"

For best quality: - Steps: 30-50 - CFG Scale: 7-10 - Resolution: 1024x1024

For speed: - Steps: 20-30 - CFG Scale: 7 - Resolution: 512x512


Testing

Test Image Generation

php artisan tinker

use App\Domains\Entity\Enums\EntityEnum;
use App\Domains\Entity\Facades\Entity;

$result = Entity::driver(EntityEnum::STABLE_DIFFUSION_XL_1024_V_1_0)
    ->input([
        'prompt' => 'A majestic lion in the savanna, golden hour lighting, professional wildlife photography',
        'negative_prompt' => 'blurry, low quality',
        'width' => 1024,
        'height' => 1024,
    ])
    ->generate();

dump($result);

Verify S3 Storage

aws s3 ls s3://your-bucket/images/ --recursive

Troubleshooting

Error: "Model not enabled"

Solution: Request access to SDXL in AWS Bedrock console

Error: "Insufficient permissions"

Solution: Add Bedrock permissions to IAM role:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "bedrock:InvokeModel",
        "bedrock:InvokeModelWithResponseStream"
      ],
      "Resource": "arn:aws:bedrock:*::foundation-model/stability.stable-diffusion-xl-v1"
    }
  ]
}

Images are blurry

Solution: Increase steps and resolution:

'steps' => 50,
'width' => 1024,
'height' => 1024,
'cfg_scale' => 8.0,


Migration Checklist

  • Enable AWS Bedrock SDXL in AWS Console
  • Test image generation with Bedrock
  • Run R2 to S3 migration script
  • Update UI to use AWS Bedrock
  • Remove Midjourney/FalAI references from controllers
  • Update documentation for users
  • Test existing image URLs (should now point to S3)
  • Verify S3 bucket permissions (public read for images)
  • Monitor AWS Bedrock costs
  • Remove R2 credentials from .env after migration

Support

AWS Bedrock Docs: https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-diffusion.html Stable Diffusion Guide: https://platform.stability.ai/docs/api-reference

Issues: https://github.com/vell-io/vell-main/issues


Last Updated: 2025-11-21 Compliance Status: ✅ AWS-Compliant