-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yaml
93 lines (86 loc) · 2.32 KB
/
template.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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: When request to s3 api using signature version 2, notification to email address.
Parameters:
EmailAddress:
Type: String
Resources:
CloudTrail:
Type: AWS::CloudTrail::Trail
Properties:
EventSelectors:
- DataResources:
- Type: AWS::S3::Object
Values:
- 'arn:aws:s3:::'
IncludeManagementEvents: false
IncludeGlobalServiceEvents: true
IsLogging: true
IsMultiRegionTrail: true
S3BucketName: !Ref LogBucket
DependsOn:
- LogBucketPolicy
LogBucket:
Type: AWS::S3::Bucket
Properties:
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
LifecycleConfiguration:
Rules:
- ExpirationInDays: 10
Status: Enabled
LogBucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref LogBucket
PolicyDocument:
Statement:
- Action: s3:GetBucketAcl
Effect: Allow
Resource: !Sub arn:aws:s3:::${LogBucket}
Principal:
Service: cloudtrail.amazonaws.com
- Action: s3:PutObject
Effect: Allow
Resource: !Sub arn:aws:s3:::${LogBucket}/AWSLogs/${AWS::AccountId}/*
Principal:
Service: cloudtrail.amazonaws.com
Condition:
StringEquals:
s3:x-amz-acl: bucket-owner-full-control
EventRule:
Type: AWS::Events::Rule
Properties:
EventPattern:
detail-type:
- AWS API Call via CloudTrail
detail:
eventSource:
- s3.amazonaws.com
additionalEventData:
SignatureVersion:
- SigV2
State: ENABLED
Targets:
- Id: sns
Arn: !Ref SNS
SNS:
Type: AWS::SNS::Topic
Properties:
Subscription:
- Endpoint: !Ref EmailAddress
Protocol: email
SNSPolicy:
Type: AWS::SNS::TopicPolicy
Properties:
PolicyDocument:
Statement:
- Effect: Allow
Principal:
Service: events.amazonaws.com
Action: sns:Publish
Resource: '*'
Topics:
- !Ref SNS