sciencefair2023/cdk/sfec2/sci_stack.py

50 lines
1.6 KiB
Python

import os
import aws_cdk as cdk
import aws_cdk.aws_ec2 as ec2
import aws_cdk.aws_iam as iam
from constructs import Construct
class SciInstancesStack(cdk.Stack):
def __init__(self, vpcStack: Construct, construct_id:
str, thing: str, env: cdk.Environment, **kwargs) -> None:
super().__init__(vpcStack, construct_id, env=env, **kwargs)
thisVpc = vpcStack.vpc
imageId = ec2.LookupMachineImage(name='debian-11-amd64-20221219-1234', windows=False)
ec2instance = ec2.Instance(self, f"i-{thing}",
vpc=vpcStack.vpc,
instance_type=ec2.InstanceType("t2.nano"),
machine_image=imageId,
block_devices=[ec2.BlockDevice(
device_name="/dev/sda1",
volume=ec2.BlockDeviceVolume.ebs(6),
)
],
security_group = vpcStack.SciSG,
)
class VpcBasisStack(cdk.Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
self.vpc = ec2.Vpc(self, 'out-vpc',
ip_addresses=ec2.IpAddresses.cidr('172.19.19.0/24'),
max_azs = 1,
subnet_configuration=[
ec2.SubnetConfiguration(
name = 'pub',
subnet_type = ec2.SubnetType.PUBLIC,
cidr_mask = 26
)
],
nat_gateways = 3
)
# Create standard Security Group for all EC2 instances
self.SciSG = ec2.SecurityGroup(self, 'Sci-sg', vpc=self.vpc,
allow_all_outbound=True, security_group_name='Sci-sg' );
app = cdk.App()