-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcfn-stack-cleanup.yaml
78 lines (68 loc) · 2.15 KB
/
cfn-stack-cleanup.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
Description: Deploys the AWS CloudFormation Stack Cleanup lambda into an AWS account
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Parameters:
ExportPrefix:
Description: A optional unique prefix given to the export names
Type: String
Default: ""
Metadata:
AWS::ServerlessRepo::Application:
Author: Xavier Thomas
Description: AWS Lambda custom resource that can be invoked from an AWS CloudFormation stack to clean up any left over stack resources such as S3 buckets, Log Groups, Sub-Stacks, etc.
HomePageUrl: https://github.com/xavier-thomas/aws-cfn-stack-cleanup
Labels:
- CloudFormation
- CustomResource
- Cleanup
- Cleaner
- DevOps
- S3
- Cloudwatch-Logs
LicenseUrl: LICENSE
Name: Cfn-Stack-Cleanup
ReadmeUrl: README.md
SemanticVersion: 1.3.1
SourceCodeUrl: https://github.com/xavier-thomas/aws-cfn-stack-cleanup
SpdxLicenseId: BSD-3-Clause
Resources:
StackCleanupLambda:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${ExportPrefix}StackCleanupLambda
Handler: index.handler
Layers:
- !Ref DependencyLayer
Runtime: nodejs16.x
CodeUri: ./dist
MemorySize: 128
Timeout: 900
Policies:
- AWSLambdaExecute
# Replace the resource: '*' with a specific role arn.
- Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- s3:DeleteBucket
- s3:DeleteObject
- s3:List*
Resource: '*'
DependencyLayer:
Type: AWS::Serverless::LayerVersion
Properties:
CompatibleRuntimes:
- nodejs12.x
ContentUri: ./layer
Description: Dependency layer for the Stack Cleanup lambda function
LayerName: !Sub ${ExportPrefix}StackCleanupLambdaLayer
RetentionPolicy: Delete
Outputs:
StackCleanupLambdaArn:
Value: !GetAtt StackCleanupLambda.Arn
Export:
Name: !Sub ${ExportPrefix}StackCleanupLambdaArn
StackCleanupLambdaName:
Value: !Ref StackCleanupLambda
Export:
Name: !Sub ${ExportPrefix}StackCleanupLambdaName