Task 3: Build a Serverless Backend
In this task, you will use AWS Amplify and AWS Lambda to build a serverless function
Introduction
Implementation
Create a Lambda function for handling requests
1. Create a Lambda function
On your local machine, navigate to the ai-recipe-generator/amplify/data folder, and create a file named bedrock.js.

2. Add the function code
Then, update the file with the following code:
The following code defines a request function that constructs the HTTP request to invoke the Claude 3 Sonnet foundation model in Amazon Bedrock. The response function parses the response and returns the generated recipe.
Bedrock Lambda function code
Add this code to your bedrock.js file
Add Amazon Bedrock as a data source
2. Update the backend file
Update the amplify/backend.ts file with the following code. Then, save the file.
The code adds an HTTP data source for Amazon Bedrock to your API and grant it permissions to invoke the Claude model.

Backend code
Add this code to your backend.ts file
Conclusion
You have defined a Lambda function using Amplify, and added Amazon Bedrock as an HTTP data source.
Deploy the Backend API
Start Task FourDid you find what you were looking for today?
Let us know so we can improve the quality of the content on our pages