CfnInstanceProps Struct
Properties for defining a CfnInstance.
Example
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { aws_ec2 as ec2 } from 'aws-cdk-lib';
const cfnInstanceProps: ec2.CfnInstanceProps = {
additionalInfo: 'additionalInfo',
affinity: 'affinity',
availabilityZone: 'availabilityZone',
blockDeviceMappings: [{
deviceName: 'deviceName',
// the properties below are optional
ebs: {
deleteOnTermination: false,
encrypted: false,
iops: 123,
kmsKeyId: 'kmsKeyId',
snapshotId: 'snapshotId',
volumeSize: 123,
volumeType: 'volumeType',
},
noDevice: { },
virtualName: 'virtualName',
}],
cpuOptions: {
coreCount: 123,
threadsPerCore: 123,
},
creditSpecification: {
cpuCredits: 'cpuCredits',
},
disableApiTermination: false,
ebsOptimized: false,
elasticGpuSpecifications: [{
type: 'type',
}],
elasticInferenceAccelerators: [{
type: 'type',
// the properties below are optional
count: 123,
}],
enclaveOptions: {
enabled: false,
},
hibernationOptions: {
configured: false,
},
hostId: 'hostId',
hostResourceGroupArn: 'hostResourceGroupArn',
iamInstanceProfile: 'iamInstanceProfile',
imageId: 'imageId',
instanceInitiatedShutdownBehavior: 'instanceInitiatedShutdownBehavior',
instanceType: 'instanceType',
ipv6AddressCount: 123,
ipv6Addresses: [{
ipv6Address: 'ipv6Address',
}],
kernelId: 'kernelId',
keyName: 'keyName',
launchTemplate: {
version: 'version',
// the properties below are optional
launchTemplateId: 'launchTemplateId',
launchTemplateName: 'launchTemplateName',
},
licenseSpecifications: [{
licenseConfigurationArn: 'licenseConfigurationArn',
}],
metadataOptions: {
httpEndpoint: 'httpEndpoint',
httpProtocolIpv6: 'httpProtocolIpv6',
httpPutResponseHopLimit: 123,
httpTokens: 'httpTokens',
instanceMetadataTags: 'instanceMetadataTags',
},
monitoring: false,
networkInterfaces: [{
deviceIndex: 'deviceIndex',
// the properties below are optional
associateCarrierIpAddress: false,
associatePublicIpAddress: false,
deleteOnTermination: false,
description: 'description',
enaSrdSpecification: {
enaSrdEnabled: false,
enaSrdUdpSpecification: {
enaSrdUdpEnabled: false,
},
},
groupSet: ['groupSet'],
ipv6AddressCount: 123,
ipv6Addresses: [{
ipv6Address: 'ipv6Address',
}],
networkInterfaceId: 'networkInterfaceId',
privateIpAddress: 'privateIpAddress',
privateIpAddresses: [{
primary: false,
privateIpAddress: 'privateIpAddress',
}],
secondaryPrivateIpAddressCount: 123,
subnetId: 'subnetId',
}],
placementGroupName: 'placementGroupName',
privateDnsNameOptions: {
enableResourceNameDnsAaaaRecord: false,
enableResourceNameDnsARecord: false,
hostnameType: 'hostnameType',
},
privateIpAddress: 'privateIpAddress',
propagateTagsToVolumeOnCreation: false,
ramdiskId: 'ramdiskId',
securityGroupIds: ['securityGroupIds'],
securityGroups: ['securityGroups'],
sourceDestCheck: false,
ssmAssociations: [{
documentName: 'documentName',
// the properties below are optional
associationParameters: [{
key: 'key',
value: ['value'],
}],
}],
subnetId: 'subnetId',
tags: [{
key: 'key',
value: 'value',
}],
tenancy: 'tenancy',
userData: 'userData',
volumes: [{
device: 'device',
volumeId: 'volumeId',
}],
};
Properties
additionalInfooptionalstringadditional_infooptionalstradditionalInfooptionalStringAdditionalInfooptionalstringAdditionalInfooptional*string#If you use it, the stack fails with this error: Bad property set: [Testing this property] (Service: AmazonEC2; Status Code: 400; Error Code: InvalidParameterCombination; Request ID: 0XXXXXX-49c7-4b40-8bcc-76885dcXXXXX) .
affinityoptionalstringaffinityoptionalstraffinityoptionalStringAffinityoptionalstringAffinityoptional*string#notes
If you want the instance to always restart on the same host on which it was launched, specify host . If you want the instance to restart on any available host, but try to launch onto the last host it ran on (on a best-effort basis), specify default .
availabilityZoneoptionalstringavailability_zoneoptionalstravailabilityZoneoptionalStringAvailabilityZoneoptionalstringAvailabilityZoneoptional*string#notes
If not specified, an Availability Zone will be automatically chosen for you based on the load balancing criteria for the Region.
This parameter is not supported by DescribeImageAttribute .
blockDeviceMappingsoptionalIResolvable | IResolvable | CfnInstance.BlockDeviceMappingProperty[]block_device_mappingsoptionaltyping.Union[IResolvable, typing.List[typing.Union[IResolvable, BlockDeviceMappingProperty]]]blockDeviceMappingsoptionalIResolvableBlockDeviceMappingsoptionalIResolvableBlockDeviceMappingsoptionalinterface{}#notes
By default, the block devices specified in the block device mapping for the AMI are used. You can override the AMI block device mapping using the instance block device mapping. For the root volume, you can override only the volume size, volume type, volume encryption settings, and the DeleteOnTermination setting.
After the instance is running, you can modify only the
DeleteOnTerminationparameter for the attached volumes without interrupting the instance. Modifying any other parameter results in instance replacement .
cpuOptionsoptionalIResolvable | CfnInstance.CpuOptionsPropertycpu_optionsoptionaltyping.Union[IResolvable, CpuOptionsProperty]cpuOptionsoptionalIResolvableCpuOptionsoptionalIResolvableCpuOptionsoptionalinterface{}#For more information, see Optimize CPU options in the Amazon Elastic Compute Cloud User Guide .
creditSpecificationoptionalIResolvable | CfnInstance.CreditSpecificationPropertycredit_specificationoptionaltyping.Union[IResolvable, CreditSpecificationProperty]creditSpecificationoptionalIResolvableCreditSpecificationoptionalIResolvableCreditSpecificationoptionalinterface{}#notes
Valid values are standard and unlimited . To change this attribute after launch, use ModifyInstanceCreditSpecification . For more information, see Burstable performance instances in the Amazon EC2 User Guide .
Default: standard (T2 instances) or unlimited (T3/T3a/T4g instances)
For T3 instances with host tenancy, only standard is supported.
disableApiTerminationoptionalboolean | IResolvabledisable_api_terminationoptionaltyping.Union[bool, IResolvable]disableApiTerminationoptionalBooleanDisableApiTerminationoptionalboolDisableApiTerminationoptionalinterface{}#notes
The default is false , which means that you can terminate the instance using the Amazon EC2 console, command line tools, or API. You can enable termination protection when you launch an instance, while the instance is running, or while the instance is stopped.
ebsOptimizedoptionalboolean | IResolvableebs_optimizedoptionaltyping.Union[bool, IResolvable]ebsOptimizedoptionalBooleanEbsOptimizedoptionalboolEbsOptimizedoptionalinterface{}#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.
Default: false
elasticGpuSpecificationsoptionalIResolvable | IResolvable | CfnInstance.ElasticGpuSpecificationProperty[]elastic_gpu_specificationsoptionaltyping.Union[IResolvable, typing.List[typing.Union[IResolvable, ElasticGpuSpecificationProperty]]]elasticGpuSpecificationsoptionalIResolvableElasticGpuSpecificationsoptionalIResolvableElasticGpuSpecificationsoptionalinterface{}#Amazon Elastic Graphics reached end of life on January 8, 2024.
elasticInferenceAcceleratorsoptionalIResolvable | IResolvable | CfnInstance.ElasticInferenceAcceleratorProperty[]elastic_inference_acceleratorsoptionaltyping.Union[IResolvable, typing.List[typing.Union[IResolvable, ElasticInferenceAcceleratorProperty]]]elasticInferenceAcceleratorsoptionalIResolvableElasticInferenceAcceleratorsoptionalIResolvableElasticInferenceAcceleratorsoptionalinterface{}#Amazon Elastic Inference is no longer available.
enclaveOptionsoptionalIResolvable | CfnInstance.EnclaveOptionsPropertyenclave_optionsoptionaltyping.Union[IResolvable, EnclaveOptionsProperty]enclaveOptionsoptionalIResolvableEnclaveOptionsoptionalIResolvableEnclaveOptionsoptionalinterface{}#hibernationOptionsoptionalIResolvable | CfnInstance.HibernationOptionsPropertyhibernation_optionsoptionaltyping.Union[IResolvable, HibernationOptionsProperty]hibernationOptionsoptionalIResolvableHibernationOptionsoptionalIResolvableHibernationOptionsoptionalinterface{}#notes
This parameter is valid only if the instance meets the hibernation prerequisites . For more information, see Hibernate your Amazon EC2 instance in the Amazon EC2 User Guide .
You can't enable hibernation and AWS Nitro Enclaves on the same instance.
hostIdoptionalstring | IHostRefhost_idoptionaltyping.Union[str, IHostRef]hostIdoptionalStringHostIdoptionalstringHostIdoptionalinterface{}#notes
If you don't specify an ID, Amazon EC2 launches the instance onto any available, compatible dedicated host in your account. This type of launch is called an untargeted launch. Note that for untargeted launches, you must have a compatible, dedicated host available to successfully launch instances.
hostResourceGroupArnoptionalstringhost_resource_group_arnoptionalstrhostResourceGroupArnoptionalStringHostResourceGroupArnoptionalstringHostResourceGroupArnoptional*string#If you specify a host resource group ARN, omit the Tenancy parameter or set it to host .
iamInstanceProfileoptionalstring | IInstanceProfileRefiam_instance_profileoptionaltyping.Union[str, IInstanceProfileRef]iamInstanceProfileoptionalStringIamInstanceProfileoptionalstringIamInstanceProfileoptionalinterface{}#To create a new IAM instance profile, use the AWS::IAM::InstanceProfile resource.
imageIdoptionalstringimage_idoptionalstrimageIdoptionalStringImageIdoptionalstringImageIdoptional*string#An AMI ID is required to launch an instance and must be specified here or in a launch template.
instanceInitiatedShutdownBehavioroptionalstringinstance_initiated_shutdown_behavioroptionalstrinstanceInitiatedShutdownBehavioroptionalStringInstanceInitiatedShutdownBehavioroptionalstringInstanceInitiatedShutdownBehavioroptional*string#Default: stop
instanceTypeoptionalstringinstance_typeoptionalstrinstanceTypeoptionalStringInstanceTypeoptionalstringInstanceTypeoptional*string#notes
When you change your EBS-backed instance type, instance restart or replacement behavior depends on the instance type compatibility between the old and new types. An instance with an instance store volume as the root volume is always replaced. For more information, see Change the instance type in the Amazon EC2 User Guide .
ipv6AddressCountoptionalnumberipv6_address_countoptionalint | floatipv6AddressCountoptionalNumberIpv6AddressCountoptionaldoubleIpv6AddressCountoptional*float64#notes
Amazon EC2 chooses the IPv6 addresses from the range of your subnet. You cannot specify this option and the option to assign specific IPv6 addresses in the same request. You can specify this option if you've specified a minimum number of instances to launch.
You cannot specify this option and the network interfaces option in the same request.
ipv6AddressesoptionalIResolvable | IResolvable | CfnInstance.InstanceIpv6AddressProperty[]ipv6_addressesoptionaltyping.Union[IResolvable, typing.List[typing.Union[IResolvable, InstanceIpv6AddressProperty]]]ipv6AddressesoptionalIResolvableIpv6AddressesoptionalIResolvableIpv6Addressesoptionalinterface{}#notes
You cannot specify this option and the option to assign a number of IPv6 addresses in the same request. You cannot specify this option if you've specified a minimum number of instances to launch.
You cannot specify this option and the network interfaces option in the same request.
kernelIdoptionalstringkernel_idoptionalstrkernelIdoptionalStringKernelIdoptionalstringKernelIdoptional*string#We recommend that you use PV-GRUB instead of kernels and RAM disks. For more information, see PV-GRUB in the Amazon EC2 User Guide .
keyNameoptionalstringkey_nameoptionalstrkeyNameoptionalStringKeyNameoptionalstringKeyNameoptional*string#If you do not specify a key pair, you can't connect to the instance unless you choose an AMI that is configured to allow users another way to log in.
launchTemplateoptionalIResolvable | CfnInstance.LaunchTemplateSpecificationPropertylaunch_templateoptionaltyping.Union[IResolvable, LaunchTemplateSpecificationProperty]launchTemplateoptionalIResolvableLaunchTemplateoptionalIResolvableLaunchTemplateoptionalinterface{}#Any additional parameters that you specify for the new instance overwrite the corresponding parameters included in the launch template.
licenseSpecificationsoptionalIResolvable | IResolvable | CfnInstance.LicenseSpecificationProperty[]license_specificationsoptionaltyping.Union[IResolvable, typing.List[typing.Union[IResolvable, LicenseSpecificationProperty]]]licenseSpecificationsoptionalIResolvableLicenseSpecificationsoptionalIResolvableLicenseSpecificationsoptionalinterface{}#metadataOptionsoptionalIResolvable | CfnInstance.MetadataOptionsPropertymetadata_optionsoptionaltyping.Union[IResolvable, MetadataOptionsProperty]metadataOptionsoptionalIResolvableMetadataOptionsoptionalIResolvableMetadataOptionsoptionalinterface{}#monitoringoptionalboolean | IResolvablemonitoringoptionaltyping.Union[bool, IResolvable]monitoringoptionalBooleanMonitoringoptionalboolMonitoringoptionalinterface{}#notes
Specify true to enable detailed monitoring. Otherwise, basic monitoring is enabled. For more information about detailed monitoring, see Enable or turn off detailed monitoring for your instances in the Amazon EC2 User Guide .
networkInterfacesoptionalIResolvable | IResolvable | CfnInstance.NetworkInterfaceProperty[]network_interfacesoptionaltyping.Union[IResolvable, typing.List[typing.Union[IResolvable, NetworkInterfaceProperty]]]networkInterfacesoptionalIResolvableNetworkInterfacesoptionalIResolvableNetworkInterfacesoptionalinterface{}#notes
If you use this property to point to a network interface, you must terminate the original interface before attaching a new one to allow the update of the instance to succeed.
If this resource has a public IP address and is also in a VPC that is defined in the same template, you must use the DependsOn Attribute to declare a dependency on the VPC-gateway attachment.
placementGroupNameoptionalstring | IPlacementGroupRefplacement_group_nameoptionaltyping.Union[str, IPlacementGroupRef]placementGroupNameoptionalStringPlacementGroupNameoptionalstringPlacementGroupNameoptionalinterface{}#privateDnsNameOptionsoptionalIResolvable | CfnInstance.PrivateDnsNameOptionsPropertyprivate_dns_name_optionsoptionaltyping.Union[IResolvable, PrivateDnsNameOptionsProperty]privateDnsNameOptionsoptionalIResolvablePrivateDnsNameOptionsoptionalIResolvablePrivateDnsNameOptionsoptionalinterface{}#privateIpAddressoptionalstringprivate_ip_addressoptionalstrprivateIpAddressoptionalStringPrivateIpAddressoptionalstringPrivateIpAddressoptional*string#notes
Only one private IP address can be designated as primary. You can't specify this option if you've specified the option to designate a private IP address as the primary IP address in a network interface specification. You cannot specify this option if you're launching more than one instance in the request.
You cannot specify this option and the network interfaces option in the same request.
If you make an update to an instance that requires replacement, you must assign a new private IP address. During a replacement, AWS CloudFormation creates a new instance but doesn't delete the old instance until the stack has successfully updated. If the stack update fails, AWS CloudFormation uses the old instance to roll back the stack to the previous working state. The old and new instances cannot have the same private IP address.
propagateTagsToVolumeOnCreationoptionalboolean | IResolvablepropagate_tags_to_volume_on_creationoptionaltyping.Union[bool, IResolvable]propagateTagsToVolumeOnCreationoptionalBooleanPropagateTagsToVolumeOnCreationoptionalboolPropagateTagsToVolumeOnCreationoptionalinterface{}#Note that using this feature does not assign the tags to volumes that are created separately and then attached using AWS::EC2::VolumeAttachment .
ramdiskIdoptionalstringramdisk_idoptionalstrramdiskIdoptionalStringRamdiskIdoptionalstringRamdiskIdoptional*string#notes
Some kernels require additional drivers at launch. Check the kernel requirements for information about whether you need to specify a RAM disk. To find kernel requirements, go to the AWS Resource Center and search for the kernel ID.
We recommend that you use PV-GRUB instead of kernels and RAM disks. For more information, see PV-GRUB in the Amazon EC2 User Guide .
securityGroupIdsoptionalstring | ISecurityGroupRef[]security_group_idsoptionaltyping.List[typing.Union[str, ISecurityGroupRef]]securityGroupIdsoptionalList<String>SecurityGroupIdsoptionalstring[]SecurityGroupIdsoptional*[]interface{}#You can specify the IDs of existing security groups and references to resources created by the stack template.
If you specify a network interface, you must specify any security groups as part of the network interface.
securityGroupsoptionalstring[]security_groupsoptionaltyping.List[str]securityGroupsoptionalList<String>SecurityGroupsoptionalstring[]SecurityGroupsoptional*[]*string#notes
You cannot specify this option and the network interfaces option in the same request. The list can contain both the name of existing Amazon EC2 security groups or references to AWS::EC2::SecurityGroup resources created in the template.
Default: Amazon EC2 uses the default security group.
sourceDestCheckoptionalboolean | IResolvablesource_dest_checkoptionaltyping.Union[bool, IResolvable]sourceDestCheckoptionalBooleanSourceDestCheckoptionalboolSourceDestCheckoptionalinterface{}#notes
If the value is true , source/destination checks are enabled; otherwise, they are disabled. The default value is true . You must disable source/destination checks if the instance runs services such as network address translation, routing, or firewalls.
ssmAssociationsoptionalIResolvable | IResolvable | CfnInstance.SsmAssociationProperty[]ssm_associationsoptionaltyping.Union[IResolvable, typing.List[typing.Union[IResolvable, SsmAssociationProperty]]]ssmAssociationsoptionalIResolvableSsmAssociationsoptionalIResolvableSsmAssociationsoptionalinterface{}#You can associate only one document with an instance.
subnetIdoptionalstring | ISubnetRefsubnet_idoptionaltyping.Union[str, ISubnetRef]subnetIdoptionalStringSubnetIdoptionalstringSubnetIdoptionalinterface{}#If you specify a network interface, you must specify any subnets as part of the network interface instead of using this parameter.
tagsoptionalCfnTag[]tagsoptionaltyping.List[CfnTag]tagsoptionalList<CfnTag>TagsoptionalCfnTag[]Tagsoptional*[]CfnTag#notes
These tags are not applied to the EBS volumes, such as the root volume, unless PropagateTagsToVolumeOnCreation is true .
tenancyoptionalstringtenancyoptionalstrtenancyoptionalStringTenancyoptionalstringTenancyoptional*string#An instance with a tenancy of dedicated runs on single-tenant hardware.
userDataoptionalstringuser_dataoptionalstruserDataoptionalStringUserDataoptionalstringUserDataoptional*string#notes
Any scripts in user data are run when you launch the instance. User data is limited to 16 KB. You must provide base64-encoded text. For more information, see Fn::Base64 .
If the root volume is an EBS volume and you update user data, CloudFormation restarts the instance. If the root volume is an instance store volume and you update user data, the instance is replaced.
volumesoptionalIResolvable | IResolvable | CfnInstance.VolumeProperty[]volumesoptionaltyping.Union[IResolvable, typing.List[typing.Union[IResolvable, VolumeProperty]]]volumesoptionalIResolvableVolumesoptionalIResolvableVolumesoptionalinterface{}#