Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions apigw-bedrock-nova-canvas/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ Important: this application uses various AWS services and there are costs associ

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.

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.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


1. Create a new directory, navigate to that directory in a terminal and clone the GitHub repository:
```
git clone https://github.com/aws-samples/serverless-patterns
Expand Down Expand Up @@ -86,4 +84,4 @@ You must request access to the model before you can use it. If you try to use th
----
Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.

SPDX-License-Identifier: MIT-0
SPDX-License-Identifier: MIT-0
20 changes: 10 additions & 10 deletions apigw-bedrock-nova-canvas/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ resource "random_string" "suffix" {

# Create Lambda layer for Pillow from provided zip file
resource "aws_lambda_layer_version" "pillow_layer" {
filename = "pillow.zip" # Make sure this zip file exists in your terraform directory
layer_name = "pillow_layer"
filename = "pillow.zip" # Make sure this zip file exists in your terraform directory
layer_name = "pillow_layer"
compatible_runtimes = ["python3.11"]
description = "Pillow library layer for image processing"
description = "Pillow library layer for image processing"
}

# IAM Policy for invoking Bedrock model
Expand All @@ -36,7 +36,7 @@ resource "aws_iam_policy" "invoke_model_policy" {
]
Effect = "Allow"
Resource = [
"arn:aws:bedrock:${data.aws_region.current.name}::foundation-model/amazon.nova-canvas-v1:0"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name - (Optional, Deprecated) Full name of the region to select. Use region instead.
https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region

"arn:aws:bedrock:${data.aws_region.current.region}::foundation-model/amazon.nova-canvas-v1:0"
]
},
]
Expand All @@ -45,23 +45,23 @@ resource "aws_iam_policy" "invoke_model_policy" {

# S3 bucket for storing images
resource "aws_s3_bucket" "image_bucket" {
bucket = "${lower(var.prefix)}-image-bucket-${random_string.suffix.result}"
bucket = "${lower(var.prefix)}-image-bucket-${random_string.suffix.result}"
force_destroy = true
}

# Create CloudWatch Log Group for Lambda
resource "aws_cloudwatch_log_group" "lambda_log_group" {
name = "/aws/lambda/${lower(var.prefix)}-invoke-bedrock"
retention_in_days = 14

lifecycle {
prevent_destroy = false
}
}

# Lambda function
resource "aws_lambda_function" "invoke_bedrock_function" {
filename = "index.zip" # Replace with your Lambda code zip file
filename = "index.zip" # Replace with your Lambda code zip file
function_name = "${lower(var.prefix)}-invoke-bedrock"
role = aws_iam_role.lambda_role.arn
handler = "index.handler"
Expand Down Expand Up @@ -146,7 +146,7 @@ resource "aws_api_gateway_integration" "lambda_integration" {
# API Gateway Deployment
resource "aws_api_gateway_deployment" "api_deployment" {
rest_api_id = aws_api_gateway_rest_api.bedrock_api.id

depends_on = [
aws_api_gateway_integration.lambda_integration
]
Expand Down Expand Up @@ -176,12 +176,12 @@ output "lambda_function" {

output "api_endpoint" {
description = "The API Gateway endpoint URL "
value = "${aws_api_gateway_stage.api_stage.invoke_url}/image_gen"
value = "${aws_api_gateway_stage.api_stage.invoke_url}/image_gen"
}

output "s3_image_bucket" {
description = "The Output S3 bucket is "
value = aws_s3_bucket.image_bucket.id
value = aws_s3_bucket.image_bucket.id
}

# Data source for current region
Expand Down