Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
VolumeSize=200,
VolumeType="gp2"
)
)
]
# Make syncgateway0 a cache writer, and the rest cache readers
# See https://github.com/couchbase/sync_gateway/wiki/Distributed-channel-cache-design-notes
instance.Tags = Tags(Name=name, Type="syncgateway")
t.add_resource(instance)
# Gateload instances (ubuntu ami)
for i in range(num_gateloads):
name = "gateload{}".format(i)
instance = ec2.Instance(name)
instance.ImageId = "ami-6d1c2007" # centos7
instance.InstanceType = gateload_instance_type
instance.SecurityGroups = [Ref(secGrpCouchbase)]
instance.KeyName = Ref(keyname_param)
instance.IamInstanceProfile = Ref(instanceProfile)
instance.Tags = Tags(Name=name, Type="gateload")
instance.BlockDeviceMappings = [
ec2.BlockDeviceMapping(
DeviceName="/dev/sda1",
Ebs=ec2.EBSBlockDevice(
DeleteOnTermination=True,
VolumeSize=200,
VolumeType="gp2"
)
)
]
def setUp(self):
self.instance = ec2.Instance('Instance', UserData='')
dir = os.path.dirname(__file__)
self.filepath = os.path.join(dir, 'userdata_test_scripts/')
def test_extraattribute(self):
class ExtendedInstance(Instance):
def __init__(self, *args, **kwargs):
self.attribute = None
super(ExtendedInstance, self).__init__(*args, **kwargs)
instance = ExtendedInstance('ec2instance', attribute='value')
self.assertEqual(instance.attribute, 'value')
CPUCredits=lu('ec2.cpu-credits'),
)
# TODO: 'root' is undefined in the project definition
# TODO: extract in private method?
if context['ec2'].get('root'):
project_ec2['BlockDeviceMappings'] = [{
'DeviceName': '/dev/sda1',
'Ebs': {
'VolumeSize': context['ec2']['root']['size'],
'VolumeType': context['ec2']['root'].get('type', 'standard'),
# unfortunately root volumes do not support Tags:
# https://blog.cloudability.com/two-solutions-for-tagging-elusive-aws-ebs-volumes/
}
}]
return ec2.Instance(EC2_TITLE_NODE % node, **project_ec2)
ec2.SecurityGroupRule(
IpProtocol="tcp",
FromPort=Ref(webport_param),
ToPort=Ref(webport_param),
CidrIp="0.0.0.0/0",
),
]
)
)
eipA = template.add_resource(ec2.EIP('eipA', Domain='vpc',))
eipB = template.add_resource(ec2.EIP('eipB', Domain='vpc',))
# Add the web server instance
WebInstance = template.add_resource(ec2.Instance(
"WebInstance",
SecurityGroups=[Ref(instance_sg)],
KeyName=Ref(keyname_param),
InstanceType=Ref("InstanceType"),
ImageId=FindInMap("RegionMap", Ref("AWS::Region"), "AMI"),
UserData=Base64(Ref(webport_param)),
))
# Add the network LB
NetworkLB = template.add_resource(elb.LoadBalancer(
"NetworkLB",
Name="NetworkLB",
Scheme="internet-facing",
SubnetMappings=[
elb.SubnetMapping(
AllocationId=GetAtt(eipA, 'AllocationId'),
FromPort=Ref(webport_param),
ToPort=Ref(webport_param),
CidrIp="0.0.0.0/0",
),
ec2.SecurityGroupRule(
IpProtocol="tcp",
FromPort=Ref(apiport_param),
ToPort=Ref(apiport_param),
CidrIp="0.0.0.0/0",
),
]
)
)
# Add the web server instance
WebInstance = template.add_resource(ec2.Instance(
"WebInstance",
SecurityGroups=[Ref(instance_sg)],
KeyName=Ref(keyname_param),
InstanceType=Ref("InstanceType"),
ImageId=FindInMap("RegionMap", Ref("AWS::Region"), "AMI"),
UserData=Base64(Ref(webport_param)),
))
# Add the api server instance
ApiInstance = template.add_resource(ec2.Instance(
"ApiInstance",
SecurityGroups=[Ref(instance_sg)],
KeyName=Ref(keyname_param),
InstanceType=Ref("InstanceType"),
ImageId=FindInMap("RegionMap", Ref("AWS::Region"), "AMI"),
UserData=Base64(Ref(apiport_param)),
def create_ec2_instance(self):
t = self.template
variables = self.get_variables()
t.add_resource(
ec2.Instance(
"LampInstance",
ImageId=FindInMap(
'AmiMap', Ref("AWS::Region"), variables["ImageName"]),
InstanceType=variables["InstanceType"],
NetworkInterfaces=[
ec2.NetworkInterfaceProperty(
DeviceIndex=0,
AssociatePublicIpAddress=True,
GroupSet=[Ref('ServerSecurityGroup')],
SubnetId=Select(0, variables['Subnets']))],
Tags=[ec2.Tag('Name', 'lamp-ec2-instance')],
KeyName=variables['SshKeyName'],
UserData=self.parse_user_data(variables["UserData"]),
),
CidrIp="0.0.0.0/0",
),
ec2.SecurityGroupRule(
IpProtocol="tcp",
FromPort=Ref(webport_param),
ToPort=Ref(webport_param),
CidrIp="0.0.0.0/0",
),
]
)
)
# Add the web server instances
web_instances = []
for name in ("Ec2Instance1", "Ec2Instance2"):
instance = template.add_resource(ec2.Instance(
name,
SecurityGroups=[Ref(instance_sg)],
KeyName=Ref(keyname_param),
InstanceType=Ref("InstanceType"),
ImageId=FindInMap("RegionMap", Ref("AWS::Region"), "AMI"),
UserData=Base64(Ref(webport_param)),
))
web_instances.append(instance)
elasticLB = template.add_resource(elb.LoadBalancer(
'ElasticLoadBalancer',
AccessLoggingPolicy=elb.AccessLoggingPolicy(
EmitInterval=5,
Enabled=True,
S3BucketName="logging",
S3BucketPrefix="myELB",
SecurityGroupEgress=[
ec2.SecurityGroupRule(IpProtocol='tcp',
CidrIp=VPC_CIDR,
FromPort=p, ToPort=p)
for p in [POSTGRESQL, REDIS, SSH]
] + [
ec2.SecurityGroupRule(IpProtocol='tcp',
CidrIp=ALLOW_ALL_CIDR,
FromPort=p, ToPort=p)
for p in [HTTP, HTTPS]
],
Tags=self.get_tags(Name=bastion_security_group_name)
))
bastion_host_name = 'BastionHost'
return self.add_resource(ec2.Instance(
bastion_host_name,
InstanceType=Ref(self.bastion_instance_type),
KeyName=Ref(self.keyname),
ImageId=Ref(self.bastion_host_ami),
NetworkInterfaces=[
ec2.NetworkInterfaceProperty(
Description='ENI for BastionHost',
GroupSet=[Ref(bastion_security_group)],
SubnetId=Select('0', Ref(self.public_subnets)),
AssociatePublicIpAddress=True,
DeviceIndex=0,
DeleteOnTermination=True
)
],
Tags=self.get_tags(Name=bastion_host_name)
))