-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserverless.example.yml
101 lines (93 loc) · 2.7 KB
/
serverless.example.yml
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
# serverless.example.yml - Secure Template
service: subscription-service
provider:
name: aws
runtime: nodejs18.x
region: us-east-2
environment:
TABLE_NAME: YourTableName
SES_EMAIL: your-verified-email@example.com
deploymentBucket:
name: your-deployment-bucket-name
iam:
role:
statements:
# DynamoDB Permissions
- Effect: Allow
Action:
- dynamodb:UpdateItem
- dynamodb:Query
Resource:
- "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${self:provider.environment.TABLE_NAME}"
- "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${self:provider.environment.TABLE_NAME}/index/*"
# SES Email Permissions
- Effect: Allow
Action:
- ses:SendEmail
- ses:SendRawEmail
Resource: "*"
Condition:
StringEquals:
"ses:FromAddress": ${self:provider.environment.SES_EMAIL}
# CloudWatch Monitoring Permissions
- Effect: Allow
Action:
- cloudwatch:PutMetricData
Resource: "*"
package:
individually: true
patterns:
- "!**" # Exclude all files by default
functions:
# Subscription Webhook Handler
handlerSubscription:
handler: handlers/handlerSubscription.handler
package:
patterns:
- "handlers/handlerSubscription.js"
events:
- http:
path: /subscriptions
method: post
cors: true
# Scheduled Expiration Checker
checkExpirations:
handler: handlers/checkExpirations.handler
package:
patterns:
- "handlers/checkExpirations.js"
events:
- schedule:
rate: cron(0 10 * * ? *) # Daily at 10:00 UTC
enabled: true
resources:
Resources:
# DynamoDB Table Configuration
SubscriptionsTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:provider.environment.TABLE_NAME}
AttributeDefinitions:
- AttributeName: userId
AttributeType: S
- AttributeName: subscriptionId
AttributeType: S
- AttributeName: status
AttributeType: S
- AttributeName: endDate
AttributeType: S
KeySchema:
- AttributeName: userId
KeyType: HASH
- AttributeName: subscriptionId
KeyType: RANGE
BillingMode: PAY_PER_REQUEST
GlobalSecondaryIndexes:
- IndexName: status-endDate-index
KeySchema:
- AttributeName: status
KeyType: HASH
- AttributeName: endDate
KeyType: RANGE
Projection:
ProjectionType: ALL