-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtemplate.yaml
More file actions
179 lines (168 loc) · 5.46 KB
/
template.yaml
File metadata and controls
179 lines (168 loc) · 5.46 KB
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: HackOverflow Backend API
Parameters:
DatabaseURL:
Type: String
Description: Database connection URL
NoEcho: true
SecretKey:
Type: String
Description: JWT secret key
NoEcho: true
FrontendURL:
Type: String
Description: Frontend URL for CORS
Default: "https://hackoverflow.srkrcodingclub.in"
CloudinaryCloudName:
Type: String
Description: Cloudinary Cloud Name
CloudinaryAPIKey:
Type: String
Description: Cloudinary API Key
NoEcho: true
CloudinaryAPISecret:
Type: String
Description: Cloudinary API Secret
NoEcho: true
EmailUser:
Type: String
Description: Email username for sending emails
NoEcho: true
EmailPass:
Type: String
Description: Email password for sending emails
NoEcho: true
FromEmail:
Type: String
Description: From email address for sending emails
ReSendApiKey:
Type: String
Description: Resend API Key for sending emails
NoEcho: true
Resources:
# REST API Gateway with explicit stage configuration
HackOverflowRestApi:
Type: AWS::Serverless::Api
Properties:
StageName: prod
Cors:
AllowOrigin: !Sub "'${FrontendURL}'"
AllowHeaders: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token,Accept,Accept-Encoding,Accept-Language,Cache-Control,Connection,Host,Origin,Pragma,Referer,User-Agent,X-Requested-With'"
AllowMethods: "'GET,POST,PUT,DELETE,PATCH,OPTIONS'"
AllowCredentials: true
BinaryMediaTypes:
- "multipart/form-data"
- "image/*"
- "application/octet-stream"
HackOverflowAPI:
Type: AWS::Serverless::Function
Properties:
PackageType: Image
Architectures: [x86_64]
MemorySize: 1024
Timeout: 30
Environment:
Variables:
NODE_ENV: production
DATABASE_URL: !Ref DatabaseURL
SECRET_KEY: !Ref SecretKey
FRONTEND_URL: !Ref FrontendURL
CLOUDINARY_CLOUD_NAME: !Ref CloudinaryCloudName
CLOUDINARY_API_KEY: !Ref CloudinaryAPIKey
CLOUDINARY_API_SECRET: !Ref CloudinaryAPISecret
EMAIL_USER: !Ref EmailUser
EMAIL_PASS: !Ref EmailPass
FROM_EMAIL: !Ref FromEmail
RESEND_API_KEY: !Ref ReSendApiKey
EMAIL_QUEUE_URL: !Ref HackOverflowEmailQueue
AWS_LAMBDA_NODEJS_DISABLE_CALLBACK_WARNING: true
Policies:
Statement:
- Effect: Allow
Action:
- firehose:PutRecord
- firehose:PutRecordBatch
- sqs:SendMessage
Resource:
- arn:aws:firehose:ap-south-1:161266029104:deliverystream/hackoverflow-audit-log-stream
- !GetAtt HackOverflowEmailQueue.Arn
Events:
ApiEvent:
Type: Api
Properties:
RestApiId: !Ref HackOverflowRestApi
Path: /{proxy+}
Method: ANY
RootEvent:
Type: Api
Properties:
RestApiId: !Ref HackOverflowRestApi
Path: /
Method: ANY
Metadata:
Dockerfile: Dockerfile
DockerContext: ./
DockerTag: nodejs20.x-v1
FirehoseRole:
Type: AWS::IAM::Role
Properties:
RoleName: hackoverflow-audit-firehose-role
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service: firehose.amazonaws.com
Action: sts:AssumeRole
Path: "/"
Policies:
- PolicyName: FirehoseS3AndKMS
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- s3:PutObject
- s3:PutObjectAcl
- s3:AbortMultipartUpload
- s3:GetBucketLocation
- s3:ListBucket
Resource:
- arn:aws:s3:::hackoverflow-audit-logs-prod-ap-south-1
- arn:aws:s3:::hackoverflow-audit-logs-prod-ap-south-1/*
- Effect: Allow
Action:
- kms:GenerateDataKey
- kms:Encrypt
Resource:
- arn:aws:kms:ap-south-1:161266029104:key/aa69749c-3817-4b52-b3ef-a1ece512d06d
AuditFirehose:
Type: AWS::KinesisFirehose::DeliveryStream
Properties:
DeliveryStreamName: hackoverflow-audit-log-stream
DeliveryStreamType: DirectPut
S3DestinationConfiguration:
BucketARN: arn:aws:s3:::hackoverflow-audit-logs-prod-ap-south-1
RoleARN: !GetAtt FirehoseRole.Arn
Prefix: "audit_logs/date=!{timestamp:yyyy-MM-dd}/"
ErrorOutputPrefix: "audit_logs/dlq/!{firehose:error-output-type}/"
BufferingHints:
SizeInMBs: 64
IntervalInSeconds: 300
CompressionFormat: GZIP
EncryptionConfiguration:
KMSEncryptionConfig:
AWSKMSKeyARN: arn:aws:kms:ap-south-1:161266029104:key/aa69749c-3817-4b52-b3ef-a1ece512d06d
HackOverflowEmailQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: hackoverflow-email-queue
VisibilityTimeout: 60
Outputs:
ApiUrl:
Description: "REST API Gateway endpoint URL for prod stage"
Value: !Sub "https://${HackOverflowRestApi}.execute-api.${AWS::Region}.amazonaws.com/prod"
ApiId:
Description: "API Gateway ID"
Value: !Ref HackOverflowRestApi