-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudformation.yaml
99 lines (88 loc) · 2.39 KB
/
cloudformation.yaml
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
AWSTemplateFormatVersion: 2010-09-09
Description: Lambda Function to fetch upcoming races for a MultiGP Chapter
Parameters:
MultiGPChapter:
Type: String
Description: Chapter URL Slug
JsonOutputBucket:
Type: String
Description: Name of S3 Bucket used for hosting json
Resources:
RaceFinderFunction:
Type: AWS::Lambda::Function
Properties:
Code:
ZipFile: racefinder.zip
Handler: races.lambda_multigp
Runtime: python2.7
MemorySize: 512
Timeout: 60
Role: !GetAtt LambdaExecutionRole.Arn
Environment:
Variables:
MGP_CHAPTER: !Ref MultiGPChapter
OUTPUT_BUCKET: !Ref RaceJsonBucket
RaceFinderSchedule:
Type: AWS::Events::Rule
Properties:
Name: RaceFinderSchedule
ScheduleExpression: rate(1 day)
Targets:
-
Arn: !GetAtt RaceFinderFunction.Arn
Id: DailyRaceFinder
RaceFinderFunctionPermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref RaceFinderFunction
Action: lambda:InvokeFunction
Principal: events.amazonaws.com
SourceArn: !GetAtt RaceFinderSchedule.Arn
LambdaExecutionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Path: "/"
Policies:
- PolicyName: root
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- logs:*
Resource: arn:aws:logs:*:*:*
- Effect: Allow
Action:
- s3:GetObject
- s3:PutObject
- s3:PutObjectAcl
Resource: !GetAtt RaceJsonBucket.Arn
RaceJsonBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Ref JsonOutputBucket
AccessControl: PublicRead
DeletionPolicy: Delete
RaceJsonBucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref RaceJsonBucket
PolicyDocument:
Statement:
- Sid: PublicReadForGetBucketObjects
Effect: Allow
Principal: '*'
Action: s3:GetObject
Resource: !Sub arn:aws:s3:::${RaceJsonBucket}/*
Outputs:
LambdaFunction:
Value: !Ref RaceFinderFunction