-
Notifications
You must be signed in to change notification settings - Fork 0
/
serverless.yml
171 lines (158 loc) · 5.23 KB
/
serverless.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
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
service: etl
plugins:
- serverless-python-requirements
- serverless-pseudo-parameters
custom:
pythonRequirements:
dockerizePip: non-linux
AWSGlueCrawlerName: crawler-${self:service}-${opt:stage, self:provider.stage}
provider:
name: aws
runtime: python3.8
region: us-east-1
stage: dev
memorySize: 256
timeout: 300
environment:
TABLE_NAME: ${self:service}-covid-cases-${opt:stage, self:provider.stage}
PROCESS_STATUS_TABLE: ${self:service}-process-status-${opt:stage, self:provider.stage}
BUCKET_NAME: ${self:service}-data-bucket-${opt:stage, self:provider.stage}
SNSTOPIC_NAME: arn:aws:sns:${self:provider.region}:#{AWS::AccountId}:${self:service}-${opt:stage, self:provider.stage}
iamRoleStatements:
- Effect: Allow
Action:
- "dynamodb:PutItem"
- "dynamodb:GetItem"
- "dynamodb:UpdateItem"
Resource: "arn:aws:dynamodb:${self:provider.region}:#{AWS::AccountId}:table/${self:provider.environment.PROCESS_STATUS_TABLE}"
- Effect: Allow
Action:
- "s3:PutObject"
- "s3:GetObject"
- "sns:Publish"
- "dynamodb:PutItem"
- "dynamodb:GetItem"
- "dynamodb:UpdateItem"
- "s3:DeleteObject"
Resource:
- "arn:aws:dynamodb:${self:provider.region}:#{AWS::AccountId}:table/${self:provider.environment.TABLE_NAME}"
- "arn:aws:s3:::${self:provider.environment.BUCKET_NAME}/*"
- "arn:aws:s3:::${self:provider.environment.BUCKET_NAME}"
- "arn:aws:sns:${self:provider.region}:#{AWS::AccountId}:${self:service}-${opt:stage, self:provider.stage}"
functions:
indexFunction:
handler: index.handler
events:
- schedule:
name: ${self:service}-${opt:stage, self:provider.stage}-Cron-Job
description: Covid ETL cron job Runs everyday at 12:15PM
rate: cron(15 12 * * ? *)
resources:
Resources:
SNSTopic:
Type: AWS::SNS::Topic
Properties:
TopicName: ${self:service}-${opt:stage, self:provider.stage}
DisplayName: Covid ETL Update
SNSSubscription:
DependsOn: SNSTopic
Type: AWS::SNS::Subscription
Properties:
TopicArn:
Ref: SNSTopic
Protocol: email
Endpoint: [email protected]
S3DataBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: ${self:provider.environment.BUCKET_NAME}
AccessControl: Private
VersioningConfiguration:
Status: Enabled
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
ProcessStatusTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:provider.environment.PROCESS_STATUS_TABLE}
AttributeDefinitions:
- AttributeName: Status
AttributeType: S
KeySchema:
- AttributeName: Status
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
DynamoDbTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:provider.environment.TABLE_NAME}
AttributeDefinitions:
- AttributeName: Date
AttributeType: S
KeySchema:
- AttributeName: Date
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
CrawlerRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- "glue.amazonaws.com"
Action:
- "sts:AssumeRole"
Path: "/"
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSGlueServiceRole
Policies:
- PolicyName: ${self:custom.AWSGlueCrawlerName}-policy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- "s3:GetObject"
- "s3:PutObject"
Resource:
- "arn:aws:s3:::${self:provider.environment.BUCKET_NAME}/data*"
CrawlerDatabase:
Type: AWS::Glue::Database
Properties:
CatalogId:
Ref: AWS::AccountId
DatabaseInput:
Description: AWS Glue Database for Crawler | Covid ETL Project
Name: ${self:custom.AWSGlueCrawlerName}-database
Crawler:
Type: AWS::Glue::Crawler
Properties:
Name: ${self:custom.AWSGlueCrawlerName}
Description: AWS Glue Crawler for Covid Data ETL Job
DatabaseName:
Ref: CrawlerDatabase
Configuration: '{"Version":1.0,"Grouping":{"TableGroupingPolicy":"CombineCompatibleSchemas"}}'
Schedule:
ScheduleExpression: cron(30 12 * * ? *)
Role:
Ref: CrawlerRole
Targets:
S3Targets:
- Path: s3://${self:service}-data-bucket-${opt:stage, self:provider.stage}/data
package:
exclude:
- venv/**