troposphere icon indicating copy to clipboard operation
troposphere copied to clipboard

example usage of VPC and ENI

Open ghost opened this issue 6 years ago • 1 comments

is there example implementation of this service (ENI's in a VPC) ?

https://docs.aws.amazon.com/vpc/latest/userguide/VPC_ElasticNetworkInterfaces.html

if so, can you share this?

ghost avatar Apr 03 '19 16:04 ghost

Hi,

If you still need an example, here is a dirty copy-paste from one of my template:

vpc = template.add_resource(
    ec2.VPC(
        "Vpc",
        CidrBlock="192.168.0.0/24",
        EnableDnsSupport=True,
        EnableDnsHostnames=True,
        InstanceTenancy="default",
        Tags=Tags(Name=Sub("${AWS::StackName}")),
    )
)

subnet = template.add_resource(
    ec2.Subnet(
        "Subnet",
        DependsOn=vpc.title,
        VpcId=Ref(vpc),
        CidrBlock="192.168.0.0/25",
        MapPublicIpOnLaunch=False,
        AvailabilityZone=Select(0, GetAZs()),
        Tags=Tags(Name=Sub("${AWS::StackName}")),
    )
)

eni = template.add_resource(
    ec2.NetworkInterface(
        "Eni",
        Description="Interface for example",
        SubnetId=Ref(subnet),
        DependsOn=[subnet.title],
    )
)

instance = template.add_resource(
    ec2.Instance(
        "Instance",
        AvailabilityZone=Select(0, GetAZs()),
        BlockDeviceMappings=[
            ec2.BlockDeviceMapping(
                DeviceName="/dev/sda1", Ebs=ec2.EBSBlockDevice(DeleteOnTermination=True, Encrypted=True, VolumeSize=8)
            )
        ],
        ImageId=Ref("ExampleAmi"),
        InstanceType="t3.small",
        NetworkInterfaces=[
            ec2.NetworkInterfaceProperty(
                Description="Example ENI", NetworkInterfaceId=Ref(eni), DeviceIndex=0
            ),
        ],
        DependsOn=[eni.title],
        Tags=Tags(Name=Sub("${AWS::StackName}")),
    )
)

urluba avatar Jul 13 '20 12:07 urluba