-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtemplate.yaml
72 lines (67 loc) · 1.95 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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
Example macro you can use to automatically set retention policies on your logs
Globals:
Function:
Runtime: nodejs14.x
Tracing: Active
Timeout: 10
Handler: index.handler
Architectures:
- arm64
Layers:
- !Ref DependencyLayer
Resources:
DependencyLayer:
Type: AWS::Serverless::LayerVersion
Metadata:
BuildMethod: nodejs14.x
Properties:
LayerName: dependencies
ContentUri: layers/
CompatibleRuntimes:
- nodejs14.x
SetLogRetentionFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: lambdas/set-log-retention/
Environment:
Variables:
RETENTION_DAYS: 3
Events:
ScheduledEvent:
Type: Schedule
Properties:
Schedule: "cron(0 2 * * ? *)"
Policies:
- AWSLambdaBasicExecutionRole
- Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- logs:DescribeLogGroups
- logs:PutRetentionPolicy
Resource: !Sub arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:*
DeleteUnusedLogGroupsFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: lambdas/delete-unused-log-groups/
Events:
ScheduledEvent:
Type: Schedule
Properties:
Schedule: "rate(7 days)"
Policies:
- AWSLambdaBasicExecutionRole
- Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- logs:DescribeLogGroups
- logs:DeleteLogGroup
Resource: !Sub arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:*
- Effect: Allow
Action:
- lambda:ListFunctions
Resource: "*"