# CfnInstance

Specifies an EC2 instance.

If an Elastic IP address is attached to your instance, AWS CloudFormation reattaches the Elastic IP address after it updates the instance. For more information about updating stacks, see [AWS CloudFormation Stacks Updates](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks.html) .

Extends: Construct › CfnElement › CfnRefElement › CfnResource › CfnInstance
Implements: IInspectable, ITaggable, IEnvironmentAware, IInstanceRef, IConstruct, IDependable

- CloudFormation: [`AWS::EC2::Instance`](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-ec2-instance.html)
- Source: Generated code
- Type last changed: v2.252.0 · 30 Apr 2026

## Example

```ts
// 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 cfnInstance = new ec2.CfnInstance(this, 'MyCfnInstance', /* all optional props */ {
  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',
  }],
});
```

## Initializer

```ts
new CfnInstance(scope: Construct, id: string, props?: CfnInstanceProps)
```

## Construct Props

- `additionalInfo`: string — This property is reserved for internal use.

  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)` .

- `affinity`: string — Indicates whether the instance is associated with a dedicated host.

  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` .

- `availabilityZone`: string — The Availability Zone of the instance.

  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](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeImageAttribute.html) .

- `blockDeviceMappings`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnInstance.BlockDeviceMappingProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnInstance.BlockDeviceMappingProperty.html)[] — The block device mapping entries that defines the block devices to attach to the instance at launch.

  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 `DeleteOnTermination` parameter for the attached volumes without interrupting the instance. Modifying any other parameter results in instance [replacement](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-replacement) .

- `cpuOptions`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnInstance.CpuOptionsProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnInstance.CpuOptionsProperty.html) — The CPU options for the instance.

  For more information, see [Optimize CPU options](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-optimize-cpu.html) in the *Amazon Elastic Compute Cloud User Guide* .

- `creditSpecification`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnInstance.CreditSpecificationProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnInstance.CreditSpecificationProperty.html) — The credit option for CPU usage of the burstable performance instance.

  Valid values are `standard` and `unlimited` . To change this attribute after launch, use [ModifyInstanceCreditSpecification](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_ModifyInstanceCreditSpecification.html) . For more information, see [Burstable performance instances](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/burstable-performance-instances.html) 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.

- `disableApiTermination`: boolean | [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) — Indicates whether termination protection is enabled for the instance.

  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.

- `ebsOptimized`: boolean | [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) — Indicates whether the instance is optimized for Amazon EBS I/O.

  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`

- `elasticGpuSpecifications`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnInstance.ElasticGpuSpecificationProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnInstance.ElasticGpuSpecificationProperty.html)[] — An elastic GPU to associate with the instance.

  > Amazon Elastic Graphics reached end of life on January 8, 2024.

- `elasticInferenceAccelerators`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnInstance.ElasticInferenceAcceleratorProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnInstance.ElasticInferenceAcceleratorProperty.html)[] — An elastic inference accelerator to associate with the instance.

  > Amazon Elastic Inference is no longer available.

- `enclaveOptions`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnInstance.EnclaveOptionsProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnInstance.EnclaveOptionsProperty.html) — Indicates whether the instance is enabled for AWS Nitro Enclaves.

- `hibernationOptions`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnInstance.HibernationOptionsProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnInstance.HibernationOptionsProperty.html) — Indicates whether an instance is enabled for hibernation.

  This parameter is valid only if the instance meets the [hibernation prerequisites](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/hibernating-prerequisites.html) . For more information, see [Hibernate your Amazon EC2 instance](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Hibernate.html) in the *Amazon EC2 User Guide* .

  You can't enable hibernation and AWS Nitro Enclaves on the same instance.

- `hostId`: string | [IHostRef](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_ec2.IHostRef.html) — If you specify host for the `Affinity` property, the ID of a dedicated host that the instance is associated with.

  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.

- `hostResourceGroupArn`: string — The ARN of the host resource group in which to launch the instances.

  If you specify a host resource group ARN, omit the *Tenancy* parameter or set it to `host` .

- `iamInstanceProfile`: string | [IInstanceProfileRef](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_iam.IInstanceProfileRef.html) — The name of an IAM instance profile.

  To create a new IAM instance profile, use the [AWS::IAM::InstanceProfile](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-instanceprofile.html) resource.

- `imageId`: string — The ID of the AMI.

  An AMI ID is required to launch an instance and must be specified here or in a launch template.

- `instanceInitiatedShutdownBehavior`: string — Indicates whether an instance stops or terminates when you initiate shutdown from the instance (using the operating system command for system shutdown).

  Default: `stop`

- `instanceType`: string — The instance type. For more information, see [Instance types](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html) in the *Amazon EC2 User Guide* .

  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](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-resize.html) in the *Amazon EC2 User Guide* .

- `ipv6AddressCount`: number — The number of IPv6 addresses to associate with the primary network interface.

  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.

- `ipv6Addresses`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnInstance.InstanceIpv6AddressProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnInstance.InstanceIpv6AddressProperty.html)[] — The IPv6 addresses from the range of the subnet to associate with the primary network interface.

  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.

- `kernelId`: string — The ID of the kernel.

  > We recommend that you use PV-GRUB instead of kernels and RAM disks. For more information, see [PV-GRUB](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/UserProvidedkernels.html) in the *Amazon EC2 User Guide* .

- `keyName`: string — The name of the key pair. For more information, see [Create a key pair for your EC2 instance](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/create-key-pairs.html) .

  > 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.

- `launchTemplate`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnInstance.LaunchTemplateSpecificationProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnInstance.LaunchTemplateSpecificationProperty.html) — The launch template.

  Any additional parameters that you specify for the new instance overwrite the corresponding parameters included in the launch template.

- `licenseSpecifications`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnInstance.LicenseSpecificationProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnInstance.LicenseSpecificationProperty.html)[] — The license configurations.

- `metadataOptions`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnInstance.MetadataOptionsProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnInstance.MetadataOptionsProperty.html) — The metadata options for the instance.

- `monitoring`: boolean | [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) — Specifies whether detailed monitoring is enabled for the instance.

  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](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-cloudwatch-new.html) in the *Amazon EC2 User Guide* .

- `networkInterfaces`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnInstance.NetworkInterfaceProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnInstance.NetworkInterfaceProperty.html)[] — The network interfaces to associate with the instance.

  > 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](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-dependson.html) to declare a dependency on the VPC-gateway attachment.

- `placementGroupName`: string | [IPlacementGroupRef](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_ec2.IPlacementGroupRef.html) — The name of an existing placement group that you want to launch the instance into (cluster | partition | spread).

- `privateDnsNameOptions`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnInstance.PrivateDnsNameOptionsProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnInstance.PrivateDnsNameOptionsProperty.html) — The options for the instance hostname.

- `privateIpAddress`: string — The primary IPv4 address. You must specify a value from the IPv4 address range of the subnet.

  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.

- `propagateTagsToVolumeOnCreation`: boolean | [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) — Indicates whether to assign the tags specified in the `Tags` property to the volumes specified in the `BlockDeviceMappings` property.

  Note that using this feature does not assign the tags to volumes that are created separately and then attached using `AWS::EC2::VolumeAttachment` .

- `ramdiskId`: string — The ID of the RAM disk to select.

  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](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/UserProvidedkernels.html) in the *Amazon EC2 User Guide* .

- `securityGroupIds`: string | [ISecurityGroupRef](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_ec2.ISecurityGroupRef.html)[] — The IDs of the security groups.

  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.

- `securityGroups`: string[] — [Default VPC] The names of the security groups. For a nondefault VPC, you must use security group IDs instead.

  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.

- `sourceDestCheck`: boolean | [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) — Enable or disable source/destination checks, which ensure that the instance is either the source or the destination of any traffic that it receives.

  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.

- `ssmAssociations`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnInstance.SsmAssociationProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnInstance.SsmAssociationProperty.html)[] — The SSM [document](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ssm-document.html) and parameter values in AWS Systems Manager to associate with this instance. To use this property, you must specify an IAM instance profile role for the instance. For more information, see [Create an IAM instance profile for Systems Manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-configuring-access-role.html) in the *AWS Systems Manager User Guide* .

  > You can associate only one document with an instance.

- `subnetId`: string | [ISubnetRef](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_ec2.ISubnetRef.html) — The ID of the subnet to launch the instance into.

  If you specify a network interface, you must specify any subnets as part of the network interface instead of using this parameter.

- `tags`: [CfnTag](/cdk/api/v2/docs/aws-cdk-lib.CfnTag.html)[] — The tags to add to the instance.

  These tags are not applied to the EBS volumes, such as the root volume, unless [PropagateTagsToVolumeOnCreation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-instance.html#cfn-ec2-instance-propagatetagstovolumeoncreation) is `true` .

- `tenancy`: string — The tenancy of the instance.

  An instance with a tenancy of `dedicated` runs on single-tenant hardware.

- `userData`: string — The parameters or scripts to store as user data.

  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](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-base64.html) .

  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.

- `volumes`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnInstance.VolumeProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnInstance.VolumeProperty.html)[] — The volumes to attach to the instance.

## Properties

- `additionalInfo`: string — This property is reserved for internal use.

- `affinity`: string — Indicates whether the instance is associated with a dedicated host.

- `attrAvailabilityZone`: string

- `attrInstanceId`: string — The ID of the instance.

- `attrPrivateDnsName`: string — The private DNS name of the specified instance.

  For example: `ip-10-24-34-0.ec2.internal` .

- `attrPrivateIp`: string — The private IP address of the specified instance.

  For example: `10.24.34.0` .

- `attrPublicDnsName`: string — The public DNS name of the specified instance.

  For example: `ec2-107-20-50-45.compute-1.amazonaws.com` .

- `attrPublicIp`: string — The public IP address of the specified instance.

  For example: `192.0.2.0` .

- `attrState`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) — The current state of the instance.

- `attrVpcId`: string — The ID of the VPC in which the instance is running.

- `availabilityZone`: string — The Availability Zone of the instance.

- `blockDeviceMappings`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnInstance.BlockDeviceMappingProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnInstance.BlockDeviceMappingProperty.html)[] — The block device mapping entries that defines the block devices to attach to the instance at launch.

- `CFN_RESOURCE_TYPE_NAME`: string (static) — The CloudFormation resource type name for this resource class.

- `cfnOptions`: [ICfnResourceOptions](/cdk/api/v2/docs/aws-cdk-lib.ICfnResourceOptions.html) — Options for this resource, such as condition, update policy etc.

- `cfnResourceType`: string — AWS resource type.

- `cpuOptions`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnInstance.CpuOptionsProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnInstance.CpuOptionsProperty.html) — The CPU options for the instance.

- `creationStack`: string[]

- `creditSpecification`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnInstance.CreditSpecificationProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnInstance.CreditSpecificationProperty.html) — The credit option for CPU usage of the burstable performance instance.

- `disableApiTermination`: boolean | [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) — Indicates whether termination protection is enabled for the instance.

- `ebsOptimized`: boolean | [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) — Indicates whether the instance is optimized for Amazon EBS I/O.

- `elasticGpuSpecifications`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnInstance.ElasticGpuSpecificationProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnInstance.ElasticGpuSpecificationProperty.html)[] — An elastic GPU to associate with the instance.

- `elasticInferenceAccelerators`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnInstance.ElasticInferenceAcceleratorProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnInstance.ElasticInferenceAcceleratorProperty.html)[] — An elastic inference accelerator to associate with the instance.

- `enclaveOptions`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnInstance.EnclaveOptionsProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnInstance.EnclaveOptionsProperty.html) — Indicates whether the instance is enabled for AWS Nitro Enclaves.

- `env`: [ResourceEnvironment](/cdk/api/v2/docs/aws-cdk-lib.interfaces.ResourceEnvironment.html)

- `hibernationOptions`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnInstance.HibernationOptionsProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnInstance.HibernationOptionsProperty.html) — Indicates whether an instance is enabled for hibernation.

- `hostId`: string — If you specify host for the `Affinity` property, the ID of a dedicated host that the instance is associated with.

- `hostResourceGroupArn`: string — The ARN of the host resource group in which to launch the instances.

- `iamInstanceProfile`: string — The name of an IAM instance profile.

- `imageId`: string — The ID of the AMI.

- `instanceInitiatedShutdownBehavior`: string — Indicates whether an instance stops or terminates when you initiate shutdown from the instance (using the operating system command for system shutdown).

- `instanceRef`: [InstanceReference](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_ec2.InstanceReference.html) — A reference to a Instance resource.

- `instanceType`: string — The instance type.

  For more information, see [Instance types](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html) in the *Amazon EC2 User Guide* .

- `ipv6AddressCount`: number — The number of IPv6 addresses to associate with the primary network interface.

- `ipv6Addresses`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnInstance.InstanceIpv6AddressProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnInstance.InstanceIpv6AddressProperty.html)[] — The IPv6 addresses from the range of the subnet to associate with the primary network interface.

- `kernelId`: string — The ID of the kernel.

- `keyName`: string — The name of the key pair.

  For more information, see [Create a key pair for your EC2 instance](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/create-key-pairs.html) .

- `launchTemplate`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnInstance.LaunchTemplateSpecificationProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnInstance.LaunchTemplateSpecificationProperty.html) — The launch template.

- `licenseSpecifications`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnInstance.LicenseSpecificationProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnInstance.LicenseSpecificationProperty.html)[] — The license configurations.

- `logicalId`: string — The logical ID for this CloudFormation stack element.

  The logical ID of the element
  is calculated from the path of the resource node in the construct tree.

  To override this value, use `overrideLogicalId(newLogicalId)`.

- `metadataOptions`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnInstance.MetadataOptionsProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnInstance.MetadataOptionsProperty.html) — The metadata options for the instance.

- `monitoring`: boolean | [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) — Specifies whether detailed monitoring is enabled for the instance.

- `networkInterfaces`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnInstance.NetworkInterfaceProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnInstance.NetworkInterfaceProperty.html)[] — The network interfaces to associate with the instance.

- `node`: [Node](/cdk/api/v2/docs/constructs.Node.html) — The tree node.

- `placementGroupName`: string — The name of an existing placement group that you want to launch the instance into (cluster | partition | spread).

- `privateDnsNameOptions`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnInstance.PrivateDnsNameOptionsProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnInstance.PrivateDnsNameOptionsProperty.html) — The options for the instance hostname.

- `privateIpAddress`: string — The primary IPv4 address.

  You must specify a value from the IPv4 address range of the subnet.

- `propagateTagsToVolumeOnCreation`: boolean | [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) — Indicates whether to assign the tags specified in the `Tags` property to the volumes specified in the `BlockDeviceMappings` property.

- `ramdiskId`: string — The ID of the RAM disk to select.

- `ref`: string — Return a string that will be resolved to a CloudFormation `{ Ref }` for this element.

  If, by any chance, the intrinsic reference of a resource is not a string, you could
  coerce it to an IResolvable through `Lazy.any({ produce: resource.ref })`.

- `securityGroupIds`: string[] — The IDs of the security groups.

- `securityGroups`: string[] — [Default VPC] The names of the security groups.

  For a nondefault VPC, you must use security group IDs instead.

- `sourceDestCheck`: boolean | [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) — Enable or disable source/destination checks, which ensure that the instance is either the source or the destination of any traffic that it receives.

- `ssmAssociations`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnInstance.SsmAssociationProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnInstance.SsmAssociationProperty.html)[] — The SSM [document](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ssm-document.html) and parameter values in AWS Systems Manager to associate with this instance. To use this property, you must specify an IAM instance profile role for the instance. For more information, see [Create an IAM instance profile for Systems Manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-configuring-access-role.html) in the *AWS Systems Manager User Guide* .

- `stack`: [Stack](/cdk/api/v2/docs/aws-cdk-lib.Stack.html) — The stack in which this element is defined.

  CfnElements must be defined within a stack scope (directly or indirectly).

- `subnetId`: string — The ID of the subnet to launch the instance into.

- `tags`: [TagManager](/cdk/api/v2/docs/aws-cdk-lib.TagManager.html) — Tag Manager which manages the tags for this resource.

- `tagsRaw`: [CfnTag](/cdk/api/v2/docs/aws-cdk-lib.CfnTag.html)[] — The tags to add to the instance.

- `tenancy`: string — The tenancy of the instance.

- `userData`: string — The parameters or scripts to store as user data.

- `volumes`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnInstance.VolumeProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnInstance.VolumeProperty.html)[] — The volumes to attach to the instance.

## Methods

- `addDeletionOverride(path: string): void` — Syntactic sugar for `addOverride(path, undefined)`.

  **Parameters**

  - `path` — The path of the value to delete.

- `addDependency(target: CfnResource): void` — Use `addResourceDependency` instead.

  This method has been renamed to `addResourceDependency` to more clearly
  set it apart from `construct.node.addDependency`. See the documentation
  of that function for more details.

- `addDependsOn(target: CfnResource): void` — Use `addResourceDependency` instead.

  This can be used for resources across stacks (or nested stack) boundaries
  and the dependency will automatically be transferred to the relevant scope.

  This method has been renamed to `addResourceDependency`, which makes it
  more clear that this method operates at a different level from the
  construct-level `construct.node.addDependency()` mechanism.

- `addMetadata(key: string, value: any): void` — Add a value to the CloudFormation Resource Metadata.

- `addOverride(path: string, value: any): void` — Adds an override to the synthesized CloudFormation resource.

  To add a
  property override, either use `addPropertyOverride` or prefix `path` with
  "Properties." (i.e. `Properties.TopicName`).

  If the override is nested, separate each nested level using a dot (.) in the path parameter.
  If there is an array as part of the nesting, specify the index in the path.

  To include a literal `.` in the property name, prefix with a `\`. In most
  programming languages you will need to write this as `"\\."` because the
  `\` itself will need to be escaped.

  For example,
  ```typescript
  cfnResource.addOverride('Properties.GlobalSecondaryIndexes.0.Projection.NonKeyAttributes', ['myattribute']);
  cfnResource.addOverride('Properties.GlobalSecondaryIndexes.1.ProjectionType', 'INCLUDE');
  ```
  would add the overrides
  ```json
  "Properties": {
    "GlobalSecondaryIndexes": [
      {
        "Projection": {
          "NonKeyAttributes": [ "myattribute" ]
          ...
        }
        ...
      },
      {
        "ProjectionType": "INCLUDE"
        ...
      },
    ]
    ...
  }
  ```

  The `value` argument to `addOverride` will not be processed or translated
  in any way. Pass raw JSON values in here with the correct capitalization
  for CloudFormation. If you pass CDK classes or structs, they will be
  rendered with lowercased key names, and CloudFormation will reject the
  template.

  **Parameters**

  - `path` — - The path of the property, you can use dot notation to override values in complex types.
  - `value` — - The value.

- `addPropertyDeletionOverride(propertyPath: string): void` — Adds an override that deletes the value of a property from the resource definition.

  **Parameters**

  - `propertyPath` — The path to the property.

- `addPropertyOverride(propertyPath: string, value: any): void` — Adds an override to a resource property.

  Syntactic sugar for `addOverride("Properties.<...>", value)`.

  **Parameters**

  - `propertyPath` — The path of the property.
  - `value` — The value.

- `addResourceDependency(target: CfnResource, reason?: string): void` — Indicates that this resource depends on another resource and cannot be provisioned unless the other resource has been successfully provisioned.

  This can be used for resources across stacks (or nested stack) boundaries
  and the dependency will automatically be transferred to the relevant scope.

  This method only adds dependencies between L1 resources. If you are
  looking for a generic construct-to-construct dependency mechanism that works
  for all constructs including L2s, use `construct.node.addDependency` instead.

- `applyCrossStackReferenceStrength(strength: ReferenceStrength): void` — Sets the cross-stack reference strength for this resource.

  When set, any cross-stack reference to this resource will use the specified
  strength instead of the global default from the consuming stack's context.

  **Parameters**

  - `strength` — - The reference strength to use for this resource.

- `applyRemovalPolicy(policy?: RemovalPolicy, options?: RemovalPolicyOptions): void` — Sets the deletion policy of the resource based on the removal policy specified.

  The Removal Policy controls what happens to this resource when it stops
  being managed by CloudFormation, either because you've removed it from the
  CDK application or because you've made a change that requires the resource
  to be replaced.

  The resource can be deleted (`RemovalPolicy.DESTROY`), or left in your AWS
  account for data recovery and cleanup later (`RemovalPolicy.RETAIN`). In some
  cases, a snapshot can be taken of the resource prior to deletion
  (`RemovalPolicy.SNAPSHOT`). A list of resources that support this policy
  can be found in the following link:

- `arnForInstance(resource: IInstanceRef): string` (static)

- `cfnPropertyName(cdkPropertyName: string): string`

- `fromInstanceId(scope: Construct, id: string, instanceId: string): IInstanceRef` (static) — Creates a new IInstanceRef from a instanceId.

- `getAtt(attributeName: string, typeHint?: ResolutionTypeHint): Reference` — Returns a token for an runtime attribute of this resource.

  Ideally, use generated attribute accessors (e.g. `resource.arn`), but this can be used for future compatibility
  in case there is no generated attribute.

  **Parameters**

  - `attributeName` — The name of the attribute.

- `getMetadata(key: string): any` — Retrieve a value value from the CloudFormation Resource Metadata.

- `inspect(inspector: TreeInspector): void` — Examines the CloudFormation resource and discloses attributes.

  **Parameters**

  - `inspector` — tree inspector to collect and process attributes.

- `isCfnElement(x: any): boolean` (static) — Returns `true` if a construct is a stack element (i.e. part of the synthesized cloudformation template).

  Uses duck-typing instead of `instanceof` to allow stack elements from different
  versions of this library to be included in the same stack.

  **Returns:** The construct as a stack element or undefined if it is not a stack element.

- `isCfnInstance(x: any): boolean` (static) — Checks whether the given object is a CfnInstance.

- `isCfnResource(x: any): boolean` (static) — Check whether the given object is a CfnResource.

- `isConstruct(x: any): boolean` (static) — Checks if `x` is a construct.

  Use this method instead of `instanceof` to properly detect `Construct`
  instances, even when the construct library is symlinked.

  Explanation: in JavaScript, multiple copies of the `constructs` library on
  disk are seen as independent, completely different libraries. As a
  consequence, the class `Construct` in each copy of the `constructs` library
  is seen as a different class, and an instance of one class will not test as
  `instanceof` the other class. `npm install` will not create installations
  like this, but users may manually symlink construct libraries together or
  use a monorepo tool: in those cases, multiple copies of the `constructs`
  library can be accidentally installed, and `instanceof` will behave
  unpredictably. It is safest to avoid using `instanceof`, and using
  this type-testing method instead.

  **Parameters**

  - `x` — Any object.

  **Returns:** true if `x` is an object created from a class which extends `Construct`.

- `obtainDependencies(): Stack | CfnResource[]` — Retrieves an array of resources and stacks this resource depends on.

  For resources depended on directly, returns the `CfnResource` object. For
  dependencies on other stacks, returns the `Stack` object. The order of the
  array is not guaranteed.

- `overrideLogicalId(newLogicalId: string): void` — Overrides the auto-generated logical ID with a specific ID.

  **Parameters**

  - `newLogicalId` — The new logical ID to use for this stack element.

- `removeDependency(target: CfnResource): void` — Use `removeResourceDependency` instead

  This can be used for resources across stacks (including nested stacks)
  and the dependency will automatically be removed from the relevant scope.

- `removeResourceDependency(target: CfnResource): void` — Indicates that this resource no longer depends on another resource.

  This can be used for resources across stacks (including nested stacks)
  and the dependency will automatically be removed from the relevant scope.

- `replaceDependency(target: CfnResource, newTarget: CfnResource): void` — Replaces one dependency with another.

  **Parameters**

  - `target` — The dependency to replace.
  - `newTarget` — The new dependency to add.

- `toString(): string` — Returns a string representation of this construct.

  **Returns:** a string representation of this resource

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.
  Use multiple `with()` calls if subsequent mixins should apply to added
  constructs.
