Go back

Step by step guide to setup Stable Diffusion on AWS

This section describes how to launch and connect to Techlatest Stable Diffusion with AUTOMATIC1111 Web Interface on Amazon Web Services (AWS).

  1. Open Techlatest Stable Diffusion with API & AUTOMATIC1111 on AWS VM listing on AWS marketplace

/img/aws/stable-diffusion/marketplace-2.png

  1. Click on Continue to subscribe.
  • Login with your credentials and follow the instruction.
  • Subscribe to the product and click on Continue to configuration button.
  • Select a Region where you want to launch the VM(such as US East (N.Virginia))

/img/aws/stable-diffusion/region.png

  • Click on Continue to Launch Button.
  • Choose Action: You can launch it through EC2 or from Website.(Let’s choose Launch from website)
  • Optionally change the EC2 instance type. This defaults to t2.xlarge instance type, 4 vCPUs and 16 GB RAM.
  • For optimal performance, Stable Diffusion requires significant processing power, which is best achieved with a GPU instance. However, if the cost of a GPU instance is prohibitive, a CPU instance with higher processing capacity may be used as an alternative.

Below are the recommended VM configuration:

  • GPU VM : g4dn.xlarge (4 vcpu 16gb memory) configuration
  • CPU VM : t2.xlarge (4vcpu, 16gb ram)

For CPU, its the minimum spec but more cpu is preferred.

/img/aws/stable-diffusion/launch-2.png

/img/aws/stable-diffusion/launch-g4dn.png

  • Select the VPC and Subnet from the dropdown.

/img/aws/stable-diffusion/vpc.png

  • Create the Security Group based on default configuration which comes with the ports 22 (for SSH), 3389 (for RDP) and 80 (for HTTP) exposed. Click on Create New based on Seller Settings. /img/aws/stable-diffusion/create-new-sg.png
  • Provide the Security group name and description. Save the changes. /img/aws/stable-diffusion/SG-2.png
  • Be sure to download the key-pair which is available by default, or you can create the new key-pair and download it. /img/aws/stable-diffusion/key-pair.png
  • Click on Launch when you are ready.
  • Techlatest Stable Diffusion with API & AUTOMATIC1111 will begin deploying. 3. A summary page displays.To see this instance on EC2 Console click on EC2 Console link.

/img/aws/stable-diffusion/deployed.png

  1. On the EC2 Console page, instance is up and running. Select the instance checkbox to see its details.

/img/aws/stable-diffusion/vm-details.png

  1. After VM launch for the first time, GPU instances will take 5-10 minutes and CPU instances will take 15-30 minutes to launch the app in the browser.

Wait for 5-10 or 15-30 minutes depending on if your VM is GPU or CPU based and then access the Stable Diffusion GUI via browser by copying the public IP of the VM from the VM’s overview page and paste it in the browser and then hit enter.

Note: Please use http and not https in the URL when accessing AUTOMATIC1111 interface in GUI, for eg. http://vm_public_ip.

/img/aws/stable-diffusion/public-ip.png

  1. The Stable Diffusion GUI comes with lots of options and settings. The first window shows text to image page. Provide the Prompt and click on Generate button and wait till it finishes.

/img/azure/stable-diffusion/stable-diffusion-gui-2.png

  1. Output Images can be seen in the Image Browser tab. Click on Image browser and click on first page to load the images.

/img/azure/stable-diffusion/image-browser-gallery-2.png

  1. In Image Browser, click on any image to see the details of it.

/img/azure/stable-diffusion/image-browser-2.png

  1. To change any settings, go to Settings tab.

/img/azure/stable-diffusion/settings-2.png

  1. Web UI also provides you the option to add extensions. Navigate to extensions tab, go to available and select load from URL. It will list all the available extensions.

/img/azure/stable-diffusion/extensions-2.png

  1. You can also see the list of installed extensions under installed tab.

/img/azure/stable-diffusion/extensions-installed.png

  1. For more information on how to use the GUI, Go to Stable Diffusion Web UI

  2. The images created from GUI are stored under /home/ubuntu/stable-diffusion/output/ directory on the VM. To access this directory, follow below steps:

/img/azure/stable-diffusion/output-directory.png

  1. To access the VM’s Desktop environment, first you need to SSH to this instance through putty. For that, copy the IPv4 Public IP Address

/img/aws/stable-diffusion/public-ip.png 15. Open putty, paste the IP address and browse your private key you downloaded while deploying the VM, by going to SSH- >Auth, click on Open. In the terminal enter ubuntu as userid and hit enter.

/img/aws/stable-diffusion/putty-01.png

/img/aws/stable-diffusion/putty-02.png

  1. Once connected, change the password for ubuntu user using below command
sudo passwd ubuntu

/img/aws/stable-diffusion/ssh-login.png

  1. Now the password for ubuntu user is set, you can connect to the VM’s desktop environment from any local Windows Machine using RDP protocol or Linux Machine using Remmina.

    From your local windows machine, goto “start” menu, in the search box type and select “Remote desktop connection”. In the “Remote Desktop connection” wizard, copy the public IP address and click connect

/img/aws/desktop-linux/rdp.png

  1. This will connect you to the VM’s desktop environment. Provide the username ubuntu and the password set in the above “Reset password” step to authenticate. Click OK

/img/aws/stable-diffusion/rdp-login.png

  1. Now you are connected to the out of box Techlatest Stable Diffusion with API & AUTOMATIC1111 environment via Windows Machine.

/img/aws/stable-diffusion/rdp-desktop.png

  1. To connect using RDP via Linux machine, first note the external IP of the VM from VM details page,then from your local Linux machine, goto menu, in the search box type and select “Remmina”.

    Note: If you don’t have Remmina installed on your Linux machine, firstInstall Remmina as per your linux distribution.

/img/gcp/common/remmina-search.png

  1. In the “Remmina Remote Desktop Client” wizard, select the RDP option from dropdown and paste the external ip and click enter.

/img/gcp/common/remmina-external-ip.png

  1. This will connect you to the VM’s desktop environment. Provide ubuntu as the userid and the password set in above reset password step to authenticate. Click OK

/img/gcp/common/remmina-rdp-login.png

  1. Now you are connected to out of box Techlatest Stable Diffusion with API & AUTOMATIC1111 environment via Linux machine.

/img/aws/stable-diffusion/rdp-desktop.png

  1. From VM’s Desktop, you can access the Output Images by navigating to /home/ubuntu/stable-diffusion/outputs/ directory.

/img/azure/stable-diffusion/output-directory.png

  1. You can also access the sourcecode of the Stable Diffusion. It is available under sourcecode folder on Desktop.

/img/gcp/stable-diffusion/source-code-folder-on-desktop.png

/img/aws/stable-diffusion/sourcecode-folder.png

  1. This VM is pre-configured for Stable Diffusion with an enabled API (Application Programming Interface). To access the preinstalled API’s, follow below steps:
  • open VM’s url using http://vmip/docs. Here you can find the list of API’s.

/img/azure/stable-diffusion/docs.png

  • Search for txt2img API, then click on the arrow at the right end of the searched api line, it gives an example of a payload to send to the API. Click on the try it out button.

/img/azure/stable-diffusion/txt2imgapi.png

  • This will enable the Request Body and Execute button. Try with the below code snippet in request body and click on Execute button.

e.g

{
“prompt”: “duck flying in sky”,
“steps”: 5
}

/img/azure/stable-diffusion/execute-api.png

  • After clicing on “Execute” button, You can observe the progress in the terminal by running-
tail -f /var/log/cloud-init-output.log

/img/azure/stable-diffusion/api-logs.png

  • Once image processing is complete, in the API webconsole, it will show “200” as response code and the response field will have response in json format with image in “images:” field of json.

/img/azure/stable-diffusion/response.png

  1. Please note that APIs are exposed on public internet and you must add necessary security controls to secure the API.

  2. If you want to disable the API or want to make any further configuration changes then please update line 20 and line 23 of /var/lib/cloud/scripts/per-boot/sd-per-boot.sh file as per the Stable Diffusion Wiki documentation.

sudo vi /var/lib/cloud/scripts/per-boot/sd-per-boot.sh

/img/azure/stable-diffusion/update-sd-per-boot.png

Credits:

Go back