Guidance for Asynchronous Image Generation with Stable Diffusion on AWS
Use open source tools and generative AI for asynchronous image generation
Overview
How it Works
These technical details feature an architecture diagram to illustrate how to effectively use this solution. The architecture diagram shows the key components and their interactions, providing an overview of the architecture's structure and functionality step-by-step.
Well-Architected Pillars
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.
Operational Excellence
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 whitepaperSecurity
AWS Identity and Access Management (IAM) provides access control for API Gateway, Lambda, AmazonSNS, 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 whitepaperReliability
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 whitepaperPerformance Efficiency
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 whitepaperCost Optimization
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 whitepaperSustainability
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 whitepaperImplementation Resources
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.
Open implementation guide
Open sample code on GitHub
Disclaimer
Did you find what you were looking for today?
Let us know so we can improve the quality of the content on our pages