-
Notifications
You must be signed in to change notification settings - Fork 126
/
Copy pathtemplate.yaml
97 lines (89 loc) · 3.18 KB
/
template.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
bedrock-agent-fastapi
FastAPI app that work with Agents for Amazon Bedrock
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 60
Resources:
BedrockAgentFastAPIFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: ./app
Runtime: python3.12
Handler: run.sh
MemorySize: 1024
Environment:
Variables:
AWS_LAMBDA_EXEC_WRAPPER: /opt/bootstrap
AWS_LWA_READINESS_CHECK_PROTOCOL: TCP
PORT: 8000
Layers:
- !Sub arn:aws:lambda:${AWS::Region}:753240598075:layer:LambdaAdapterLayerX86:24
Policies: AmazonS3ReadOnlyAccess
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/*
BedrockAgentResourceRole:
Type: AWS::IAM::Role
Properties:
RoleName: AmazonBedrockExecutionRoleForAgents_FastAPISample
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service: bedrock.amazonaws.com
Action: sts:AssumeRole
Condition:
StringEquals:
aws:SourceAccount: !Sub ${AWS::AccountId}
ArnLike:
aws:SourceArn: !Sub arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:agent/*
Policies:
- PolicyName: AmazonBedrockExecutionRoleForAgents_FastAPISamplePolicy
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action: bedrock:InvokeModel
Resource: !Sub arn:aws:bedrock:${AWS::Region}::foundation-model/anthropic.claude-v2:1
- Effect: Allow
Action: lambda:InvokeFunction
Resource: !GetAtt BedrockAgentFastAPIFunction.Arn
BedrockAgent:
Type: AWS::Bedrock::Agent
Properties:
AgentName: BedrockAgentFastAPISample
Description: Query S3 information agent.
AgentResourceRoleArn: !GetAtt BedrockAgentResourceRole.Arn
Instruction: This agent allows you to query the S3 information in your AWS account.
FoundationModel: anthropic.claude-v2:1
ActionGroups:
- ActionGroupName: action-group
ActionGroupExecutor:
Lambda: !GetAtt BedrockAgentFastAPIFunction.Arn
ApiSchema:
Payload: '<<Open API schema>>'
BedrockAgentRelease:
Type: AWS::Bedrock::AgentAlias
Properties:
AgentAliasName: v1
AgentId: !Ref BedrockAgent
Outputs:
BedrockAgentFastAPIFunction:
Description: "BedrockAgentFastAPIFunction Lambda Function ARN"
Value: !GetAtt BedrockAgentFastAPIFunction.Arn
BedrockAgent:
Description: "BedrockAgent ID"
Value: !Ref BedrockAgent
BedrockAgentAlias:
Description: "BedrockAgentAlias ID"
Value: !Ref BedrockAgentRelease