-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yaml
76 lines (71 loc) · 2.13 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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
Bedrock Access Gateway (OpenAI API Schema) with FastAPI on AWS Lambda,
exposed as a public API with AWS Lambda Function URL.
Parameters:
ApiKey:
Type: String
Description: "API Key to be used in the Authorization header"
MinLength: 1
# NoEcho: true
Globals:
Function:
MemorySize: 512
Timeout: 150
Resources:
BedrockAccessGatewayLayer:
Type: AWS::Serverless::LayerVersion
Properties:
ContentUri: layer/
CompatibleRuntimes:
- python3.12
CompatibleArchitectures:
- x86_64
Metadata:
BuildMethod: python3.12
BedrockAccessGatewayFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: app/
Handler: run.sh
Runtime: python3.12
Architectures:
- x86_64
Environment:
Variables:
API_KEY: !Ref ApiKey
AWS_LAMBDA_EXEC_WRAPPER: /opt/bootstrap
AWS_LWA_INVOKE_MODE: RESPONSE_STREAM
# Align with `app/api/app.py` in the `uvicorn.run` line
AWS_LWA_PORT: 8000
# DEBUG: 'true'
DEFAULT_MODEL: 'amazon.nova-micro-v1:0'
ENABLE_CROSS_REGION_INFERENCE: 'true'
Layers:
- !Ref BedrockAccessGatewayLayer
- !Sub arn:aws:lambda:${AWS::Region}:753240598075:layer:LambdaAdapterLayerX86:23
FunctionUrlConfig:
AuthType: NONE
InvokeMode: RESPONSE_STREAM
Policies:
- Statement:
- Action:
- bedrock:ListFoundationModels
- bedrock:ListInferenceProfiles
Effect: Allow
Resource: "*"
- Action:
- bedrock:InvokeModel
- bedrock:InvokeModelWithResponseStream
Effect: Allow
Resource:
- arn:aws:bedrock:*::foundation-model/*
- arn:aws:bedrock:*:*:inference-profile/*
Outputs:
FunctionUrl:
Description: "Function URL for FastAPI function"
Value: !GetAtt BedrockAccessGatewayFunctionUrl.FunctionUrl
Function:
Description: "FastAPI Lambda Function ARN"
Value: !GetAtt BedrockAccessGatewayFunction.Arn