AWS Amazon EC2 Host
This page shows how to write Terraform and CloudFormation for Amazon EC2 Host and write them securely.
aws_ec2_host (Terraform)
The Host in Amazon EC2 can be configured in Terraform with the resource name aws_ec2_host
. The following sections describe how to use the resource and its parameters.
Example Usage from GitHub
An example could not be found in GitHub.
Parameters
The following arguments are supported:
auto_placement
- (Optional) Indicates whether the host accepts any untargeted instance launches that match its instance type configuration, or if it only accepts Host tenancy instance launches that specify its unique host ID. Valid values:on
,off
. Default:on
.availability_zone
- (Required) The Availability Zone in which to allocate the Dedicated Host.host_recovery
- (Optional) Indicates whether to enable or disable host recovery for the Dedicated Host. Valid values:on
,off
. Default:off
.instance_family
- (Optional) Specifies the instance family to be supported by the Dedicated Hosts. If you specify an instance family, the Dedicated Hosts support multiple instance types within that instance family. Exactly one ofinstance_family
orinstance_type
must be specified.instance_type
- (Optional) Specifies the instance type to be supported by the Dedicated Hosts. If you specify an instance type, the Dedicated Hosts support instances of the specified instance type only. Exactly one ofinstance_family
orinstance_type
must be specified.tags
- (Optional) Map of tags to assign to this resource. If configured with a providerdefault_tags
configuration block present, tags with matching keys will overwrite those defined at the provider-level.
In addition to all arguments above, the following attributes are exported:
id
- The ID of the allocated Dedicated Host. This is used to launch an instance onto a specific host.arn
- The ARN of the Dedicated Host.owner_id
- The ID of the AWS account that owns the Dedicated Host.tags_all
- A map of tags assigned to the resource, including those inherited from the providerdefault_tags
configuration block.
Explanation in Terraform Registry
Provides an EC2 Host resource. This allows Dedicated Hosts to be allocated, modified, and released.
Tips: Best Practices for The Other AWS Amazon EC2 Resources
In addition to the aws_default_vpc, AWS Amazon EC2 has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.
aws_default_vpc
Ensure to avoid using default VPC
It is better to define the own VPC and use it.
aws_network_acl_rule
Ensure your network ACL rule blocks unwanted inbound traffic
It is better to block unwanted inbound traffic.
aws_ebs_volume
Ensure to use a customer-managed key for EBS volume encryption
It is better to use a customer-managed key for EBS volume encryption. It can be gain more control over the encryption by using customer-managed keys (CMK).
aws_instance
Ensure to avoid storing AWS access keys in user data
It is better to avoid storing AWS access keys in user data. `aws_iam_instance_profile` could be used instead.
aws_security_group
Ensure your security group blocks unwanted inbound traffic
It is better to block unwanted inbound traffic.
AWS::EC2::Host (CloudFormation)
The Host in EC2 can be configured in CloudFormation with the resource name AWS::EC2::Host
. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
Type: 'AWS::EC2::Host'
Properties: {}
EC2VPC35SOY:
Type: 'AWS::EC2::VPC'
Properties: {}
Resources:
Type: AWS::EC2::Host
Properties:
AutoPlacement: 'on'
AvailabilityZone: us-east-1a
InstanceType: mac1.metal
rEc2Instance:
Type: AWS::EC2::Host
Properties:
AvailabilityZone: !Ref '<caret>
InstanceType: '1'
Type: AWS::EC2::Host
Properties:
AvailabilityZone: !Ref '<caret>
InstanceType: '1'
Type: AWS::EC2::Host
Description: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-host.html
Properties:
AvailabilityZone: !Ref 'AvailabilityZone'
InstanceType: !Ref 'InstanceType'
"AWS::EC2::Host": {
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-host.html",
"Properties": {
"AutoPlacement": {
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-host.html#cfn-ec2-host-autoplacement",
"PrimitiveType": "String",
"AWS::EC2::Host": {
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-host.html",
"Properties": {
"AutoPlacement": {
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-host.html#cfn-ec2-host-autoplacement",
"PrimitiveType": "String",
"AWS::EC2::Host": {
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-host.html",
"Properties": {
"AutoPlacement": {
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-host.html#cfn-ec2-host-autoplacement",
"PrimitiveType": "String",
"AWS::EC2::Host": {
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-host.html",
"Properties": {
"AutoPlacement": {
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-host.html#cfn-ec2-host-autoplacement",
"PrimitiveType": "String",
"AWS::EC2::Host": {
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-host.html",
"Properties": {
"AutoPlacement": {
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-host.html#cfn-ec2-host-autoplacement",
"PrimitiveType": "String",
Parameters
-
AutoPlacement
optional - String -
AvailabilityZone
required - String -
HostRecovery
optional - String -
InstanceType
required - String
Explanation in CloudFormation Registry
Allocates a fully dedicated physical server for launching EC2 instances. Because the host is fully dedicated for your use, it can help you address compliance requirements and reduce costs by allowing you to use your existing server-bound software licenses. For more information, see Dedicated Hosts in the Amazon EC2 User Guide for Linux Instances.
Frequently asked questions
What is AWS Amazon EC2 Host?
AWS Amazon EC2 Host is a resource for Amazon EC2 of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.
Where can I find the example code for the AWS Amazon EC2 Host?
For CloudFormation, the semmersultan/semmer-cloudformation, scottenriquez/aws-reinvent-2020-samples and shalupov/idea-cloudformation source code examples are useful. See the CloudFormation Example section for further details.