Skip to content

Commit 0c6888b

Browse files
committed
feat : add serverless data pipeline scripts
1 parent ce30bc6 commit 0c6888b

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed

serverless.yml

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
service: serverless-data-pipeline
2+
frameworkVersion: '3'
3+
package:
4+
exclude:
5+
- '**/*'
6+
include:
7+
- 'data-extractor.py'
8+
provider:
9+
name: aws
10+
runtime: python3.9
11+
region: us-east-1
12+
iam:
13+
role:
14+
statements:
15+
- Effect: Allow
16+
Action:
17+
- 's3:*'
18+
- 'cloudwatch:*'
19+
- 'logs:*'
20+
- 'firehose:*'
21+
Resource: '*'
22+
lambdaHashingVersion: 20201221
23+
functions:
24+
data_extractor_lambda:
25+
handler: data-extractor.lambda_handler
26+
timeout: 300
27+
environment:
28+
FIREHOSE_NAME: !Ref FirehoseDeliveryStream
29+
events:
30+
- schedule:
31+
name: DataExtractor-Lambda-Schedule
32+
rate: cron(0 8 * * ? *)
33+
34+
resources:
35+
Resources:
36+
SQSQueue:
37+
Type: AWS::SQS::Queue
38+
Properties:
39+
QueueName: ${self:service}-s3-event-notification-queue
40+
S3BucketRawData:
41+
Type: AWS::S3::Bucket
42+
Properties:
43+
BucketName: cse-aspi-index-raw-data-bucket
44+
NotificationConfiguration:
45+
QueueConfigurations:
46+
- Event: s3:ObjectCreated:*
47+
Queue: !GetAtt SQSQueue.Arn
48+
SQSQueuePolicy:
49+
Type: AWS::SQS::QueuePolicy
50+
Properties:
51+
Queues:
52+
- !Ref SQSQueue
53+
PolicyDocument:
54+
Version: '2012-10-17'
55+
Statement:
56+
- Effect: Allow
57+
Principal: '*'
58+
Action: sqs:*
59+
Resource: !GetAtt SQSQueue.Arn
60+
Condition:
61+
ArnEquals:
62+
aws:SourceArn: !GetAtt S3BucketRawData.Arn
63+
- Effect: Allow
64+
Principal:
65+
AWS: !GetAtt ExecutionIAMRole.Arn
66+
Action: sqs:*
67+
Resource: !GetAtt SQSQueue.Arn
68+
S3BucketParquetData:
69+
Type: AWS::S3::Bucket
70+
Properties:
71+
BucketName: cse-aspi-index-parquet-data-bucket
72+
S3BucketProdData:
73+
Type: AWS::S3::Bucket
74+
Properties:
75+
BucketName: cse-aspi-index-prod-table-data-bucket
76+
S3BucketOutputData:
77+
Type: AWS::S3::Bucket
78+
Properties:
79+
BucketName: athena-query-results-output-data-bucket
80+
ExecutionIAMRole:
81+
Type: AWS::IAM::Role
82+
Properties:
83+
RoleName: ${self:service}-execution-role
84+
AssumeRolePolicyDocument:
85+
Version: '2012-10-17'
86+
Statement:
87+
- Effect: Allow
88+
Principal:
89+
Service:
90+
- firehose.amazonaws.com
91+
- glue.amazonaws.com
92+
Action: sts:AssumeRole
93+
Policies:
94+
- PolicyName: '${self:service}-execution-role-policy'
95+
PolicyDocument:
96+
Version: '2012-10-17'
97+
Statement:
98+
- Effect: Allow
99+
Action:
100+
- s3:*
101+
- sqs:*
102+
- glue:*
103+
- athena:*
104+
Resource:
105+
- '*'
106+
- Effect: Allow
107+
Action:
108+
- logs:*
109+
Resource:
110+
- '*'
111+
FirehoseDeliveryStream:
112+
Type: AWS::KinesisFirehose::DeliveryStream
113+
Properties:
114+
DeliveryStreamType: DirectPut
115+
S3DestinationConfiguration:
116+
BucketARN: !GetAtt S3BucketRawData.Arn
117+
RoleARN: !GetAtt ExecutionIAMRole.Arn
118+
BufferingHints:
119+
IntervalInSeconds: 300
120+
SizeInMBs: 5
121+
CompressionFormat: UNCOMPRESSED
122+
CloudWatchLoggingOptions:
123+
Enabled: true
124+
LogGroupName: !Sub "/aws/kinesisfirehose/${AWS::StackName}/delivery"
125+
LogStreamName: !Sub "${AWS::StackName}-firehose-delivery-stream"

0 commit comments

Comments
 (0)