-
Notifications
You must be signed in to change notification settings - Fork 4
/
AWS-Lambda-Trigger.py
49 lines (44 loc) · 1.78 KB
/
AWS-Lambda-Trigger.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
from __future__ import print_function
import boto3
ami = 'ami-16fd6365'
def lambda_handler(event, context):
ec2 = boto3.resource('ec2')
res = ec2.create_instances(ImageId=ami,
InstanceType='t2.micro',
MinCount=1,
MaxCount=1,
Placement={
'AvailabilityZone': "eu-west-1c"
},
SecurityGroups=[
'puiterwijk-atomic-compose-server'
],
InstanceType='t2.micro',
KeyName='test',
IamInstanceProfile={
'Arn': 'arn:aws:iam::757505437733:instance-profile/puiterwijk-atomic'
},
BlockDeviceMappings=[{
'DeviceName': '/dev/sda1',
'Ebs': {
'VolumeSize': 10,
'DeleteOnTermination': True,
'VolumeType': 'gp2'
},
}],
UserData="""#cloud-config
runcmd:
- /bin/sh -c "curl https://raw.githubusercontent.com/puiterwijk/puiterwijk-Atomic/master/boot.sh | bash"
""")
instance = res[0]
instance.create_tags(Tags=[
{
"Key": "Name",
"Value": "Puiterwijk-Atomic-Compose-Triggered"
},
{
"Key": "Project",
"Value": "Puiterwijk-Atomic"
}
])
return "Instance spun up: %s" % res