The cdk.json
file tells the CDK Toolkit how to execute your app.
This project is set up like a standard Python project. The initialization
process also creates a virtualenv within this project, stored under the .venv
directory. To create the virtualenv it assumes that there is a python3
(or python
for Windows) executable in your path with access to the venv
package. If for any reason the automatic creation of the virtualenv fails,
you can create the virtualenv manually.
To manually create a virtualenv on MacOS and Linux:
$ python3 -m venv .venv
After the init process completes and the virtualenv is created, you can use the following step to activate your virtualenv.
$ source .venv/bin/activate
If you are a Windows platform, you would activate the virtualenv like this:
% .venv\Scripts\activate.bat
Once the virtualenv is activated, you can install the required dependencies.
(.venv) $ pip install -r requirements.txt
Before to synthesize the CloudFormation template for this code, you should update cdk.context.json
file.
For example,
{ "vpc_name": "default", "sd_webui_instance_type": "g4dn.2xlarge", "dlami_name": "Deep Learning Proprietary Nvidia Driver AMI GPU PyTorch 2.0.1 (Amazon Linux 2) 20240206", "ec2_key_pair_name": "your-ec2-key-pair-name(exclude .pem extension)" }
Now you are ready to synthesize the CloudFormation template for this code.
(.venv) $ cdk synth --all
ℹ️ You can find out the latest Deep learning AMI by runing the following command:
aws ec2 describe-images --region us-east-1 \ --owners amazon \ --filters 'Name=name,Values=Deep Learning Proprietary Nvidia Driver AMI GPU PyTorch 2.0.1 (Amazon Linux 2) ????????' 'Name=state,Values=available' \ --query 'reverse(sort_by(Images, &CreationDate))[:1].Name'
Use cdk deploy
command to create the stack shown above.
(.venv) $ cdk deploy --all
Or, we can provision each CDK stack one at a time like this:
(.venv) $ cdk list
SDWebUIonDLAMIVpcStack
SDWebUIonDLAMIStack
(.venv) $ cdk deploy SDWebUIonDLAMIVpcStack
(.venv) $ cdk deploy SDWebUIonDLAMIStack
To add additional dependencies, for example other CDK libraries, just add
them to your setup.py
file and rerun the pip install -r requirements.txt
command.
- Find out the Stable Diffusion WebUI URL by running the following command:
$ aws cloudformation describe-stacks \ --stack-name SDWebUIonDLAMIStack | \ jq -r '.Stacks[0].Outputs | .[] | select(.OutputKey | endswith("StableDiffusionWebUIURL")) | .OutputValue'
- In the address bar of your browser, type the URL above, or click on the link.
Delete the CloudFormation stacks by running the below command.
(.venv) $ cdk destroy --force --all
cdk ls
list all stacks in the appcdk synth
emits the synthesized CloudFormation templatecdk deploy
deploy this stack to your default AWS account/regioncdk diff
compare deployed stack with current statecdk docs
open CDK documentation
Enjoy!
- Extension for Stable Diffusion on AWS - The Extension for Stable Diffusion on Amazon Web Services solution helps customers migrate their existing Stable Diffusion model training, inference, and finetuning workloads from on-premises servers to Amazon SageMaker using extension and CloudFormation template.
- Release Notes for Amazon DLAMI
- Query AMI-ID with AWSCLI (example region is
us-east-1
):aws ec2 describe-images --region us-east-1 \ --owners amazon \ --filters 'Name=name,Values=Deep Learning AMI (Amazon Linux 2) Version ??.?' 'Name=state,Values=available' \ --query 'reverse(sort_by(Images, &CreationDate))[:1].Name'
- Query AMI-ID with AWSCLI (example region is
- (Open Source) Stable Diffusion Web UI - A web interface for Stable Diffusion, implemented using Gradio library
- Stable Diffusion Prompt: a Definitive guide
- How can I send user-data output to the console logs on an EC2 instance running Amazon Linux or Amazon Linux 2?
- The following is the line that redirects the user-data output:
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
- The following is the line that redirects the user-data output:
- How to Specify AWS EC2 Root Volume Size with CDK
- (AWS re:Post) How do I set the properties of a root volume for an Amazon EC2 instance that I created using an AWS CloudFormation template?