This Guidance helps you implement a scalable and low-cost Stable Diffusion (SD) web user interface (UI) inference architecture on AWS. SD is a popular open source project for generating images using generative AI. This Guidance shows how to use serverless and container services to build and deploy an end-to-end, low-cost, and asynchronous image generation architecture. 

Please note: [Disclaimer]

Architecture Diagram

[Architecture diagram description]

Download the architecture diagram PDF 

Well-Architected Pillars

The AWS Well-Architected Framework helps you understand the pros and cons of the decisions you make when building systems in the cloud. The six pillars of the Framework allow you to learn architectural best practices for designing and operating reliable, secure, efficient, cost-effective, and sustainable systems. Using the AWS Well-Architected Tool, available at no charge in the AWS Management Console, you can review your workloads against these best practices by answering a set of questions for each pillar.

The architecture diagram above is an example of a Solution created with Well-Architected best practices in mind. To be fully Well-Architected, you should follow as many Well-Architected best practices as possible.

  • AWS X-Ray traces a request from API Gateway to Lambda, Amazon SNS, Amazon SQS, Amazon EKS pods, and all the way to Amazon S3. This allows users to quickly troubleshoot requests. Additionally, X-Ray provides a service map that allows the user to identify the current system status with one glance.  

    AWS Distro for OpenTelemetry collects metrics from the EKS cluster and sends them to Amazon CloudWatch. Distro for OpenTelemetry and CloudWatch help you obtain critical metrics and receive automatic alerts when metrics exceed thresholds. CloudWatch Container Insights helps to visualize those metrics.

    Read the Operational Excellence whitepaper 
  • AWS Identity and Access Management (IAM) provides access control for API Gateway, Lambda, Amazon SNS, Amazon SQS, and Amazon S3. IAM Roles for Service Accounts (IRSA) on EKS clusters provides fine-grained access control for pods running inside the EKS cluster. IAM and IRSA on EKS clusters enforce role-based access control and limit unauthorized access to resources.

    Read the Security whitepaper 
  • All the services in this Guidance are regional services with built-in high availability and fault tolerance against Availability Zone failure. In addition to the high availability of each individual service, this Guidance uses a loosely-coupled microservices architecture. Additionally, Amazon S3 and Amazon EFS provide highly reliable storage service to support uptime.

    Read the Reliability whitepaper 
  • Amazon EKS provides flexible container scheduling and scalability. KEDA is an event-driven pod auto-scaler for Kubernetes. Karpenter simplifies Kubernetes infrastructure and automatically launches the right amount of compute resources to handle the cluster's applications. Combined with KEDA and Karpenter, Amazon EKS can scale up a new node in less than one minute. Bottlerocket is a container-optimized operating system and has a shorter start up time than Amazon Linux 2.

    Read the Performance Efficiency whitepaper 
  • Spot instances offer a lower price than on-demand instances. Stable Diffusion Web UI in Amazon EKS requires GPU instances for inference, and using Spot instances could save up to 70% on costs. Because SQS queues store the inference tasks, you won’t lose data in the event of spot interruption.

    Additionally, Amazon Elastic Container Service (Amazon ECS) on Fargate provides serverless infrastructure for running containerized applications. Amazon EKS provides a cost-efficient way to deploy, run, and manage containers through standard APIs. Amazon ECS on Fargate and Amazon EKS provide container orchestration with configurable infrastructure options to optimize costs. 

    Read the Cost Optimization whitepaper 
  • Lambda automatically scales based on requests and does not charge for idle infrastructure. This reduces the compute usage for the frontend API. Karpenter has a container workload consolidation feature that periodically checks if the current workloads can be consolidated onto existing EKS compute nodes with a lesser resource footprint, which helps to reduce idle resources. Amazon ECS on Fargate provides a serverless infrastructure option to run containers with a minimal resource footprint.

    Read the Sustainability whitepaper 

Implementation Resources

A detailed guide is provided to experiment and use within your AWS account. Each stage of building the Guidance, including deployment, usage, and cleanup, is examined to prepare it for deployment.

The sample code is a starting point. It is industry validated, prescriptive but not definitive, and a peek under the hood to help you begin.

[Content Type]


This [blog post/e-book/Guidance/sample code] demonstrates how [insert short description].


The sample code; software libraries; command line tools; proofs of concept; templates; or other related technology (including any of the foregoing that are provided by our personnel) is provided to you as AWS Content under the AWS Customer Agreement, or the relevant written agreement between you and AWS (whichever applies). You should not use this AWS Content in your production accounts, or on production or other critical data. You are responsible for testing, securing, and optimizing the AWS Content, such as sample code, as appropriate for production grade use based on your specific quality control practices and standards. Deploying AWS Content may incur AWS charges for creating or using AWS chargeable resources, such as running Amazon EC2 instances or using Amazon S3 storage.

References to third-party services or organizations in this Guidance do not imply an endorsement, sponsorship, or affiliation between Amazon or AWS and the third party. Guidance from AWS is a technical starting point, and you can customize your integration with third-party services when you deploy the architecture.

Was this page helpful?