Add Bedrock Agent example#357
Conversation
| Properties: | ||
| PackageType: Image | ||
| MemorySize: 256 | ||
| Policies: arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess |
There was a problem hiding this comment.
Here you can use policy name:
Policies: AmazonS3ReadOnlyAccess| Metadata: | ||
| Dockerfile: Dockerfile | ||
| DockerContext: ./app | ||
| DockerTag: python3.12-v1 |
There was a problem hiding this comment.
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.ArnThere was a problem hiding this comment.
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.
Before testing, we should show how to get the openapi spec from the FastAPI.
There was a problem hiding this comment.
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.
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.
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.
256 is a bit slow. Increase it to 1024.
| @@ -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.
Add AWS_LWA_READINESS_CHECK_PROTOCOL=tcp to use TCP connect for healthcheck
ENV PORT=8000 AWS_LWA_READINESS_CHECK_PROTOCOL=tcp* 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