Automate 1111 image generators and how to deploying it on AWS EC2 instance and it configuration for production.
Stable Diffuision Automate 1111

Automate 1111 image generators and how to deploying it on AWS EC2 instance and it configuration for production.

Have you ever wonder where these beautiful AI images come from. That’s what I was thinking when my elder brother Hassan Revel comes to me, one of the best Cloud Engineer (Just Kidding) and said hey can we deploy automate1111 on AWS EC2 cause I really need it. That when I introduced to automate1111 and things make sense to me where those AI anime girls images comes from.

Anyways about deploying Automate to EC2, it’s really simple and straight forward. We need to open some port and make adjust in automate config files. Pretty simple isn't?

Note:

I am not going to step up automate on instance for you. Gonna have to do it by yourself, Just install and configure it as you do it on your computer. Don’t judge me on this I know I am lazy person.

1: Instance type g4dn.xlarge

I believe this instance is great for anyone kind of AI and Machine learning work. My elder brother use this all the time and he has a great experience using it and nice things to say about it, "What is wong with this instance. This is bold sh*t." said by Hassan Revel . Anyways Please use this instance for this project because it's super fast and very reliable. You can get up 60% on it if you request spot Instance.

g4dn.xlarge

2: Instance Configuration

Please completing installing your automate on it as you do in your device. Now we gonna need to do some adjust on system and projects file. I have look into the docs of automate1111 and I believe they did a great job setting it up for productions.

automate files

Automate configuration:

Now run the automate as you normally do by typing

If thing are things correctly then you are good to follow my lead.

  • sudo nano webui-user.sh
  • In export COMMANDLIN_ARGS section add —share and —listening in quotes.

webui-user.sh

See if the automate is running run on host and port 0.0.0.0:7862

automate host

  • Cntrl C

Instance configuration

Now we need to tell ubuntu that it keep the automate running on closing ssh or on server restart

  • cd /etc/systemd/system
  • sudo nano Automatic1111.service
  • Past the script below into it

Description=Automatic1111
After=network.target

[Service]
Type=simple
ExecStart=/home/ubuntu/stable-diffusion-webui/webui.sh
Restart=always
User=ubuntu

[Install]
WantedBy=multi-user.target        

  • Make Sure to set the proper path to your automate project

system.conf

  • CNTRL X, Y and enter

Now it's time to see if your efforts are worth the trouble or not!

  • sudo systemctl daemon-reload
  • sudo systemctl enable Automatic1111
  • sudo systemctl start Automatic1111
  • sudo systemctl status Automatic1111

Automate status

If the automate is in running state after configuring the files. Then we successed if not then I am afraid you gonna have to follow things again. Getting error at this stage is normal. I made this blogs after solving a lones of error, so it's normal if you get stuck in error it helps us to keep learning.

3: AWS configuration

For automate the AWSconfiguration kinda go different. Now you might say this is just like web page all I have to do is open port on 80 and 443 and It would work. At least that is what I though to myself but no. Follow through the below step and It would work like a charm. Trust me!

Security Group setting:

  • Go to your security group that is attach to your instance

Security group


  • Add some inbounds rules to it like http, https inbound rules for load balancer.

http and https rules

  • Add a new rule and it would be custom TCP on port 7860

custom tcp rule


  • Copy your instance public IP address and paste it to browser with mentioning the port as well
  • 18.132.196.188:7860

automate

Now at this moment things are working great but if one if those rocket must be pointer guys then follow the below configuration to connect it to Route 53 for https or domain name.

Load balance configuration:

Trust me! this part may seem complicate but if you’re developer then this nothing for you or if not then just follow along. Good Luck!

  • Create a instance target group first

Here people might try to have TCP or change the port. Trust me you don’t have to change anything for it to work, just configure it normally.

Target group

  • Select your VPC and the click next
  • Here Change the port 80 to 7860

target port

  • Add you instance to pending

pending stage

  • Click create and we are off to load balance

Now please don’t thing about create a Network load balance just create a Application Load balance. Don’t judge me on this I know it’s possible with NLB but ALB also get the job done and it's cost efficient and more reliable in this regard.

  • Create the load balancer you normal create for web pages

Listener

  • Attach your SSL certificate to ALB

  • In Listening and rules, select HTTP:80 then click on manage rules and then add a rule


  • Give it a name then Next.
  • Add a condition by selecting HTTP and type GET then confirm. Now click next
  • GO to redirect to url enter port 443
  • Give the Priority 1 and then next and create

This will redirect http traffic to https

  • Go to route 53 and create a record

Woow it worked:

Summary:

This is all there is to deploying the automate1111 to AWS. Now we could have made things much more secure and fast but that would require a lot of unnecessary steps. I made this blogs just to get the project on running site. Feel free to contact me if you wanna attach nginx or apache to it, I hope we would work together to improve your work.

要查看或添加评论,请登录

Ali Raza的更多文章

社区洞察

其他会员也浏览了