Sketch-to-3D is an end-to-end generative AI pipeline for fashion design: it transforms hand-drawn sketches into photorealistic product images and interactive 3D models, deployed on AWS with real-time updates.
The Sketch-to-3D sample uses Amazon SageMaker for ML inference (FLUX.2 and TRELLIS.2), Amazon S3 for storage, AWS AppSync for real-time GraphQL subscriptions, Amazon DynamoDB for state management, Amazon Cognito for authentication, AWS Lambda for orchestration, and AWS Amplify with React for the frontend.
There are two main inference flows:
- Sketch to Image (A): User uploads a sketch → S3 trigger Lambda reads job parameters → invokes SageMaker FLUX.2 async endpoint → 5 photorealistic variants generated in ~17s → results written to S3 → DynamoDB Streams push updates via AppSync to the frontend in real time.
- Image to 3D (B): User selects a variant → trigger Lambda invokes SageMaker TRELLIS.2 async endpoint → 3D GLB mesh with baked textures generated → result delivered via AppSync subscription → interactive 3D viewer in browser.
For a detailed breakdown of stacks, project structure, security controls, and costs, see docs/ARCHITECTURE.md. The React frontend is documented separately in docs/FRONTEND.md.
To deploy the sample application you will require an AWS account. If you don't already have an AWS account, create one at https://aws.amazon.com by following the on-screen instructions. Your access to the AWS account must have IAM permissions to launch AWS CDK stacks that create IAM roles.
You will also need:
- AWS CLI v2 configured
- Python 3.10+
- Node.js 20+
- AWS CDK CLI, recent version (
npm install -g aws-cdk@latest). The CLI must be new enough to read the cloud-assembly schema produced by the pinnedaws-cdk-lib; an outdated CLI fails with a "Cloud assembly schema version mismatch" error. If you hit that, upgrade the CLI. - Docker Desktop running
- SageMaker
ml.g7e.12xlarge for endpoint usagequota ≥ 2 — the exact Service Quotas name (request via the Service Quotas console) - Bedrock model access enabled for Claude Haiku 4.5 in the deploy region. The default model ID is the US cross-region inference profile (
us.anthropic.claude-haiku-4-5-...). If you deploy outsideus-*, overrideBEDROCK_MODEL_IDinconfig.envwith the inference profile for your region (e.g.eu.anthropic.claude-haiku-4-5-...) — otherwise sketch analysis fails at runtime with an AccessDenied/Validation error. - A HuggingFace token with the gated approvals for
facebook/dinov3-vitl16-pretrain-lvd1689mandbriaai/RMBG-2.0
To use the sample application you will require a modern browser.
Note: You are responsible for the cost of the AWS services used while running this sample deployment. There is no additional cost for using this sample. For full details, see the pricing pages for each AWS service you will be using in this sample. Prices are subject to change.
git clone https://github.com/aws-samples/sample-retail-sketch-to-3d.git
cd sample-retail-sketch-to-3d
# Install dependencies
cd backend && python3 -m venv .venv && source .venv/bin/activate && pip install -r requirements.txt
cd ../frontend && npm install && cd ../backend
# Create your config and set the deploy account + region.
# (setup_prerequisites resolves the account from STS automatically, but the
# other tools — cdk, sync_config — read these values from config.env.)
cp config.env.example config.env
export AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
export AWS_REGION=us-east-1 # must match your Bedrock/quota region (see below)
# then edit config.env to set AWS_ACCOUNT_ID and AWS_REGION accordingly
# Store HuggingFace token (both containers download gated weights at build/runtime)
aws ssm put-parameter --name /sketch-to-3d/hf-token --type SecureString --value "hf_..." --region us-east-1
aws ssm put-parameter --name /sketch-to-3d/hf-token-trellis --type SecureString --value "hf_..." --region us-east-1
# Provision S3 + Cognito + IAM
python3 scripts/setup_prerequisites.py --skip-ssm
# Deploy all five CDK stacks (~10–15 min; bootstrap is scoped to your account/region)
cdk bootstrap aws://$AWS_ACCOUNT_ID/$AWS_REGION && cdk deploy --all && python3 scripts/sync_config.py
# Build + deploy the two SageMaker endpoints (≈40–70 min each, can run in parallel)
(cd containers/sketch_to_image && ./build_and_push.sh --codebuild --wait) && python3 scripts/create_endpoint.py
(cd containers/trellis && ./build_and_push.sh --codebuild --wait) && python3 scripts/create_trellis_endpoint.py
# Deploy the frontend
cd ../frontend && python3 ../backend/scripts/generate_frontend_env.py && bash deploy-frontend.sh
# Tighten CORS now that the Amplify app exists
cd ../backend && cdk deploy --all && python3 scripts/setup_prerequisites.py --skip-ssm && python3 scripts/update_identity_pool_policy.pyFor full step-by-step instructions, post-deploy hardening, and troubleshooting, see docs/DEPLOYMENT.md.
- Create a user — self sign-up is disabled for security. Create your first user via the CLI:
aws cognito-idp admin-create-user --user-pool-id <YOUR_USER_POOL_ID> \ --username "you@example.com" --temporary-password "TempPass123!!" \ --user-attributes Name=email,Value=you@example.com Name=email_verified,Value=true \ --region us-east-1
- Open the Amplify URL → sign in with the temporary password → set your permanent password (12-char minimum with symbol)
- Upload a sketch (drag & drop, take photo on mobile, or "Capture from Phone" QR flow on desktop)
- Pick garment type (auto-detected by Claude Haiku 4.5), colour, material, optional pattern / moodboard
- Generate Design → 5 variants in ≈17s → pick one
- 3D
.glbgenerates automatically and displays in an interactive viewer
The two SageMaker endpoints cost ≈$22/h combined on ml.g7e.12xlarge. Always stop them after use — the rest of the stack is <$5/month.
python3 scripts/stop_endpoint.py # FLUX
python3 scripts/stop_trellis_endpoint.py # TRELLISA single script tears down everything — SageMaker endpoints/configs/models, the
five CDK stacks (cdk destroy --all), the S3 buckets and Cognito pools created
by setup_prerequisites.py, the IAM roles, the ECR repos, and the Amplify app:
cd backend
python3 scripts/teardown.py --dry-run # preview what will be deleted
python3 scripts/teardown.py # delete (prompts for confirmation)Useful flags:
--keep-ssm— preserve the HuggingFace SSM token parameters (skip re-storing the token on the next deploy)--yes— skip the confirmation prompt (for automation)
The account-level SageMaker service quota is never touched.
Contributions are more than welcome. Please read the code of conduct and the contributing guidelines.
This sample code is made available under the MIT-0 license. See the LICENSE file.
This project uses the following third-party models:
- FLUX.2 Klein 4B — Apache 2.0 (Black Forest Labs)
- TRELLIS.2-4B — MIT (Microsoft)

