This project demonstrates how to generate images using Stable Diffusion by hosting ComfyUI on Amazon SageMaker Inference. It is a design pattern that allows adding GenAI image generation capability to your application.
ComfyUI is one of the most popular GUI and backend that allows you to generate images using Stable Diffusion. Some of the key features:
By hosting ComfyUI using Amazon SageMaker Inference, it can be particularly suitable when you want to:
There is a Lambda function to invoke SageMaker inference endpoint (which is running ComfyUI) for generating images. For illustration, Lambda function URL is configured so you can test the image generation by calling to this dedicated HTTPS endpoint.
The easiest way is to launch an EC2 instance of g5.xlarge
running AMI Deep Learning OSS Nvidia Driver AMI GPU PyTorch 2.3.0 (Amazon Linux 2)
. Connect to the instane using Session Manager, then add user to group docker
by running the following command.
sudo usermod -a -G docker $(whoami)
Disconnect and connect again for updated group membership to take effects.
- If you do not run ComfyUI locally, non-gpu instance such as
t3.small
also works.- If you want to run FLUX.1 model, use at least
g5.2xlarge
or above for fp8 version. use at leastg5.4xlarge
for fp16 version.
AWS Cloud9 or local machine also work but make sure the followings are installed properly.
🚫 Notes: Apple M1/M2/M3 is not working as cross-architecture build of container is not supported yet. You must build on x86_64 that matches SageMaker endpoint.
Step 1 - Clone the project:
git clone https://github.com/aws-samples/comfyui-on-amazon-sagemaker.git
Step 2 - Customize the following files (optional):
FLUX.1 - If you want to try FLUX.1 models:
Step 3 - Run deploy.sh. It usually takes less than one hour to complete.
./deploy.sh
For illustration, Lambda function URL is enabled so you can test the image generation by calling to this dedicated HTTPS endpoint. The endpoint URL can be found at the ComfyUIFunctionUrl
from the stack output.
AWS_IAM
auth is configured by default for invoking the lambda function URL, so you must sign each HTTP request using AWS Signature Version 4 (SigV4). Tools such as awscurl, Postman, and AWS SigV4 Proxy offer built-in ways to sign your requests with SigV4. You may disable the authentication by setting LAMBDA_URL_AUTH_TYPE
to NONE
in deploy.sh but it is dangerious as the function URL is open to everyone.
Example of AWS Signature authorization using Postman:
And here is an example of request body:
{
"positive_prompt": "hill happy dog",
"negative_prompt": "hill",
"prompt_file": "workflow_api.json",
"seed": 11245
}
A successful invocation seeing the image generated:
Delete the following resources deployed by deploy.sh.
comfyui
)comfyui-sagemaker-<AWS_ACCOUNT_ID>-<AWS_REGION>
)comfyui-sagemaker
)See DEVELOPMENT
See CONTRIBUTING for more information.
This library is licensed under the MIT-0 License. See the LICENSE file.