Use CreateDhcpOptions with a CLI - Amazon Elastic Compute Cloud
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Use CreateDhcpOptions with a CLI

The following code examples show how to use CreateDhcpOptions.

CLI
Amazon CLI

To create a set of DHCP options

The following create-dhcp-options example creates a set of DHCP options that specifies the domain name, the domain name servers, and the NetBIOS node type.

aws ec2 create-dhcp-options \ --dhcp-configuration \ "Key=domain-name-servers,Values=10.2.5.1,10.2.5.2" \ "Key=domain-name,Values=example.com" \ "Key=netbios-node-type,Values=2"

Output:

{ "DhcpOptions": { "DhcpConfigurations": [ { "Key": "domain-name", "Values": [ { "Value": "example.com" } ] }, { "Key": "domain-name-servers", "Values": [ { "Value": "10.2.5.1" }, { "Value": "10.2.5.2" } ] }, { "Key": "netbios-node-type", "Values": [ { "Value": "2" } ] } ], "DhcpOptionsId": "dopt-06d52773eff4c55f3" } }
PowerShell
Tools for PowerShell

Example 1: This example creates the specified set of DHCP options. The syntax used by this example requires PowerShell version 3 or later.

$options = @( @{Key="domain-name";Values=@("abc.local")}, @{Key="domain-name-servers";Values=@("10.0.0.101","10.0.0.102")}) New-EC2DhcpOption -DhcpConfiguration $options

Output:

DhcpConfigurations DhcpOptionsId Tags ------------------ ------------- ---- {domain-name, domain-name-servers} dopt-1a2b3c4d {}

Example 2: With PowerShell version 2, you must use New-Object to create each DHCP option.

$option1 = New-Object Amazon.EC2.Model.DhcpConfiguration $option1.Key = "domain-name" $option1.Values = "abc.local" $option2 = New-Object Amazon.EC2.Model.DhcpConfiguration $option2.Key = "domain-name-servers" $option2.Values = @("10.0.0.101","10.0.0.102") New-EC2DhcpOption -DhcpConfiguration @($option1, $option2)

Output:

DhcpConfigurations DhcpOptionsId Tags ------------------ ------------- ---- {domain-name, domain-name-servers} dopt-2a3b4c5d {}
  • For API details, see CreateDhcpOptions in Amazon Tools for PowerShell Cmdlet Reference.

For a complete list of Amazon SDK developer guides and code examples, see Create Amazon EC2 resources using an Amazon SDK. This topic also includes information about getting started and details about previous SDK versions.