forked from chankh/eks-lambda-drainer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsam.yaml
108 lines (102 loc) · 3.47 KB
/
sam.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
AWSTemplateFormatVersion: '2010-09-09'
Metadata:
AWS::ServerlessRepo::Application:
Name: eks-lambda-drainer
Description: "Lambda handler for node draining on Amazon EKS spot instances"
Author: Pahud Hsieh
SpdxLicenseId: Apache-2.0
LicenseUrl: LICENSE
ReadmeUrl: README.md
Labels: ['eks','lambda','drain','taint', 'autoscaling', 'lifecyclehook']
HomePageUrl: https://github.com/pahud/eks-lambda-drainer
SemanticVersion: 1.0.0
SourceCodeUrl: https://github.com/pahud/eks-lambda-drainer
Mappings:
LayerArn:
ap-northeast-1:
kubectl: 'arn:aws:lambda:ap-northeast-1:903779448426:layer:eks-kubectl-layer:27'
ap-northeast-2:
kubectl: 'arn:aws:lambda:ap-northeast-2:903779448426:layer:eks-kubectl-layer:1'
ap-southeast-1:
kubectl: 'arn:aws:lambda:ap-southeast-1:903779448426:layer:eks-kubectl-layer:1'
ap-southeast-2:
kubectl: 'arn:aws:lambda:ap-southeast-2:903779448426:layer:eks-kubectl-layer:1'
us-east-1:
kubectl: 'arn:aws:lambda:us-east-1:903779448426:layer:eks-kubectl-layer:1'
us-west-2:
kubectl: 'arn:aws:lambda:us-west-2:903779448426:layer:eks-kubectl-layer:1'
us-east-2:
kubectl: 'arn:aws:lambda:us-east-2:903779448426:layer:eks-kubectl-layer:2'
eu-central-1:
kubectl: 'arn:aws:lambda:eu-central-1:903779448426:layer:eks-kubectl-layer:1'
eu-west-1:
kubectl: 'arn:aws:lambda:eu-west-1:903779448426:layer:eks-kubectl-layer:1'
cn-north-1:
kubectl: 'arn:aws-cn:lambda:cn-north-1:937788672844:layer:eks-kubectl-layer:1'
cn-northwest-1:
kubectl: 'arn:aws-cn:lambda:cn-northwest-1:937788672844:layer:eks-kubectl-layer:1'
Parameters:
ClusterName:
Type: String
Default: default
FunctionName:
Type: String
Default: defaultFunc
Transform: AWS::Serverless-2016-10-31
Description: eks-lambda-drainer Func
Resources:
Func:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Ref FunctionName
Description: github.com/pahud/eks-lambda-drainer
Handler: main
CodeUri: ./func.d
Runtime: provided
Layers:
# - !Sub "arn:aws:lambda:ap-northeast-1:${AWS::AccountId}:layer:layer-eks-kubectl-layer-stack:2"
- !FindInMap
- LayerArn
- !Ref 'AWS::Region'
- kubectl
MemorySize: 512
Environment:
Variables:
cluster_name: !Ref ClusterName
Policies:
- AWSLambdaBasicExecutionRole # Managed Policy
- Version: '2012-10-17' # Policy Document
Statement:
- Effect: Allow
Action:
- ec2:DescribeInstances
- ec2:DescribeTags
- eks:DescribeCluster
- autoscaling:CompleteLifecycleAction
Resource: '*'
#Role: !Sub "arn:aws:iam::${AWS::AccountId}:role/LambdaEKSAdminRole"
Timeout: 50
Events:
CWE1:
Type: CloudWatchEvent
Properties:
Pattern:
source:
- aws.ec2
detail-type:
- "EC2 Spot Instance Interruption Warning"
CWE2:
Type: CloudWatchEvent
Properties:
Pattern:
source:
- aws.autoscaling
detail-type:
- "EC2 Instance-terminate Lifecycle Action"
Outputs:
Func:
Description: "Lambda function Arn"
Value: !GetAtt Func.Arn
FuncIamRole:
Description: "Lambda function IAM role Arn"
Value: !GetAtt FuncRole.Arn