Class: AWSCDK::EC2::NatInstanceProps

Inherits:
Jsii::Struct
  • Object
show all
Defined in:
ec2/nat_instance_props.rb

Overview

Properties for a NAT instance.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instance_type:, associate_public_ip_address: nil, credit_specification: nil, default_allowed_traffic: nil, key_name: nil, key_pair: nil, machine_image: nil, security_group: nil, user_data: nil) ⇒ NatInstanceProps

Returns a new instance of NatInstanceProps.

Parameters:

  • instance_type (AWSCDK::EC2::InstanceType)

    Instance type of the NAT instance.

  • associate_public_ip_address (Boolean, nil) (defaults to: nil)

    Whether to associate a public IP address to the primary network interface attached to this instance.

  • credit_specification (AWSCDK::EC2::CpuCredits, nil) (defaults to: nil)

    Specifying the CPU credit type for burstable EC2 instance types (T2, T3, T3a, etc).

  • default_allowed_traffic (AWSCDK::EC2::NatTrafficDirection, nil) (defaults to: nil)

    Direction to allow all traffic through the NAT instance by default.

  • key_name (String, nil) (defaults to: nil)

    Name of SSH keypair to grant access to instance.

  • key_pair (AWSCDK::EC2::IKeyPair, nil) (defaults to: nil)

    The SSH keypair to grant access to the instance.

  • machine_image (AWSCDK::EC2::IMachineImage, nil) (defaults to: nil)

    The machine image (AMI) to use.

  • security_group (AWSCDK::EC2::ISecurityGroup, nil) (defaults to: nil)

    Security Group for NAT instances.

  • user_data (AWSCDK::EC2::UserData, nil) (defaults to: nil)

    Custom user data to run on the NAT instances.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'ec2/nat_instance_props.rb', line 16

def initialize(instance_type:, associate_public_ip_address: nil, credit_specification: nil, default_allowed_traffic: nil, key_name: nil, key_pair: nil, machine_image: nil, security_group: nil, user_data: nil)
  @instance_type = instance_type
  Jsii::Type.check_type(@instance_type, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfZWMyLkluc3RhbmNlVHlwZSJ9")), "instanceType")
  @associate_public_ip_address = associate_public_ip_address
  Jsii::Type.check_type(@associate_public_ip_address, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJib29sZWFuIn0=")), "associatePublicIpAddress") unless @associate_public_ip_address.nil?
  @credit_specification = credit_specification
  Jsii::Type.check_type(@credit_specification, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfZWMyLkNwdUNyZWRpdHMifQ==")), "creditSpecification") unless @credit_specification.nil?
  @default_allowed_traffic = default_allowed_traffic
  Jsii::Type.check_type(@default_allowed_traffic, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfZWMyLk5hdFRyYWZmaWNEaXJlY3Rpb24ifQ==")), "defaultAllowedTraffic") unless @default_allowed_traffic.nil?
  @key_name = key_name
  Jsii::Type.check_type(@key_name, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "keyName") unless @key_name.nil?
  @key_pair = key_pair
  Jsii::Type.check_type(@key_pair, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfZWMyLklLZXlQYWlyIn0=")), "keyPair") unless @key_pair.nil?
  @machine_image = machine_image
  Jsii::Type.check_type(@machine_image, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfZWMyLklNYWNoaW5lSW1hZ2UifQ==")), "machineImage") unless @machine_image.nil?
  @security_group = security_group
  Jsii::Type.check_type(@security_group, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfZWMyLklTZWN1cml0eUdyb3VwIn0=")), "securityGroup") unless @security_group.nil?
  @user_data = user_data
  Jsii::Type.check_type(@user_data, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfZWMyLlVzZXJEYXRhIn0=")), "userData") unless @user_data.nil?
end

Instance Attribute Details

#associate_public_ip_addressBoolean? (readonly)

Note:

Default: undefined - No public IP address associated

Whether to associate a public IP address to the primary network interface attached to this instance.

Returns:

  • (Boolean, nil)


45
46
47
# File 'ec2/nat_instance_props.rb', line 45

def associate_public_ip_address
  @associate_public_ip_address
end

#credit_specificationAWSCDK::EC2::CpuCredits? (readonly)

Note:

Default: - T2 instances are standard, while T3, T4g, and T3a instances are unlimited.

Specifying the CPU credit type for burstable EC2 instance types (T2, T3, T3a, etc).

The unlimited CPU credit option is not supported for T3 instances with dedicated host (host) tenancy.

Returns:



52
53
54
# File 'ec2/nat_instance_props.rb', line 52

def credit_specification
  @credit_specification
end

#default_allowed_trafficAWSCDK::EC2::NatTrafficDirection? (readonly)

Note:

Default: NatTrafficDirection.INBOUND_AND_OUTBOUND

Direction to allow all traffic through the NAT instance by default.

By default, inbound and outbound traffic is allowed.

If you set this to another value than INBOUND_AND_OUTBOUND, you must configure the NAT instance's security groups in another way, either by passing in a fully configured Security Group using the security_group property, or by configuring it using the .securityGroup or .connections members after passing the NAT Instance Provider to a Vpc.



65
66
67
# File 'ec2/nat_instance_props.rb', line 65

def default_allowed_traffic
  @default_allowed_traffic
end

#instance_typeAWSCDK::EC2::InstanceType (readonly)

Instance type of the NAT instance.



40
41
42
# File 'ec2/nat_instance_props.rb', line 40

def instance_type
  @instance_type
end

#key_nameString? (readonly)

Note:

Default: - No SSH access will be possible.

Name of SSH keypair to grant access to instance.

Returns:

  • (String, nil)


71
72
73
# File 'ec2/nat_instance_props.rb', line 71

def key_name
  @key_name
end

#key_pairAWSCDK::EC2::IKeyPair? (readonly)

Note:

Default: - No SSH access will be possible.

The SSH keypair to grant access to the instance.

Returns:



76
77
78
# File 'ec2/nat_instance_props.rb', line 76

def key_pair
  @key_pair
end

#machine_imageAWSCDK::EC2::IMachineImage? (readonly)

Note:

Default: - Latest NAT instance image

The machine image (AMI) to use.

By default, will do an AMI lookup for the latest NAT instance image.

If you have a specific AMI ID you want to use, pass a GenericLinuxImage. For example:

AWSCDK::EC2::NatProvider.instance({
    instance_type: AWSCDK::EC2::InstanceType.new("t3.micro"),
    machine_image: AWSCDK::EC2::GenericLinuxImage.new({
        "us-east-2" => "ami-0f9c61b5a562a16af",
    }),
})

Returns:



94
95
96
# File 'ec2/nat_instance_props.rb', line 94

def machine_image
  @machine_image
end

#security_groupAWSCDK::EC2::ISecurityGroup? (readonly)

Deprecated.
  • Cannot create a new security group before the VPC is created, and cannot create the VPC without the NAT provider. Set {@link defaultAllowedTraffic } to {@link NatTrafficDirection.NONE } and use {@link NatInstanceProviderV2.gatewayInstances } to retrieve the instances on the fly and add security groups
Note:

Default: - A new security group will be created

Security Group for NAT instances.

Examples:

nat_gateway_provider = AWSCDK::EC2::NatProvider.instance_v2({
    instance_type: AWSCDK::EC2::InstanceType.new("t3.small"),
    default_allowed_traffic: AWSCDK::EC2::NatTrafficDirection::NONE,
})
vpc = AWSCDK::EC2::VPC.new(self, "Vpc", {nat_gateway_provider: nat_gateway_provider})

security_group = AWSCDK::EC2::SecurityGroup.new(self, "SecurityGroup", {
    vpc: vpc,
    allow_all_outbound: false,
})
security_group.add_egress_rule(AWSCDK::EC2::Peer.any_ipv4, AWSCDK::EC2::Port.tcp(443))
nat_gateway_provider.gateway_instances.each do |gateway_instance|
  gateway_instance.add_security_group(security_group)
end

Returns:



115
116
117
# File 'ec2/nat_instance_props.rb', line 115

def security_group
  @security_group
end

#user_dataAWSCDK::EC2::UserData? (readonly)

Note:

Default: UserData.forLinux().addCommands(...NatInstanceProviderV2.DEFAULT_USER_DATA_COMMANDS); - Appropriate user data commands to initialize and configure the NAT instances

Custom user data to run on the NAT instances.



121
122
123
# File 'ec2/nat_instance_props.rb', line 121

def user_data
  @user_data
end

Class Method Details

.jsii_propertiesObject



123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'ec2/nat_instance_props.rb', line 123

def self.jsii_properties
  {
    :instance_type => "instanceType",
    :associate_public_ip_address => "associatePublicIpAddress",
    :credit_specification => "creditSpecification",
    :default_allowed_traffic => "defaultAllowedTraffic",
    :key_name => "keyName",
    :key_pair => "keyPair",
    :machine_image => "machineImage",
    :security_group => "securityGroup",
    :user_data => "userData",
  }
end

Instance Method Details

#to_jsiiObject



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'ec2/nat_instance_props.rb', line 137

def to_jsii
  result = {}
  result.merge!({
    "instanceType" => @instance_type,
    "associatePublicIpAddress" => @associate_public_ip_address,
    "creditSpecification" => @credit_specification,
    "defaultAllowedTraffic" => @default_allowed_traffic,
    "keyName" => @key_name,
    "keyPair" => @key_pair,
    "machineImage" => @machine_image,
    "securityGroup" => @security_group,
    "userData" => @user_data,
  })
  result.compact
end