-
Notifications
You must be signed in to change notification settings - Fork 135
Add Bedrock Agent example #357
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
Conversation
Properties: | ||
PackageType: Image | ||
MemorySize: 256 | ||
Policies: arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess |
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.
Here you can use policy name:
Policies: AmazonS3ReadOnlyAccess
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.
fixed
Metadata: | ||
Dockerfile: Dockerfile | ||
DockerContext: ./app | ||
DockerTag: python3.12-v1 |
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.
You need to configure resource policy to allow Bedrock service to invoke this lambda function. And output the function arn will be useful.
BedrockAgentPermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref BedrockAgentFastAPIFunction
Action: lambda:InvokeFunction
Principal: bedrock.amazonaws.com
SourceAccount: !Ref 'AWS::AccountId'
SourceArn: !Sub arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:agent/*
Outputs:
BedrockAgentFastAPIFunction:
Description: "BedrockAgentFastAPIFunction Lambda Function ARN"
Value: !GetAtt BedrockAgentFastAPIFunction.Arn
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.
added your reccomend code
Create a bedrock agent. (see [reference](https://docs.aws.amazon.com/bedrock/latest/userguide/agents-create.html | ||
)) | ||
|
||
## Test |
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.
Before testing, we should show how to get the openapi spec from the FastAPI.
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.
add "Generate OpenAPI schema" section
|
||
Test your agent. (see [reference](https://docs.aws.amazon.com/bedrock/latest/userguide/agents-test.html)) | ||
|
||
## Run the docker locally |
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.
This section could be removed and replaced with how to use sam local invoke
to test locally the agent function with event payloads in the events directory.
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.
remove "Run the docker locally" section.
add "Test locally" section.
Type: AWS::Serverless::Function | ||
Properties: | ||
PackageType: Image | ||
MemorySize: 256 |
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.
256 is a bit slow. Increase it to 1024.
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.
fixed
@@ -0,0 +1,8 @@ | |||
FROM public.ecr.aws/docker/library/python:3.12.0-slim | |||
COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:0.8.1 /lambda-adapter /opt/extensions/lambda-adapter | |||
ENV PORT=8000 |
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.
Add AWS_LWA_READINESS_CHECK_PROTOCOL=tcp
to use TCP connect for healthcheck
ENV PORT=8000 AWS_LWA_READINESS_CHECK_PROTOCOL=tcp
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.
fixed
* Update Dockerfile - add `AWS_LWA_READINESS_CHECK_PROTOCOL` env * Update template.yaml - change `MemorySize` 256 to 1024 - fix Policies define `arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess` to `AmazonS3ReadOnlyAccess` - add BedrockAgentPermission - add Output * Update README.md - update Dockerfile - add "Generate OpenAPI schema", "Create an agent.", "Test locally" section. - remove "Run the docker locally" section.
Thanks for the contribution! |
#317
Add Bedrock Agent example