Generate image with Amazon Bedrock, AWS Lambda, and Amazon API Gateway

API Gateway REST API → AWS Lambda → Amazon Bedrock → Amazon S3

Generate images using Amazon Bedrock from an AWS Lambda function fronted with API Gateway and save to Amazon S3

This project builds an integration between Amazon API Gateway, AWS Lambda, Amazon Bedrock and Amazon S3
The core functionality revolves around exposing an API endpoint via API Gateway that accepts a user-defined prompt.
When a prompt is received, API Gateway invokes an AWS Lambda function. This function is responsible for invoking a diffusion image generation model (Stable Diffusion XL 1.0) hosted on Amazon Bedrock, generating an image and saving it to Amazon S3.
To ensure compatibility with Bedrock, a Lambda Layer is used, it contains the latest version of the Boto3 library, as only the most recent Boto3 version includes a client for Amazon Bedrock.

< Back to all patterns

GitHub icon Download this pattern (.zip)

GitHub icon View this pattern on GitHub


Clone repo

git clone https://github.com/aws-samples/serverless-patterns/cd serverless-patterns/apigw-lambda-bedrock-s3-cdk-python

Deploy

cdk deploy


Testing

See the GitHub repo for detailed testing instructions.

Cleanup

Delete the stack: cdk delete.

Created by:

Chris Peter Francis

Chris Peter Francis

Chris is a Solutions Architect for AWS Energy. Serverless advocate and enthusiast.

Follow on LinkedIn