-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaunch-cfn.py
81 lines (75 loc) · 2.4 KB
/
launch-cfn.py
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
from __future__ import print_function
import boto3
import os
client = boto3.client('cloudformation', region_name='us-west-2')
def lambda_handler(event, context):
if 'clickType' in event:
if event['clickType'] == 'SINGLE':
print("Single press - Deploy the CloudFormation"),
build_stack()
if event['clickType'] == 'DOUBLE':
print("Double press - Delete the CloudFormation"),
delete_stack()
else:
print("Something other than a single or double click")
else:
print("Something other than a click called the Lambda")
return 'end of function'
def build_stack():
response = client.create_stack(
StackName=os.environ['stackName'],
TemplateURL='https://aws-quickstart.s3.amazonaws.com/quickstart-vmware/templates/kubernetes-cluster-with-new-vpc.template',
Parameters=[
{
"ParameterKey": "AvailabilityZone",
"ParameterValue": "us-west-2b"
},
{
"ParameterKey": "AdminIngressLocation",
"ParameterValue": "0.0.0.0/0"
},
{
"ParameterKey": "KeyName",
"ParameterValue": os.environ['keyPair']
},
{
"ParameterKey": "NetworkingProvider",
"ParameterValue": "calico"
},
{
"ParameterKey": "K8sNodeCapacity",
"ParameterValue": "2"
},
{
"ParameterKey": "InstanceType",
"ParameterValue": "m4.large"
},
{
"ParameterKey": "DiskSizeGb",
"ParameterValue": "40"
},
{
"ParameterKey": "BastionInstanceType",
"ParameterValue": "t2.micro"
},
{
"ParameterKey": "QSS3BucketName",
"ParameterValue": "aws-quickstart"
},
{
"ParameterKey": "QSS3KeyPrefix",
"ParameterValue": "quickstart-vmware/"
},
],
Capabilities=[
'CAPABILITY_IAM',
],
OnFailure='ROLLBACK',
EnableTerminationProtection=False
)
return(response)
def delete_stack():
response = client.delete_stack(
StackName=os.environ['stackName'],
)
return(response)