-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemplate.yaml
159 lines (140 loc) · 3.83 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: AlexaSkill with ChatGPT
Globals:
Function:
Tags:
Project: Alexa-ChatGPT
Timeout: 300
Environment:
Variables:
RESPONSES_QUEUE_URI: !Ref ResponsesQueue
REQUESTS_QUEUE_URI: !Ref RequestsQueue
OPENAI_API_KEY: !Ref OpenAIApiKey
GEMINI_API_KEY: !Ref GeminiApiKey
POLL_DELAY: 7
CLOUDFLARE_ACCOUNT_ID: !Ref CloudFlareAccountId
CLOUDFLARE_API_KEY: !Ref CloudFlareAPIKey
S3_BUCKET: !Ref Bucket
Parameters:
OpenAIApiKey:
Type: String
Description: OpenAI API Key
GeminiApiKey:
Type: String
Description: Google Service Account JSON B64
CloudFlareAccountId:
Type: String
Description: Cloudflare Account Id
CloudFlareAPIKey:
Type: String
Description: Cloudflare API key
Runtime:
Type: String
Default: go1.x
Architecture:
Type: String
Default: "x86_64"
Handler:
Type: String
Default: main
Resources:
Bucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub ${AWS::StackName}-contents
CorsConfiguration:
CorsRules:
- AllowedHeaders:
- "*"
AllowedMethods:
- GET
AllowedOrigins:
- "http://ask-ifr-download.s3.amazonaws.com"
- "https://ask-ifr-download.s3.amazonaws.com"
RequestsQueue:
Type: 'AWS::SQS::Queue'
Properties:
QueueName: !Sub ${AWS::StackName}-Requests
RedrivePolicy:
maxReceiveCount: 5
deadLetterTargetArn: !GetAtt RequestsDLQ.Arn
VisibilityTimeout: 301
RequestsDLQ:
Type: 'AWS::SQS::Queue'
Properties:
QueueName: !Sub ${AWS::StackName}-Requests-DLQ
ResponsesQueue:
Type: 'AWS::SQS::Queue'
Properties:
QueueName: !Sub ${AWS::StackName}-Responses
VisibilityTimeout: 301
ChatGPTFunction:
Type: AWS::Serverless::Function
Properties:
Runtime: !Ref Runtime
Handler: !Ref Handler
Architectures:
- !Ref Architecture
FunctionName: chatGPT
CodeUri: ./cmd/alexa
Events:
AlexaSkillEvent:
Type: AlexaSkill
Policies:
- SQSPollerPolicy:
QueueName:
!GetAtt ResponsesQueue.QueueName
- SQSSendMessagePolicy:
QueueName:
!GetAtt RequestsQueue.QueueName
- Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- sqs:PurgeQueue
Resource:
- !GetAtt RequestsQueue.Arn
- !GetAtt ResponsesQueue.Arn
Metadata:
BuildMethod: go1.x
ChatGPTRequests:
Type: AWS::Serverless::Function
Properties:
ReservedConcurrentExecutions: 1
Runtime: !Ref Runtime
Handler: !Ref Handler
Architectures:
- !Ref Architecture
FunctionName: chatGPTRequests
CodeUri: ./cmd/sqs
Events:
MySQSEvent:
Type: SQS
Properties:
Queue: !GetAtt RequestsQueue.Arn
BatchSize: 1
Policies:
- SQSSendMessagePolicy:
QueueName:
!GetAtt ResponsesQueue.QueueName
- S3CrudPolicy:
BucketName: !Ref Bucket
Metadata:
BuildMethod: go1.x
Outputs:
ChatGPTLambdaArn:
Description: "chatGPT alexa skill lambda ARN"
Value: !GetAtt ChatGPTFunction.Arn
ChatGPTRequestsArn:
Description: "chatGPT requests handling lambda ARN"
Value: !GetAtt ChatGPTRequests.Arn
RequestsQueue:
Description: "chatGPT prompt requests queue"
Value: !GetAtt RequestsQueue.Arn
RequestsDLQ:
Description: "chatGPT prompt requests dead letter queue"
Value: !GetAtt RequestsDLQ.Arn
ResponsesQueue:
Description: "chatGPT responses queue"
Value: !GetAtt ResponsesQueue.Arn