Last active
September 8, 2022 12:55
-
-
Save thomasmichaelwallace/82c55855d16a265f20dc0a5df4653e82 to your computer and use it in GitHub Desktop.
Revisions
-
thomasmichaelwallace revised this gist
Jun 24, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,7 @@ def lambda_to_ec2(event, context): service httpd start chkconfig httpd on echo """ + message + """ > /var/www/html/index.html shutdown -h +5""" print 'Running script:' print init_script -
thomasmichaelwallace created this gist
Aug 9, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ """ Lambda to launch ec2-instances """ import boto3 REGION = 'eu-central-1' # region to launch instance. AMI = 'ami-24bd1b4b' # matching region/setup amazon linux ami, as per: # https://aws.amazon.com/amazon-linux-ami/ INSTANCE_TYPE = 'm3.medium' # instance type to launch. EC2 = boto3.client('ec2', region_name=REGION) def lambda_to_ec2(event, context): """ Lambda handler taking [message] and creating a httpd instance with an echo. """ message = event['message'] # bash script to run: # - update and install httpd (a webserver) # - start the webserver # - create a webpage with the provided message. # - set to shutdown the instance in 5 minutes. init_script = """#!/bin/bash yum update -y yum install -y httpd24 service httpd start chkconfig httpd on echo """ + message + """ > /var/www/html/index.html shutdown -H +5""" print 'Running script:' print init_script instance = EC2.run_instances( ImageId=AMI, InstanceType=INSTANCE_TYPE, MinCount=1, # required by boto, even though it's kinda obvious. MaxCount=1, InstanceInitiatedShutdownBehavior='terminate', # make shutdown in script terminate ec2 UserData=init_script # file to run on instance init. ) print "New instance created." instance_id = instance['Instances'][0]['InstanceId'] print instance_id return instance_id