Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import textwrap
from troposphere import ec2
def create_instance():
return ec2.Instance(
'devserver',
BlockDeviceMappings=[
ec2.BlockDeviceMapping(
DeviceName='/dev/xvda',
Ebs=ec2.EBSBlockDevice(
VolumeSize=100,
VolumeType='gp2',
DeleteOnTermination=True,
),
),
],
ImageId=Ref('amiId'),
InstanceType='t2.medium',
KeyName=Ref('keypair'),
SecurityGroupIds=[Ref('securitygroup')],
SubnetId=Ref('subnet'),
Tags=create_tags(),
UserData=Base64(textwrap.dedent(rf'''
#!/bin/bash -ex
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
echo BEGIN
date '+%Y-%m-%d %H:%M:%S'
cd ~
echo '{create_resource_bundle()}' | base64 -d | tar zx
./resource_bundle/system/main.sh
echo END
date '+%Y-%m-%d %H:%M:%S'
''').lstrip()),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.