generated from amazon-archives/__template_MIT-0
-
Notifications
You must be signed in to change notification settings - Fork 1k
Pushing new pattern code to serveless-patterns #2511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
julianwood
merged 13 commits into
aws-samples:main
from
Monalisu:Monalisu-feature-lambda-bedrock-dynamodb-sam
Dec 10, 2024
Merged
Pushing new pattern code to serveless-patterns #2511
julianwood
merged 13 commits into
aws-samples:main
from
Monalisu:Monalisu-feature-lambda-bedrock-dynamodb-sam
Dec 10, 2024
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ellisms
requested changes
Dec 2, 2024
Contributor
ellisms
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Monalisu thanks for the submission. Requesting a few changes.
Co-authored-by: ellisms <114107920+ellisms@users.noreply.github.com>
Co-authored-by: ellisms <114107920+ellisms@users.noreply.github.com>
Co-authored-by: ellisms <114107920+ellisms@users.noreply.github.com>
Co-authored-by: ellisms <114107920+ellisms@users.noreply.github.com>
Co-authored-by: ellisms <114107920+ellisms@users.noreply.github.com>
implemented suggested changes.
Contributor
Author
|
Hi @***@***.***> ,
Thank you for the suggestions and help . I have implemented the changes mentioned . Let me know if anything else to be done from my side .
Warm regards,
Monalisa Nath
Solutions Architect, Field-AGS-India-ENT-CS
Amazon Web Services
Thoughts on our interaction? Provide feedback here<https://feedback.aws.amazon.com/?ea=monalisu&fn=Monalisa&ln=Nath>
From: ellisms ***@***.***>
Reply to: aws-samples/serverless-patterns ***@***.***>
Date: Monday, 2 December 2024 at 10:37 PM
To: aws-samples/serverless-patterns ***@***.***>
Cc: "Nath, Monalisa" ***@***.***>, Mention ***@***.***>
Subject: Re: [aws-samples/serverless-patterns] Pushing new pattern code to serveless-patterns (PR #2511)
@ellisms requested changes on this pull request.
Hi @Monalisu<https://github.com/Monalisu> thanks for the submission. Requesting a few changes.
________________________________
In lambda-bedrock-dynamodb-sam/src/app.py<#2511 (comment)>:
@@ -0,0 +1,33 @@
+import json
+import boto3
+import os
+
+bedrock = boto3.client('bedrock-runtime')
+dynamodb = boto3.resource('dynamodb')
+table_name = os.environ['table_name']
+
+model_id = "anthropic.claude-3-haiku-20240307-v1:0"
Recommend making this an environment variable so user can easily change model without changing code.
________________________________
In lambda-bedrock-dynamodb-sam/README.md<#2511 (comment)>:
@@ -0,0 +1,162 @@
+# Amazon Bedrock to Amazon DynamoDB
+
+This pattern demonstrates how to use AWS Lambda to process queries using Amazon Bedrock's Claude 3 Haiku model and store the results in Amazon DynamoDB.
⬇️ Suggested change
-This pattern demonstrates how to use AWS Lambda to process queries using Amazon Bedrock's Claude 3 Haiku model and store the results in Amazon DynamoDB.
+This pattern demonstrates how to use AWS Lambda to process queries using Amazon Bedrock's Claude 3 Haiku model and store the conversation results in Amazon DynamoDB.
________________________________
In lambda-bedrock-dynamodb-sam/README.md<#2511 (comment)>:
@@ -0,0 +1,162 @@
+# Amazon Bedrock to Amazon DynamoDB
+
+This pattern demonstrates how to use AWS Lambda to process queries using Amazon Bedrock's Claude 3 Haiku model and store the results in Amazon DynamoDB.
+This pattern helps the system to persist the conversation with the model in DynamoDB which is a NoSQL database offering from AWS
⬇️ Suggested change
-This pattern helps the system to persist the conversation with the model in DynamoDB which is a NoSQL database offering from AWS
________________________________
In lambda-bedrock-dynamodb-sam/README.md<#2511 (comment)>:
+# Amazon Bedrock to Amazon DynamoDB
+
+This pattern demonstrates how to use AWS Lambda to process queries using Amazon Bedrock's Claude 3 Haiku model and store the results in Amazon DynamoDB.
+This pattern helps the system to persist the conversation with the model in DynamoDB which is a NoSQL database offering from AWS
+
+Learn more about this pattern at Serverless Land Patterns: [Serverless Land](https://serverlessland.com/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](https://aws.amazon.com/pricing/) for details. You are responsible for any AWS costs incurred. No warranty is implied in this example.
+
+## Requirements
+
+* [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.
+* [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured
+* [Git Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
+* [AWS Serverless Application Model](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) (AWS SAM) installed
+
Add a prerequisite for Bedrock model access.
________________________________
In lambda-bedrock-dynamodb-sam/README.md<#2511 (comment)>:
+
+* [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.
+* [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured
+* [Git Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
+* [AWS Serverless Application Model](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) (AWS SAM) installed
+
+## Deployment Instructions
+
+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/lambda-bedrock-dynamodb-sam
+
+ ```
+1. Change directory to the pattern directory:
+ ```
+ cd bedrock-to-dynamodb
⬇️ Suggested change
- cd bedrock-to-dynamodb
+ cd lambda-bedrock-dynamodb-sam
________________________________
In lambda-bedrock-dynamodb-sam/README.md<#2511 (comment)>:
+ ```
+1. Change directory to the pattern directory:
+ ```
+ cd bedrock-to-dynamodb
+ ```
+1. From the command line, use AWS SAM to deploy the AWS resources for the pattern as specified in the template.yml file:
+ ```
+ sam deploy --guided
+ ```
+1. During the prompts:
+ * Enter a stack name
+ * Enter the desired AWS Region
+ * Enter a name for your DynamoDB table
+ * Allow SAM CLI to create IAM roles with the required permissions.
+
+ Once you have run `sam deploy --guided` mode once and saved arguments to a configuration file (samconfig.toml), you can use `sam deploy` in future to use these defaults.
⬇️ Suggested change
- Once you have run `sam deploy --guided` mode once and saved arguments to a configuration file (samconfig.toml), you can use `sam deploy` in future to use these defaults.
+ After the first run of `sam deploy --guided` and saving the arguments to a configuration file (samconfig.toml), you can use `sam deploy` in future to use these defaults.
________________________________
In lambda-bedrock-dynamodb-sam/README.md<#2511 (comment)>:
+ * Enter a name for your DynamoDB table
+ * Allow SAM CLI to create IAM roles with the required permissions.
+
+ Once you have run `sam deploy --guided` mode once and saved arguments to a configuration file (samconfig.toml), you can use `sam deploy` in future to use these defaults.
+
+1. Note the outputs from the SAM deployment process. These contain the resource names and/or ARNs which are used for testing.
+
+## How it works
+
+This pattern creates a Lambda function that uses Amazon Bedrock's Claude 3 Haiku model to process queries. The function then stores both the query and the response in a DynamoDB table. The Lambda function is triggered by an event containing a 'query' key, processes the query using Bedrock, and stores the result in DynamoDB.
+
+## Testing
+
+1. Invoke the Lambda function with a test event containing a query:
+ ```bash
+ aws lambda invoke --function-name lambda-processor --payload '{"query": "What is the capital of France?"}' output.txt
⬇️ Suggested change
- aws lambda invoke --function-name lambda-processor --payload '{"query": "What is the capital of France?"}' output.txt
+ aws lambda invoke --function-name lambda-processor --cli-binary-format raw-in-base64-out --payload '{"query": "What is the capital of France?"}' output.txt
________________________________
In lambda-bedrock-dynamodb-sam/README.md<#2511 (comment)>:
+1. Invoke the Lambda function with a test event containing a query:
+ ```bash
+ aws lambda invoke --function-name lambda-processor --payload '{"query": "What is the capital of France?"}' output.txt
+ ```
+2. Check the DynamoDB table to see the stored query and response:
+ ```bash
+ aws dynamodb scan --table-name YOUR_TABLE_NAME
+ ```
+
+Replace `YOUR_TABLE_NAME` with the actual name of your DynamoDB table.
+
+## Cleanup
+
+1. Delete the stack
+ ```bash
+ aws cloudformation delete-stack --stack-name STACK_NAME
⬇️ Suggested change
- aws cloudformation delete-stack --stack-name STACK_NAME
+sam delete
________________________________
In lambda-bedrock-dynamodb-sam/README.md<#2511 (comment)>:
+## Cleanup
+
+1. Delete the stack
+ ```bash
+ aws cloudformation delete-stack --stack-name STACK_NAME
+ ```
+1. Confirm the stack has been deleted
+ ```bash
+ aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'STACK_NAME')].StackStatus"
+ ```
+----
+Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+
+SPDX-License-Identifier: MIT-0# Bedrock and DynamoDB Integration
+
+This project demonstrates an AWS SAM (Serverless Application Model) application that integrates Amazon Bedrock with Amazon DynamoDB. It creates a Lambda function that processes queries using Bedrock's Claude 3 Haiku model and stores the results in a DynamoDB table.
From here to the end seems to be significant duplication of earlier sections. I would remove this content.
________________________________
In lambda-bedrock-dynamodb-sam/template.yaml<#2511 (comment)>:
@@ -0,0 +1,78 @@
+AWSTemplateFormatVersion: '2010-09-09'
+Transform: AWS::Serverless-2016-10-31
+Description: >
+ Sam for Bedrock and Dynamodb pattern
⬇️ Suggested change
- Sam for Bedrock and Dynamodb pattern
+ Sam for Bedrock and Dynamodb pattern (uksb-1tthgi812) (tag:lambda-bedrock-dynamodb-sam)
________________________________
In lambda-bedrock-dynamodb-sam/template.yaml<#2511 (comment)>:
+ KeyType: HASH
+ ProvisionedThroughput:
+ ReadCapacityUnits: 1
+ WriteCapacityUnits: 1
+
+ # Creates Lambda function
+
+ InvokeBedrock:
+ Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
+ Properties:
+ FunctionName: lambda-processor
+ CodeUri: src/
+ Handler: app.lambda_handler
+ Environment:
+ Variables:
+ table_name: !Ref Outputtable
add a variable for model name so users can easily test different models.
—
Reply to this email directly, view it on GitHub<#2511 (review)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/BM3MT6YJ7NNQZSBQTNVAE5L2DSHVDAVCNFSM6AAAAABRYNW5IOVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDINZTGI3TEMZZG4>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
ellisms
reviewed
Dec 4, 2024
Contributor
|
Thanks @Monalisu. I'll add this to the publishing queue. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue #, if available:
New serverless pattern - Lambda-bedrock-dynamodb-sam
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.