This pattern demonstrates how to create a serverless API leveraging Amazon Bedrock Nova Micro through AWS Lambda. The solution uses an Amazon API Gateway REST endpoint to process requests and return AI-generated responses using Nova Micro's text-to-text capabilities.
Learn more about this pattern at Serverless Land Patterns.
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 for details. You are responsible for any AWS costs incurred. No warranty is implied in this example.
- Create an AWS account 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.
- Enable Access To Nova Models and follow item 2 under the Prerequisites to request access to Amazon Nova Micro model
- AWS CLI installed and configured
- Git Installed
- Terraform installed
-
Clone the project to your local working directory
git clone https://github.com/aws-samples/serverless-patterns/
-
Change the working directory to this pattern's directory
cd serverless-patterns/apigw-lambda-bedrock-nova-terraform
-
From the command line, run each of the command mentioned in the create_lambda_layer.sh file, this file contains the commands to create the Lambda Layer as well zip the bedrock_integration.py which invokes the Amazon Nova model.
-
From the command line, initialize terraform to to downloads and installs the providers defined in the configuration:
terraform init
-
From the command line, apply the configuration in the main.tf file:
terraform apply
-
During the prompts:
- Enter yes
The pattern creates an API Gateway endpoint that accepts POST requests containing prompts. These requests are forwarded to a Lambda function which processes the input and interacts with Amazon Bedrock's Nova Micro model.
Key components:
- API Gateway REST API endpoint
- Lambda function with Nova Micro integration
- IAM roles and policies for Lambda and Bedrock access
- Lambda layer for boto3 dependencies
- Nova Micro Request Format:
{ "system": [ { "text": "You are a helpful AI assistant that provides accurate and concise information." } ], "messages": [ { "role": "user", "content": [ { "text": "<your-prompt>" } ] } ], "inferenceConfig": { "maxTokens": 1024, "temperature": 0.7, "topP": 0.9, "topK": 50, "stopSequences": [] } }
Using Curl:
```
curl -X POST \
-H "Content-Type: application/json" \
-d '{"prompt": "What are the key benefits of using AWS services?"}' \
https://YOUR-API-ENDPOINT/dev/generate_content
```
{
"generated-text": "<Model generated response>"
}
-
Change directory to the pattern directory:
cd serverless-patterns/apigw-lambda-bedrock-nova-terraform
-
Delete all created resources
terraform destroy
-
During the prompts:
- Enter yes
-
Confirm all created resources has been deleted
terraform show
Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: MIT-0