InstanceProps Struct
Properties of an EC2 Instance.
Example
// Creates a distribution from an EC2 instance
declare const vpc: ec2.Vpc;
// Create an EC2 instance in a VPC. 'subnetType' can be private.
const instance = new ec2.Instance(this, 'Instance', {
vpc,
instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE3, ec2.InstanceSize.MICRO),
machineImage: ec2.MachineImage.latestAmazonLinux2023(),
vpcSubnets: { subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS },
});
new cloudfront.Distribution(this, 'myDist', {
defaultBehavior: { origin: origins.VpcOrigin.withEc2Instance(instance) },
});
Properties
allowAllIpv6Outboundbooleanallow_all_ipv6_outboundboolallowAllIpv6OutboundBooleanAllowAllIpv6OutboundboolAllowAllIpv6Outbound*bool= false#This property is only used when you do not provide a security group.
allowAllOutboundbooleanallow_all_outboundboolallowAllOutboundBooleanAllowAllOutboundboolAllowAllOutbound*bool= true#This property is only used when you do not provide a security group.
associatePublicIpAddressbooleanassociate_public_ip_addressboolassociatePublicIpAddressBooleanAssociatePublicIpAddressboolAssociatePublicIpAddress*bool= public IP address is automatical…#You cannot specify this property and ipv6AddressCount at the same time.
default
Default: public IP address is automatically assigned based on default behavior
availabilityZonestringavailability_zonestravailabilityZoneStringAvailabilityZonestringAvailabilityZone*string= Random zone.#blockDevicesBlockDevice[]block_devicestyping.List[BlockDevice]blockDevicesList<BlockDevice>BlockDevicesBlockDevice[]BlockDevices*[]BlockDevice= Uses the block device mapping of…#notes · default
Each instance that is launched has an associated root device volume, either an Amazon EBS volume or an instance store volume. You can use block device mappings to specify additional EBS volumes or instance store volumes to attach to an instance when it is launched.
Default: Uses the block device mapping of the AMI
creditSpecificationCpuCreditscredit_specificationCpuCreditscreditSpecificationCpuCreditsCreditSpecificationCpuCreditsCreditSpecificationCpuCredits= T2 instances are standard, while…#The unlimited CPU credit option is not supported for T3 instances with a dedicated host.
default
Default: T2 instances are standard, while T3, T4g, and T3a instances are unlimited.
detailedMonitoringbooleandetailed_monitoringbooldetailedMonitoringBooleanDetailedMonitoringboolDetailedMonitoring*bool= false#disableApiTerminationbooleandisable_api_terminationbooldisableApiTerminationBooleanDisableApiTerminationboolDisableApiTermination*bool= false#notes
To change this attribute after launch, use ModifyInstanceAttribute. Alternatively, if you set InstanceInitiatedShutdownBehavior to terminate, you can terminate the instance by running the shutdown command from the instance.
notes
This optimization provides dedicated throughput to Amazon EBS and an optimized configuration stack to provide optimal Amazon EBS I/O performance. This optimization isn't available with all instance types. Additional usage charges apply when using an EBS-optimized instance.
enclaveEnabledbooleanenclave_enabledboolenclaveEnabledBooleanEnclaveEnabledboolEnclaveEnabled*bool= false#notes
Nitro Enclaves requires a Nitro-based virtualized parent instance with specific Intel/AMD with at least 4 vCPUs or Graviton with at least 2 vCPUs instance types and Linux/Windows host OS, while the enclave itself supports only Linux OS.
You can't set both enclaveEnabled and hibernationEnabled to true on the same instance.
hibernationEnabledbooleanhibernation_enabledboolhibernationEnabledBooleanHibernationEnabledboolHibernationEnabled*bool= false#You can't set both enclaveEnabled and hibernationEnabled to true on the same instance.
httpProtocolIpv6booleanhttp_protocol_ipv6boolhttpProtocolIpv6BooleanHttpProtocolIpv6boolHttpProtocolIpv6*bool= false#httpPutResponseHopLimitnumberhttp_put_response_hop_limitint | floathttpPutResponseHopLimitNumberHttpPutResponseHopLimitdoubleHttpPutResponseHopLimit*float64= No default value specified by Cl…#The larger the number, the further instance metadata requests can travel.
Possible values: Integers from 1 to 64
default
Default: No default value specified by CloudFormation
httpTokensHttpTokenshttp_tokensHttpTokenshttpTokensHttpTokensHttpTokensHttpTokensHttpTokensHttpTokens= The default is conditional based…#Set to 'required' to enforce IMDSv2. This is equivalent to using requireImdsv2: true, but allows you to configure other metadata options alongside IMDSv2 enforcement.
default
Default: The default is conditional based on the AMI and account-level settings: - If the AMI's ImdsSupport is v2.0 and the account level default is no-preference, the default is HttpTokens.REQUIRED - If the AMI's ImdsSupport is v2.0 and the account level default is V1 or V2, the default is HttpTokens.OPTIONAL - See https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-options.html#instance-metadata-options-order-of-precedence
initCloudFormationInitinitCloudFormationInitinitCloudFormationInitInitCloudFormationInitInitCloudFormationInit= no CloudFormation init#initOptionsApplyCloudFormationInitOptionsinit_optionsApplyCloudFormationInitOptionsinitOptionsApplyCloudFormationInitOptionsInitOptionsApplyCloudFormationInitOptionsInitOptionsApplyCloudFormationInitOptions= default options#Describes the configsets to use and the timeout to wait
instanceInitiatedShutdownBehaviorInstanceInitiatedShutdownBehaviorinstance_initiated_shutdown_behaviorInstanceInitiatedShutdownBehaviorinstanceInitiatedShutdownBehaviorInstanceInitiatedShutdownBehaviorInstanceInitiatedShutdownBehaviorInstanceInitiatedShutdownBehaviorInstanceInitiatedShutdownBehaviorInstanceInitiatedShutdownBehavior= InstanceInitiatedShutdownBehavio…#default
Default: InstanceInitiatedShutdownBehavior.STOP
instanceMetadataTagsbooleaninstance_metadata_tagsboolinstanceMetadataTagsBooleanInstanceMetadataTagsboolInstanceMetadataTags*bool= false#Set to disabled to turn off access to instance tags from the instance metadata.
instanceNamestringinstance_namestrinstanceNameStringInstanceNamestringInstanceName*string= CDK generated name#instanceProfileIInstanceProfileinstance_profileIInstanceProfileinstanceProfileIInstanceProfileInstanceProfileIInstanceProfileInstanceProfileIInstanceProfile= No instance profile#Note: You can provide an instanceProfile or a role, but not both.
instanceTypeInstanceTypeinstance_typeInstanceTypeinstanceTypeInstanceTypeInstanceTypeInstanceTypeInstanceTypeInstanceTyperequired#ipv6AddressCountnumberipv6_address_countint | floatipv6AddressCountNumberIpv6AddressCountdoubleIpv6AddressCount*float64= For instances associated with an…#Amazon EC2 chooses the IPv6 addresses from the range of your subnet.
You cannot specify this property and associatePublicIpAddress at the same time.
default
Default: For instances associated with an IPv6 subnet, use 1; otherwise, use 0.
keyNamestringkey_namestrkeyNameStringKeyNamestringKeyName*string= No SSH access will be possible.deprecated#keyPairIKeyPairkey_pairIKeyPairkeyPairIKeyPairKeyPairIKeyPairKeyPairIKeyPair= No SSH access will be possible.#machineImageIMachineImagemachine_imageIMachineImagemachineImageIMachineImageMachineImageIMachineImageMachineImageIMachineImagerequired#placementGroupIPlacementGroupRefplacement_groupIPlacementGroupRefplacementGroupIPlacementGroupRefPlacementGroupIPlacementGroupRefPlacementGroupIPlacementGroupRef= no placement group will be used …#default
Default: no placement group will be used for this instance.
privateIpAddressstringprivate_ip_addressstrprivateIpAddressStringPrivateIpAddressstringPrivateIpAddress*string= no association#Private IP should be available within the VPC that the instance is build within.
propagateTagsToVolumeOnCreationbooleanpropagate_tags_to_volume_on_creationboolpropagateTagsToVolumeOnCreationBooleanPropagateTagsToVolumeOnCreationboolPropagateTagsToVolumeOnCreation*bool= false#requireImdsv2booleanrequire_imdsv2boolrequireImdsv2BooleanRequireImdsv2boolRequireImdsv2*bool= false#notes
This is a simple boolean flag that enforces IMDSv2 by creating a Launch Template with httpTokens: 'required'. Use this for straightforward IMDSv2 enforcement.
For more granular control over metadata options (like disabling the metadata endpoint, configuring hop limits, or enabling instance tags), use the individual metadata option properties instead.
resourceSignalTimeoutDurationresource_signal_timeoutDurationresourceSignalTimeoutDurationResourceSignalTimeoutDurationResourceSignalTimeoutDuration= Duration.minutes(5)#The maximum value is 43200 (12 hours).
The role must be assumable by the service principal ec2.amazonaws.com: Note: You can provide an instanceProfile or a role, but not both.
default · example
Default: A role will automatically be created, it can be accessed via the role property
const role = new iam.Role(this, 'MyRole', {
assumedBy: new iam.ServicePrincipal('ec2.amazonaws.com')
});
securityGroupISecurityGroupsecurity_groupISecurityGroupsecurityGroupISecurityGroupSecurityGroupISecurityGroupSecurityGroupISecurityGroup= create new security group#sourceDestCheckbooleansource_dest_checkboolsourceDestCheckBooleanSourceDestCheckboolSourceDestCheck*bool= true#This controls whether source/destination checking is enabled on the instance. A value of true means that checking is enabled, and false means that checking is disabled. The value must be false for the instance to perform NAT.
ssmSessionPermissionsbooleanssm_session_permissionsboolssmSessionPermissionsBooleanSsmSessionPermissionsboolSsmSessionPermissions*bool= false#notes
Setting this to true adds the necessary permissions to connect to the instance using SSM Session Manager. You can do this from the AWS Console.
NOTE: Setting this flag to true may not be enough by itself. You must also use an AMI that comes with the SSM Agent, or install the SSM Agent yourself. See Working with SSM Agent in the SSM Developer Guide.
userDataUserDatauser_dataUserDatauserDataUserDataUserDataUserDataUserDataUserData= A UserData object appropriate fo…#The UserData may still be mutated after creation.
default
Default: A UserData object appropriate for the MachineImage's Operating System is created.
userDataCausesReplacementbooleanuser_data_causes_replacementbooluserDataCausesReplacementBooleanUserDataCausesReplacementboolUserDataCausesReplacement*bool= true if `initOptions` is specifi…#notes · default
Depending the EC2 instance type, changing UserData either restarts the instance or replaces the instance.
- Instance store-backed instances are replaced.
- EBS-backed instances are restarted.
By default, restarting does not execute the new UserData so you will need a different mechanism to ensure the instance is restarted.
Setting this to true will make the instance's Logical ID depend on the UserData, which will cause CloudFormation to replace it if the UserData changes.
Default: true if initOptions is specified, false otherwise.
vpcSubnetsSubnetSelectionvpc_subnetsSubnetSelectionvpcSubnetsSubnetSelectionVpcSubnetsSubnetSelectionVpcSubnetsSubnetSelection= Private subnets.#