-
Notifications
You must be signed in to change notification settings - Fork 3
/
lambda.yml
executable file
·107 lines (95 loc) · 2.96 KB
/
lambda.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
AWSTemplateFormatVersion: 2010-09-09
Parameters:
LambdaBucketName:
Type: String
Description: The name of the S3 bucket that has the code
S3FunctionCodeVersion:
Type: String
Description: The S3ObjectVersion for the function code
SesRegion:
Type: String
Default: us-east-1
SesSenderEmail:
Type: String
Description: >-
Email address to display as the sender of notifications.
Address or Domain must be verified in SES.
SesRecieverEmail:
Type: String
Description: >-
Email address to send notifications to.
Address or Domain must be verified in SES.
Resources:
AktionBucket:
Type: AWS::S3::Bucket
DeletionPolicy: Retain
ScheduledRule:
Type: AWS::Events::Rule
Properties:
ScheduleExpression: cron(00 09 ? * MON *)
State: ENABLED
Targets:
- Arn: !GetAtt Lambda.Arn
Id: !Ref Lambda
ScheduledEventPermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref Lambda
Action: lambda:InvokeFunction
Principal: events.amazonaws.com
SourceArn: !GetAtt ScheduledRule.Arn
Lambda:
Type: AWS::Lambda::Function
Properties:
FunctionName: aktion
Handler: aktion.lambda_handler
Timeout: 60
Role: !GetAtt LambdaRole.Arn
Environment:
Variables:
BUCKET_NAME: !Ref AktionBucket
SENDER_EMAIL: !Ref SesSenderEmail
RECEIVER_EMAIL: !Ref SesRecieverEmail
SES_REGION: !Ref SesRegion
Code:
S3Bucket: !Ref LambdaBucketName
S3Key: code.zip
S3ObjectVersion: !Ref S3FunctionCodeVersion
Runtime: python3.7
LambdaRole:
Type: AWS::IAM::Role
Properties:
RoleName: aktion-lambda
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Path: /
Policies:
- PolicyName: aktion-lambda
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action: ses:SendEmail
Resource:
- !Sub arn:aws:ses:${SesRegion}:${AWS::AccountId}:identity/${SesSenderEmail}
- !Sub arn:aws:ses:${SesRegion}:${AWS::AccountId}:identity/${SesRecieverEmail}
- Effect: Allow
Action:
- s3:GetObject*
- s3:PutObject*
Resource:
- !Sub arn:aws:s3:::${AktionBucket}/*
- !Sub arn:aws:s3:::${AktionBucket}
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource: arn:aws:logs:*:*:*