-
Notifications
You must be signed in to change notification settings - Fork 0
/
cft.yaml
101 lines (90 loc) · 2.7 KB
/
cft.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
98
99
100
101
AWSTemplateFormatVersion: '2010-09-09'
Description: Lambda Embedding service
Parameters:
ImageUri:
Type: String
Description: URI of service image
Resources:
Role:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Path: /lambda/execution/sentence-embeddings/
ManagedPolicyArns:
- !Sub arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
Function:
Type: AWS::Lambda::Function
Properties:
FunctionName: sentence-embeddings
Role: !GetAtt Role.Arn
PackageType: Image
MemorySize: 4096
Timeout: 30
Code:
ImageUri: !Ref ImageUri
KeepWarmInvokePermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !GetAtt Function.Arn
Action: lambda:InvokeFunction
Principal: events.amazonaws.com
SourceArn: !GetAtt KeepWarm.Arn
KeepWarm:
Type: AWS::Events::Rule
Properties:
Description: Keep warm for lambda function
Name: sentence-embeddings-keepwarm
ScheduleExpression: rate(4 minutes)
Targets:
- Arn: !GetAtt Function.Arn
Id: SentenceEmbeddingsKeepWarm
Input: '{"crid":1,"sentences":["This event spits hot fire to keep the function warm!"]}'
ApiGateWayInvokePermission:
Type: AWS::Lambda::Permission
Properties:
Action: lambda:InvokeFunction
FunctionName: !Sub ${Function.Arn}
Principal: apigateway.amazonaws.com
SourceArn: !Sub 'arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${RestApi}/*'
RestApi:
Type: AWS::ApiGateway::RestApi
Properties:
Name: sentence-embeddings-gateway
Description: Sentence Embeddings API
ProxyResource:
Type: AWS::ApiGateway::Resource
Properties:
ParentId: !GetAtt RestApi.RootResourceId
RestApiId: !Ref RestApi
PathPart: encode
ProxyMethod:
Type: AWS::ApiGateway::Method
Properties:
AuthorizationType: NONE
ApiKeyRequired: true
HttpMethod: ANY
Integration:
IntegrationHttpMethod: POST
Type: AWS_PROXY
IntegrationResponses:
- StatusCode: 200
Uri: !Sub
- arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${lambdaArn}/invocations
- lambdaArn: !GetAtt Function.Arn
ResourceId: !Ref ProxyResource
RestApiId: !Ref RestApi
ApiDeployment:
Type: AWS::ApiGateway::Deployment
DependsOn:
- ProxyMethod
Properties:
RestApiId: !Ref RestApi
StageName: api