-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemplate.yml
68 lines (63 loc) · 2.41 KB
/
template.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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Metadata:
AWS::ServerlessRepo::Application:
Name: lambda-versions-deleter
Description: A serverless app that deletes old lambda function versions on a schedule.
Author: Shweta Katdare
# SPDX License Id, e.g., MIT, MIT-0, Apache-2.0. See https://spdx.org/licenses for more details
SpdxLicenseId: Apache-2.0
# paths are relative to .aws-sam/build directory
LicenseUrl: ../../LICENSE
ReadmeUrl: ../../README.md
Labels: [aws, lambda, cloudwatch, serverless]
HomePageUrl: https://github.com/shwetaskatdare/lambda-versions-deleter
# Update the semantic version and run sam publish to publish a new version of your app
SemanticVersion: 0.0.1
# best practice is to use git tags for each release and link to the version tag as your source code URL
SourceCodeUrl: https://github.com/shwetaskatdare/lambda-versions-deleter/tree/0.0.1
Parameters:
LogLevel:
Type: String
Description: Log level for Lambda function logging, e.g., ERROR, INFO, DEBUG, etc
Default: INFO
FunctionArn:
Type: String
Description: Specify ARN of a Lambda function for which you want the versions to be deleted.
LambdaExecutionSchedule:
Type: String
Description: Specify the schedule expression to invoke LambdaVersionsDeleter using https://docs.aws.amazon.com/lambda/latest/dg/tutorial-scheduled-events-schedule-expressions.html
Default: cron(0 12 * * ? *)
Resources:
LambdaVersionsDeleter:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/
Handler: lambdaversionsdeleter.handler
Runtime: python3.7
Tracing: Active
Timeout: 60
Policies:
- Version: '2012-10-17' # PolicyDocument
Statement:
- Effect: Allow
Action:
- lambda:ListVersionsByFunction
- lambda:DeleteFunction
Resource: !Ref FunctionArn
Environment:
Variables:
LOG_LEVEL: !Ref LogLevel
FUNCTION_ARN: !Ref FunctionArn
Events:
LambdaVersionsDeleterSchedule:
Type: Schedule
Properties:
Schedule: !Ref LambdaExecutionSchedule
Outputs:
LambdaVersionsDeleter:
Description: "Lambda Function Name"
Value: !Ref LambdaVersionsDeleter
LambdaVersionsDeleterArn:
Description: "Lambda Function ARN"
Value: !GetAtt LambdaVersionsDeleter.Arn