-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.yaml
More file actions
87 lines (80 loc) · 2.16 KB
/
template.yaml
File metadata and controls
87 lines (80 loc) · 2.16 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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Parameters:
AWSAccountId:
Type: String
Description: AWS Account ID for resource naming
Resources:
# S3 Buckets
RawBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub "${AWSAccountId}-proposal-raw"
NotificationConfiguration:
EventBridgeConfiguration:
EventBridgeEnabled: true
ProcessedBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub "${AWSAccountId}-proposal-processed"
# Lambda Function
ProcessingFunction:
Type: AWS::Serverless::Function
Properties:
PackageType: Image
ImageConfig:
Command: ["app.lambda_handler"]
Timeout: 300
MemorySize: 1024
Policies:
- S3ReadPolicy:
BucketName: !Ref RawBucket
- S3CrudPolicy:
BucketName: !Ref ProcessedBucket
Environment:
Variables:
RAW_BUCKET: !Ref RawBucket
PROCESSED_BUCKET: !Ref ProcessedBucket
Metadata:
DockerTag: python3.9-v1
DockerContext: ./
Dockerfile: Dockerfile
# EventBridge Rule
S3PutEventRule:
Type: AWS::Events::Rule
Properties:
Description: "Rule to trigger Lambda on S3 PUT events"
EventPattern:
source:
- aws.s3
detail-type:
- "Object Created"
detail:
bucket:
name:
- !Ref RawBucket
object:
key:
- suffix: ".csv"
State: "ENABLED"
Targets:
- Arn: !GetAtt ProcessingFunction.Arn
Id: "ProcessCSVTarget"
# Lambda Permission for EventBridge
LambdaPermission:
Type: AWS::Lambda::Permission
Properties:
Action: lambda:InvokeFunction
FunctionName: !Ref ProcessingFunction
Principal: events.amazonaws.com
SourceArn: !GetAtt S3PutEventRule.Arn
Outputs:
RawBucketName:
Description: "Raw S3 bucket name"
Value: !Ref RawBucket
ProcessedBucketName:
Description: "Processed S3 bucket name"
Value: !Ref ProcessedBucket
ProcessingFunctionName:
Description: "Processing Lambda function name"
Value: !Ref ProcessingFunction