Coder Social home page Coder Social logo

sdxl-cdk-go's Introduction

SDXL CDK Go

CDK Stack for Amazon Bedrock and Stability.ai Stable Diffusion XL 1.0 Image Generation

A CDK pattern for generating images using AWS Bedrock via SDXL. It is built using the AWS Cloud Development Kit, an Infrastructure as Code (IaC) tool to compose existing AWS constructs to create an AWS Lambda with a Function URL and permissions to call the Bedrock API. Implemented in Go. :-)

Features

  • Generates photorealistic images with high quality
  • Includes HTML application for generating images
  • Responses can be received in 7-10 seconds
  • Configurable inputs, limited to a single prompt
  • Quick, repeatable set-up and teardown
  • Automatic bundling with 3-6 second hot swaps
  • Rigorous error handling with forgiving responses

Screenshot

Screenshot

Why Golang

This project leverages Amazon Lambda Golang Library, an experimental library under active development that allows us to define our Lambda function using a handler code entrypoint as opposed to defining the handler using an asset for automatic bundling and faster hot-swapping behavior.

Requirements

  • AWS CLI installed and configured with your AWS account
  • Go for building the Lambda function
  • Bun for running CDK CLI commands directly

Usage

Once deployed, curl the function URL to generate an image:

curl -X POST \
    -H "Content-Type: text/plain" \
    -d 'a photograph of an astronaut riding a horse, 8k' \
    'https://tfxu2xorlbqekqv3l1kytkdb3e0nkjgk.lambda-url.us-east-1.on.aws/?cfg_scale=8.0&steps=20&seed=0'

The endpoint URL will become available upon deployment and will appear in the CDK stack outputs. Pass in your prompt as the body of the request in plain text. The following query string parameters are supported:

  • cfg_scale: The scale to use when generating the image
  • seed: The seed to use when generating the image
  • steps: The number of steps to use when generating the image
  • width: The width of the image to generate
  • height: The height of the image to generate

All parameters are optional. If not specified, the Bedrock defaults will be used.

Useful commands

Accounts and regions

  • aws sso login login to AWS using Identity Center
  • aws sts get-caller-identity get your AWS identity
  • aws configure sso configure your AWS credentials
  • aws configure list list your AWS credentials

Deployment and testing

  • bunx cdk deploy deploy this stack to your default AWS account/region
  • bunx cdk diff compare deployed stack with current state
  • bunx cdk synth emits the synthesized CloudFormation template
  • go test run unit tests
  • bunx cdk destroy destroy the stack

Development

  • go mod download download dependencies
  • go run sdxl-cdk-go.go bundle handler
  • go mod tidy update dependencies
  • go mod verify verify dependencies

sdxl-cdk-go's People

Contributors

vhscom avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.