AWS Fundamentals Logo
AWS Fundamentals

Amazon EC2

137 CDK constructs available in aws-cdk-lib/aws-ec2

import * as ec2 from 'aws-cdk-lib/aws-ec2';

L2 Constructs24

Higher-level abstractions with sensible defaults and convenience methods.

BastionHostLinux

L2

This creates a linux bastion host you can use to connect to other instances or services in your VPC. The recommended way to connect to the bastion host is by using AWS Systems Manager Session Manager. The operating system is Amazon Linux 2 with the latest SSM agent installed You can also configure this bastion host to allow connections via SSH

ClientVpnAuthorizationRule

L2

A client VPN authorization rule.

ClientVpnEndpoint

L2

A client VPN connection.

ClientVpnRoute

L2

A client VPN route.

FlowLog

L2

A VPC flow log.

GatewayVpcEndpoint

L2

A gateway VPC endpoint.

Instance

L2

This represents a single EC2 instance.

InterfaceVpcEndpoint

L2

A interface VPC endpoint.

KeyPair

L2

An EC2 Key Pair.

LaunchTemplate

L2

This represents an EC2 LaunchTemplate.

NetworkAcl

L2

Define a new custom network ACL. By default, will deny all inbound and outbound traffic unless entries are added explicitly allowing it.

NetworkAclEntry

L2

Define an entry in a Network ACL table.

PlacementGroup

L2

Defines a placement group. Placement groups give you fine-grained control over where your instances are provisioned.

PrefixList

L2

A managed prefix list.

PrivateSubnet

L2

Represents a private VPC subnet resource.

PublicSubnet

L2

Represents a public VPC subnet resource.

SecurityGroup

L2

Creates an Amazon EC2 security group within a VPC. Security Groups act like a firewall with a set of rules, and are associated with any AWS resource that has or creates Elastic Network Interfaces (ENIs). A typical example of a resource that has a security group is an Instance (or Auto Scaling Group of instances) If you are defining new infrastructure in CDK, there is a good chance you won't have to interact with this class at all. Like IAM Roles, Security Groups need to exist to control access between AWS resources, but CDK will automatically generate and populate them with least-privilege permissions for you so you can concentrate on your business logic. All Constructs that require Security Groups will create one for you if you don't specify one at construction. After construction, you can selectively allow connections to and between constructs via--for example-- the `instance.connections` object. Think of it as "allowing connections to your instance", rather than "adding ingress rules a security group". See the [Allowing Connections](https://docs.aws.amazon.com/cdk/api/latest/docs/aws-cdk-lib.aws_ec2-readme.html#allowing-connections) section in the library documentation for examples. Direct manipulation of the Security Group through `addIngressRule` and `addEgressRule` is possible, but mutation through the `.connections` object is recommended. If you peer two constructs with security groups this way, appropriate rules will be created in both. If you have an existing security group you want to use in your CDK application, you would import it like this: ```ts const securityGroup = ec2.SecurityGroup.fromSecurityGroupId(this, 'SG', 'sg-12345', { mutable: false }); ```

Subnet

L2

Represents a new VPC subnet resource.

SubnetNetworkAclAssociation

L2

Volume

L2

Creates a new EBS Volume in AWS EC2.

Vpc

L2

Define an AWS Virtual Private Cloud. See the package-level documentation of this package for an overview of the various dimensions in which you can configure your VPC. For example: ```ts const vpc = new ec2.Vpc(this, 'TheVPC', { ipAddresses: ec2.IpAddresses.cidr('10.0.0.0/16'), }) // Iterate the private subnets const selection = vpc.selectSubnets({ subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS }); for (const subnet of selection.subnets) { // ... } ```

VpcEndpointService

L2

A VPC endpoint service.

VpnConnection

L2

Define a VPN Connection.

VpnGateway

L2

The VPN Gateway that shall be added to the VPC.

L1 Constructs113

Direct CloudFormation resource mappings. One-to-one with CloudFormation resource types.

CfnCapacityManagerDataExport

L1
AWS::EC2::CapacityManagerDataExport

CfnCapacityReservation

L1
AWS::EC2::CapacityReservation

CfnCapacityReservationFleet

L1
AWS::EC2::CapacityReservationFleet

CfnCarrierGateway

L1
AWS::EC2::CarrierGateway

CfnClientVpnAuthorizationRule

L1
AWS::EC2::ClientVpnAuthorizationRule

CfnClientVpnEndpoint

L1
AWS::EC2::ClientVpnEndpoint

CfnClientVpnRoute

L1
AWS::EC2::ClientVpnRoute

CfnClientVpnTargetNetworkAssociation

L1
AWS::EC2::ClientVpnTargetNetworkAssociation

CfnCustomerGateway

L1
AWS::EC2::CustomerGateway

CfnDHCPOptions

L1
AWS::EC2::DHCPOptions

CfnEC2Fleet

L1
AWS::EC2::EC2Fleet

CfnEgressOnlyInternetGateway

L1
AWS::EC2::EgressOnlyInternetGateway

CfnEIP

L1
AWS::EC2::EIP

CfnEIPAssociation

L1
AWS::EC2::EIPAssociation

CfnEnclaveCertificateIamRoleAssociation

L1
AWS::EC2::EnclaveCertificateIamRoleAssociation

CfnFlowLog

L1
AWS::EC2::FlowLog

CfnGatewayRouteTableAssociation

L1
AWS::EC2::GatewayRouteTableAssociation

CfnHost

L1
AWS::EC2::Host

CfnInstance

L1
AWS::EC2::Instance

CfnInstanceConnectEndpoint

L1
AWS::EC2::InstanceConnectEndpoint

CfnInternetGateway

L1
AWS::EC2::InternetGateway

CfnIPAM

L1
AWS::EC2::IPAM

CfnIPAMAllocation

L1
AWS::EC2::IPAMAllocation

CfnIPAMPool

L1
AWS::EC2::IPAMPool

CfnIPAMPoolCidr

L1
AWS::EC2::IPAMPoolCidr

CfnIPAMPrefixListResolver

L1
AWS::EC2::IPAMPrefixListResolver

CfnIPAMPrefixListResolverTarget

L1
AWS::EC2::IPAMPrefixListResolverTarget

CfnIPAMResourceDiscovery

L1
AWS::EC2::IPAMResourceDiscovery

CfnIPAMResourceDiscoveryAssociation

L1
AWS::EC2::IPAMResourceDiscoveryAssociation

CfnIPAMScope

L1
AWS::EC2::IPAMScope

CfnIpPoolRouteTableAssociation

L1
AWS::EC2::IpPoolRouteTableAssociation

CfnKeyPair

L1
AWS::EC2::KeyPair

CfnLaunchTemplate

L1
AWS::EC2::LaunchTemplate

CfnLocalGatewayRoute

L1
AWS::EC2::LocalGatewayRoute

CfnLocalGatewayRouteTable

L1
AWS::EC2::LocalGatewayRouteTable

CfnLocalGatewayRouteTableVirtualInterfaceGroupAssociation

L1
AWS::EC2::LocalGatewayRouteTableVirtualInterfaceGroupAssociation

CfnLocalGatewayRouteTableVPCAssociation

L1
AWS::EC2::LocalGatewayRouteTableVPCAssociation

CfnLocalGatewayVirtualInterface

L1
AWS::EC2::LocalGatewayVirtualInterface

CfnLocalGatewayVirtualInterfaceGroup

L1
AWS::EC2::LocalGatewayVirtualInterfaceGroup

CfnNatGateway

L1
AWS::EC2::NatGateway

CfnNetworkAcl

L1
AWS::EC2::NetworkAcl

CfnNetworkAclEntry

L1
AWS::EC2::NetworkAclEntry

CfnNetworkInsightsAccessScope

L1
AWS::EC2::NetworkInsightsAccessScope

CfnNetworkInsightsAccessScopeAnalysis

L1
AWS::EC2::NetworkInsightsAccessScopeAnalysis

CfnNetworkInsightsAnalysis

L1
AWS::EC2::NetworkInsightsAnalysis

CfnNetworkInsightsPath

L1
AWS::EC2::NetworkInsightsPath

CfnNetworkInterface

L1
AWS::EC2::NetworkInterface

CfnNetworkInterfaceAttachment

L1
AWS::EC2::NetworkInterfaceAttachment

CfnNetworkInterfacePermission

L1
AWS::EC2::NetworkInterfacePermission

CfnNetworkPerformanceMetricSubscription

L1
AWS::EC2::NetworkPerformanceMetricSubscription

CfnPlacementGroup

L1
AWS::EC2::PlacementGroup

CfnPrefixList

L1
AWS::EC2::PrefixList

CfnRoute

L1
AWS::EC2::Route

CfnRouteServer

L1
AWS::EC2::RouteServer

CfnRouteServerAssociation

L1
AWS::EC2::RouteServerAssociation

CfnRouteServerEndpoint

L1
AWS::EC2::RouteServerEndpoint

CfnRouteServerPeer

L1
AWS::EC2::RouteServerPeer

CfnRouteServerPropagation

L1
AWS::EC2::RouteServerPropagation

CfnRouteTable

L1
AWS::EC2::RouteTable

CfnSecurityGroup

L1
AWS::EC2::SecurityGroup

CfnSecurityGroupEgress

L1
AWS::EC2::SecurityGroupEgress

CfnSecurityGroupIngress

L1
AWS::EC2::SecurityGroupIngress

CfnSecurityGroupVpcAssociation

L1
AWS::EC2::SecurityGroupVpcAssociation

CfnSnapshotBlockPublicAccess

L1
AWS::EC2::SnapshotBlockPublicAccess

CfnSpotFleet

L1
AWS::EC2::SpotFleet

CfnSqlHaStandbyDetectedInstance

L1
AWS::EC2::SqlHaStandbyDetectedInstance

CfnSubnet

L1
AWS::EC2::Subnet

CfnSubnetCidrBlock

L1
AWS::EC2::SubnetCidrBlock

CfnSubnetNetworkAclAssociation

L1
AWS::EC2::SubnetNetworkAclAssociation

CfnSubnetRouteTableAssociation

L1
AWS::EC2::SubnetRouteTableAssociation

CfnTrafficMirrorFilter

L1
AWS::EC2::TrafficMirrorFilter

CfnTrafficMirrorFilterRule

L1
AWS::EC2::TrafficMirrorFilterRule

CfnTrafficMirrorSession

L1
AWS::EC2::TrafficMirrorSession

CfnTrafficMirrorTarget

L1
AWS::EC2::TrafficMirrorTarget

CfnTransitGateway

L1
AWS::EC2::TransitGateway

CfnTransitGatewayAttachment

L1
AWS::EC2::TransitGatewayAttachment

CfnTransitGatewayConnect

L1
AWS::EC2::TransitGatewayConnect

CfnTransitGatewayConnectPeer

L1
AWS::EC2::TransitGatewayConnectPeer

CfnTransitGatewayMeteringPolicy

L1
AWS::EC2::TransitGatewayMeteringPolicy

CfnTransitGatewayMeteringPolicyEntry

L1
AWS::EC2::TransitGatewayMeteringPolicyEntry

CfnTransitGatewayMulticastDomain

L1
AWS::EC2::TransitGatewayMulticastDomain

CfnTransitGatewayMulticastDomainAssociation

L1
AWS::EC2::TransitGatewayMulticastDomainAssociation

CfnTransitGatewayMulticastGroupMember

L1
AWS::EC2::TransitGatewayMulticastGroupMember

CfnTransitGatewayMulticastGroupSource

L1
AWS::EC2::TransitGatewayMulticastGroupSource

CfnTransitGatewayPeeringAttachment

L1
AWS::EC2::TransitGatewayPeeringAttachment

CfnTransitGatewayRoute

L1
AWS::EC2::TransitGatewayRoute

CfnTransitGatewayRouteTable

L1
AWS::EC2::TransitGatewayRouteTable

CfnTransitGatewayRouteTableAssociation

L1
AWS::EC2::TransitGatewayRouteTableAssociation

CfnTransitGatewayRouteTablePropagation

L1
AWS::EC2::TransitGatewayRouteTablePropagation

CfnTransitGatewayVpcAttachment

L1
AWS::EC2::TransitGatewayVpcAttachment

CfnVerifiedAccessEndpoint

L1
AWS::EC2::VerifiedAccessEndpoint

CfnVerifiedAccessGroup

L1
AWS::EC2::VerifiedAccessGroup

CfnVerifiedAccessInstance

L1
AWS::EC2::VerifiedAccessInstance

CfnVerifiedAccessTrustProvider

L1
AWS::EC2::VerifiedAccessTrustProvider

CfnVolume

L1
AWS::EC2::Volume

CfnVolumeAttachment

L1
AWS::EC2::VolumeAttachment

CfnVPC

L1
AWS::EC2::VPC

CfnVPCBlockPublicAccessExclusion

L1
AWS::EC2::VPCBlockPublicAccessExclusion

CfnVPCBlockPublicAccessOptions

L1
AWS::EC2::VPCBlockPublicAccessOptions

CfnVPCCidrBlock

L1
AWS::EC2::VPCCidrBlock

CfnVPCDHCPOptionsAssociation

L1
AWS::EC2::VPCDHCPOptionsAssociation

CfnVPCEncryptionControl

L1
AWS::EC2::VPCEncryptionControl

CfnVPCEndpoint

L1
AWS::EC2::VPCEndpoint

CfnVPCEndpointConnectionNotification

L1
AWS::EC2::VPCEndpointConnectionNotification

CfnVPCEndpointService

L1
AWS::EC2::VPCEndpointService

CfnVPCEndpointServicePermissions

L1
AWS::EC2::VPCEndpointServicePermissions

CfnVPCGatewayAttachment

L1
AWS::EC2::VPCGatewayAttachment

CfnVPCPeeringConnection

L1
AWS::EC2::VPCPeeringConnection

CfnVPNConcentrator

L1
AWS::EC2::VPNConcentrator

CfnVPNConnection

L1
AWS::EC2::VPNConnection

CfnVPNConnectionRoute

L1
AWS::EC2::VPNConnectionRoute

CfnVPNGateway

L1
AWS::EC2::VPNGateway

CfnVPNGatewayRoutePropagation

L1
AWS::EC2::VPNGatewayRoutePropagation

Get the Amazon EC2 Cheat Sheet

Everything you need to know about Amazon EC2 on one page. HD quality, print-friendly.

Download Free Infographic

Quick Facts

L2 Constructs24
L1 Constructs113
Moduleaws-cdk-lib/aws-ec2