forked from mlevit/aws-auto-cleanup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
serverless.yml
191 lines (185 loc) · 5.38 KB
/
serverless.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
service: auto-cleanup
custom:
company: servian # change to your company name
log_level: INFO # DEBUG for dev | INFO for prod
region: ${opt:region, "ap-southeast-2"} # AWS deployment region
pythonRequirements: # allows us to deploy a newer version of boto3
noDeploy:
[
"docutils",
"jmespath",
"python-dateutil",
"s3transfer",
"six",
"pip",
"setuptools",
]
remover:
prompt: false
buckets:
- ${self:service}-${self:provider.stage}-resourcetreebucket-${self:custom.company}
provider:
name: aws
runtime: python3.7
stage: ${opt:stage, "prod"} # Override via CLI "--stage dev"
region: ${self:custom.region}
profile: ${opt:profile, ""} # Override via CLI "--aws-profile saml"
environment:
PYTHONPATH: "/var/task/auto_cleanup:/var/task/boto3:/var/task/botocore:/var/task/dynamodb_json:/var/task/simplejson:/var/task/treelib:/var/runtime"
iamRoleStatements:
- Effect: Allow
Action:
- cloudformation:DeleteStack
- cloudformation:DescribeStacks
Resource: "*"
- Effect: Allow
Action:
- dynamodb:BatchWriteItem
- dynamodb:DeleteTable
- dynamodb:DescribeTable
- dynamodb:GetItem
- dynamodb:ListTables
- dynamodb:PutItem
- dynamodb:Scan
Resource: "*"
- Effect: Allow
Action:
- ec2:DeleteSecurityGroup
- ec2:DeleteSnapshot
- ec2:DeleteVolume
- ec2:DescribeAddresses
- ec2:DescribeImages
- ec2:DescribeInstanceAttribute
- ec2:DescribeInstances
- ec2:DescribeSecurityGroups
- ec2:DescribeSnapshots
- ec2:DescribeVolumes
- ec2:DescribeVolumes
- ec2:ModifyInstanceAttribute
- ec2:ReleaseAddress
- ec2:StopInstances
- ec2:TerminateInstances
Resource: "*"
- Effect: Allow
Action:
- elasticbeanstalk:DeleteApplication
- elasticbeanstalk:DescribeApplications
Resource: "*"
- Effect: Allow
Action:
- elasticmapreduce:ListClusters
- elasticmapreduce:TerminateJobFlows
Resource: "*"
- Effect: Allow
Action:
- iam:DeleteInstanceProfile
- iam:DeleteRole
- iam:DeleteRolePolicy
- iam:DetachRolePolicy
- iam:GenerateServiceLastAccessedDetails
- iam:GetServiceLastAccessedDetails
- iam:ListAttachedRolePolicies
- iam:ListInstanceProfilesForRole
- iam:ListRolePolicies
- iam:ListRoles
- iam:RemoveRoleFromInstanceProfile
Resource: "*"
- Effect: Allow
Action:
- lambda:DeleteFunction
- lambda:ListFunctions
Resource: "*"
- Effect: Allow
Action:
- redshift:DeleteCluster
- redshift:DeleteClusterSnapshot
- redshift:DescribeClusterSnapshots
- redshift:DescribeClusters
Resource: "*"
- Effect: Allow
Action:
- rds:DeleteDBInstance
- rds:DeleteDBSnapshot
- rds:DescribeDBInstances
- rds:DescribeDBSnapshots
- rds:ModifyDBInstance
Resource: "*"
- Effect: Allow
Action:
- s3:DeleteBucket
- s3:DeleteObject
- s3:DeleteObjectVersion
- s3:List*
- s3:PutObject
Resource: "*"
tracing:
lambda: true
package:
individually: true
exclude:
- node_modules/**
functions:
AutoCleanup:
handler: auto_cleanup.lambda_handler.lambda_handler
name: ${self:service}-${self:provider.stage}
description: Auto Cleanup removes unused AWS resources
memorySize: 128
timeout: 300
package:
include:
- auto-cleanup/**
- data/**
- dynamodb_json/**
- simplejson/**
- treelib/**
environment:
LOGLEVEL: INFO # change to DEBUG for testing
RESOURCETREEBUCKET: ${self:service}-${self:provider.stage}-resourcetreebucket-${self:custom.company}
SETTINGSTABLE: ${self:service}-settings-${self:provider.stage}
WHITELISTTABLE: ${self:service}-whitelist-${self:provider.stage}
events:
- schedule:
rate: rate(3 days)
enabled: true
resources:
Resources:
SettingsTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:service}-settings-${self:provider.stage}
AttributeDefinitions:
- AttributeName: key
AttributeType: S
KeySchema:
- AttributeName: key
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
WhitelistTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:service}-whitelist-${self:provider.stage}
AttributeDefinitions:
- AttributeName: resource_id
AttributeType: S
- AttributeName: expire_at
AttributeType: N
KeySchema:
- AttributeName: resource_id
KeyType: HASH
- AttributeName: expire_at
KeyType: RANGE
TimeToLiveSpecification:
AttributeName: expire_at
Enabled: true
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
ResourceTreeBuckett:
Type: AWS::S3::Bucket
Properties:
BucketName: ${self:service}-${self:provider.stage}-resourcetreebucket-${self:custom.company}
plugins:
- serverless-python-requirements
- serverless-s3-remover