Skip to content

Commit 5daa5db

Browse files
authored
Merge pull request #2719 from archiev4/archiev4-feature-apigw-lambda-bedrock-novacanvas
New serverless pattern - apigw-lambda-bedrock-novacanvas
2 parents 4df6121 + 1d1b80b commit 5daa5db

File tree

7 files changed

+426
-0
lines changed

7 files changed

+426
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Serverless Text-to-Image Generation with Amazon Bedrock Nova Canvas
2+
3+
![architecture](architecture/architecture.png)
4+
5+
This pattern implements a serverless text-to-image generation service using Amazon API Gateway, AWS Lambda and Amazon Bedrock's Nova Canvas model. It provides a REST API endpoint where users can submit text prompts.
6+
7+
This invokes a Lambda function containing the request and the function makes a call to Amazon Bedrock's Nova Canvas model to generate an image based on the text description. Once the image is generated, the Lambda function saves it to an S3 bucket and returns this filename to the user through the API Gateway API.
8+
9+
Learn more about this pattern at Serverless Land Patterns: https://serverlessland.com/patterns/apigw-bedrock-nova-canvas
10+
11+
Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the [AWS Pricing page](https://aws.amazon.com/pricing/) for details. You are responsible for any AWS costs incurred. No warranty is implied in this example.
12+
13+
## Requirements
14+
15+
* [Create an AWS account](https://portal.aws.amazon.com/gp/aws/developer/registration/index.html) if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources.
16+
* [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured
17+
* [Git Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
18+
* [Terraform](https://learn.hashicorp.cxom/tutorials/terraform/install-cli?in=terraform/aws-get-started) installed
19+
* [Amazon Bedrock Nova Canvas Foundation Model Access](https://docs.aws.amazon.com/bedrock/latest/userguide/model-access.html#add-model-access)
20+
21+
## Deployment Instructions
22+
23+
For this pattern, you would need access only to Amazon Nova Canvas foundation model (Model ID: amazon.nova-canvas-v1:0) in us-east-1 region, since the pattern uses us-east-1 region by default.
24+
25+
You must request access to the model before you can use it. If you try to use the model before you have requested access to it, you will receive an error message.
26+
27+
1. Create a new directory, navigate to that directory in a terminal and clone the GitHub repository:
28+
```
29+
git clone https://github.com/aws-samples/serverless-patterns
30+
```
31+
1. Change directory to the pattern directory:
32+
```
33+
cd apigw-bedrock-nova-canvas
34+
```
35+
1. From the command line, initialize terraform to downloads and installs the providers defined in the configuration:
36+
```
37+
terraform init
38+
```
39+
1. From the command line, apply the configuration in the main.tf file:
40+
```
41+
terraform apply
42+
```
43+
1. During the prompts
44+
```
45+
#var.prefix
46+
- Enter a value: {enter any prefix to associate with resources}
47+
```
48+
49+
## Testing
50+
51+
1. Make a POST request to the API using the following cURL command:
52+
53+
```
54+
curl -X POST 'API_ENDPOINT' --header "Content-Type: application/json" --data '{"prompt": "YOUR_PROMPT"}'
55+
```
56+
57+
Note: Replace `API_ENDPOINT` with the generated `api_endpoint` from Terraform (refer to the Terraform Outputs section), "YOUR_PROMPT" with your desired prompt. For ex,
58+
59+
```
60+
curl -X POST 'https://1234abcde.execute-api.us-east-1.amazonaws.com/dev/image_gen' --header "Content-Type: application/json" --data '{"prompt": "Kitten playing the piano"}'
61+
```
62+
63+
1. Once the API Gateway responds with the image ID, you can navigate to the S3 bucket (refer to the Terraform Outputs section for the bucket name) and select the correct image ID to view the generated image.
64+
65+
## Cleanup
66+
67+
1. Change directory to the pattern directory:
68+
```
69+
cd serverless-patterns/apigw-bedrock-nova-canvas
70+
```
71+
72+
1. Delete all created resources
73+
```
74+
terraform destroy
75+
```
76+
77+
1. During the prompts:
78+
```
79+
Enter all details as entered during creation.
80+
```
81+
82+
1. Confirm all created resources has been deleted
83+
```
84+
terraform show
85+
```
86+
----
87+
Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
88+
89+
SPDX-License-Identifier: MIT-0
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
{
2+
"title": "Serverless Text-to-Image Generation with Amazon Bedrock Nova Canvas",
3+
"description": "Serverless text-to-image generation using API Gateway, Lambda and Bedrock's Nova Canvas model for submitting prompts and S3 storage for images.",
4+
"language": "Python",
5+
"level": "200",
6+
"framework": "Terraform",
7+
"introBox": {
8+
"headline": "How it works",
9+
"text": [
10+
"The solution works by receiving a text prompt to an API Gateway endpoint, which triggers a Lambda function containing the request. The Lambda function then formats this prompt and makes a call to Amazon Bedrock's Nova Canvas model to generate an image based on the text description and the generated image is saved to the S3 bucket."
11+
]
12+
},
13+
"gitHub": {
14+
"template": {
15+
"repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/apigw-bedrock-nova-canvas",
16+
"templateURL": "serverless-patterns/apigw-bedrock-nova-canvas",
17+
"projectFolder": "apigw-bedrock-nova-canvas",
18+
"templateFile": "main.tf"
19+
}
20+
},
21+
"resources": {
22+
"bullets": [
23+
{
24+
"text": "Amazon Nova Canvas",
25+
"link": "https://docs.aws.amazon.com/ai/responsible-ai/nova-canvas/overview.html"
26+
},
27+
{
28+
"text": "Invoke Amazon Nova Canvas on Amazon Bedrock to generate an image",
29+
"link": "https://docs.aws.amazon.com/bedrock/latest/userguide/bedrock-runtime_example_bedrock-runtime_InvokeModel_AmazonNovaImageGeneration_section.html"
30+
}
31+
]
32+
},
33+
"deploy": {
34+
"text": ["terraform init", "terraform apply"]
35+
},
36+
"testing": {
37+
"text": ["See the GitHub repo for detailed testing instructions."]
38+
},
39+
"cleanup": {
40+
"text": ["terraform destroy", "terraform show"]
41+
},
42+
"authors": [
43+
{
44+
"name": "Archana V",
45+
"image": "https://media.licdn.com/dms/image/v2/D5603AQGhkVtEhllFEw/profile-displayphoto-shrink_400_400/B56ZZH3LL6H0Ag-/0/1744962369913?e=1750291200&v=beta&t=R0hX6jzWC03OyoWKvYJ0jDDTuPocobPSy0lAJY-3XfA",
46+
"bio": "Solutions Architect at AWS",
47+
"linkedin": "archana-venkat-9b80b7184"
48+
}
49+
],
50+
"patternArch": {
51+
"icon1": {
52+
"x": 20,
53+
"y": 60,
54+
"service": "apigw",
55+
"label": "API Gateway REST API"
56+
},
57+
"icon2": {
58+
"x": 50,
59+
"y": 60,
60+
"service": "lambda",
61+
"label": "AWS Lambda"
62+
},
63+
"icon3": {
64+
"x": 80,
65+
"y": 20,
66+
"service": "bedrock",
67+
"label": "Amazon Bedrock"
68+
},
69+
"icon4": {
70+
"x": 80,
71+
"y": 60,
72+
"service": "s3",
73+
"label": "Amazon S3"
74+
},
75+
"line1": {
76+
"from": "icon1",
77+
"to": "icon2",
78+
"label": ""
79+
},
80+
"line2": {
81+
"from": "icon2",
82+
"to": "icon3",
83+
"label": ""
84+
},
85+
"line3": {
86+
"from": "icon2",
87+
"to": "icon4",
88+
"label": ""
89+
}
90+
}
91+
}
23 KB
Loading
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"title": "Serverless Text-to-Image Generation with Amazon Bedrock Nova Canvas",
3+
"description": "This pattern implements a serverless text-to-image generation service using Amazon API Gateway, AWS Lambda and Amazon Bedrock's Nova Canvas model. It provides a REST API endpoint where users can submit text prompts and receive generated images whic are stored in an S3 bucket.",
4+
"language": "Python",
5+
"level": "200",
6+
"framework": "Terraform",
7+
"introBox": {
8+
"headline": "How it works",
9+
"text": [
10+
"The solution works by receiving a text prompt to an API Gateway endpoint, which triggers a Lambda function containing the request. The Lambda function then formats this prompt and makes a call to Amazon Bedrock's Nova Canvas model to generate an image based on the text description and the generated image is saved to the S3 bucket."
11+
]
12+
},
13+
"gitHub": {
14+
"template": {
15+
"repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/apigw-bedrock-nova-canvas",
16+
"templateURL": "serverless-patterns/apigw-bedrock-nova-canvas",
17+
"projectFolder": "apigw-bedrock-nova-canvas",
18+
"templateFile": "main.tf"
19+
}
20+
},
21+
"resources": {
22+
"bullets": [
23+
{
24+
"text": "Amazon Nova Canvas",
25+
"link": "https://docs.aws.amazon.com/ai/responsible-ai/nova-canvas/overview.html"
26+
},
27+
{
28+
"text": "Invoke Amazon Nova Canvas on Amazon Bedrock to generate an image",
29+
"link": "https://docs.aws.amazon.com/bedrock/latest/userguide/bedrock-runtime_example_bedrock-runtime_InvokeModel_AmazonNovaImageGeneration_section.html"
30+
}
31+
]
32+
},
33+
"deploy": {
34+
"text": [
35+
"terraform init",
36+
"terraform apply"
37+
]
38+
},
39+
"testing": {
40+
"text": [
41+
"See the GitHub repo for detailed testing instructions."
42+
]
43+
},
44+
"cleanup": {
45+
"text": [
46+
"terraform destroy",
47+
"terraform show"
48+
]
49+
},
50+
"authors": [
51+
{
52+
"name": "Archana V",
53+
"image": "https://media.licdn.com/dms/image/v2/D5603AQGhkVtEhllFEw/profile-displayphoto-shrink_400_400/B56ZZH3LL6H0Ag-/0/1744962369913?e=1750291200&v=beta&t=R0hX6jzWC03OyoWKvYJ0jDDTuPocobPSy0lAJY-3XfA",
54+
"bio": "Solutions Architect at AWS",
55+
"linkedin": "archana-venkat-9b80b7184"
56+
}
57+
]
58+
}
1.38 KB
Binary file not shown.

0 commit comments

Comments
 (0)