Skip to content
v2.277.0

HttpTokens Enum ​

The state of token usage for your instance metadata requests.

Example ​

ts
declare const vpc: ec2.Vpc;
declare const instanceType: ec2.InstanceType;
declare const machineImage: ec2.IMachineImage;

// Example 1: Enforce IMDSv2 with comprehensive options
new ec2.Instance(this, 'Instance', {
  vpc,
  instanceType,
  machineImage,
  httpEndpoint: true,
  httpProtocolIpv6: false,
  httpPutResponseHopLimit: 2,
  httpTokens: ec2.HttpTokens.REQUIRED,
  instanceMetadataTags: true,
});

// Example 2: Enforce IMDSv2 with minimal configuration
new ec2.Instance(this, 'SecureInstance', {
  vpc,
  instanceType,
  machineImage,
  httpTokens: ec2.HttpTokens.REQUIRED,
});
python
# vpc: ec2.Vpc
# instance_type: ec2.InstanceType
# machine_image: ec2.IMachineImage


# Example 1: Enforce IMDSv2 with comprehensive options
ec2.Instance(self, "Instance",
    vpc=vpc,
    instance_type=instance_type,
    machine_image=machine_image,
    http_endpoint=True,
    http_protocol_ipv6=False,
    http_put_response_hop_limit=2,
    http_tokens=ec2.HttpTokens.REQUIRED,
    instance_metadata_tags=True
)

# Example 2: Enforce IMDSv2 with minimal configuration
ec2.Instance(self, "SecureInstance",
    vpc=vpc,
    instance_type=instance_type,
    machine_image=machine_image,
    http_tokens=ec2.HttpTokens.REQUIRED
)
java
Vpc vpc;
InstanceType instanceType;
IMachineImage machineImage;


// Example 1: Enforce IMDSv2 with comprehensive options
// Example 1: Enforce IMDSv2 with comprehensive options
Instance.Builder.create(this, "Instance")
        .vpc(vpc)
        .instanceType(instanceType)
        .machineImage(machineImage)
        .httpEndpoint(true)
        .httpProtocolIpv6(false)
        .httpPutResponseHopLimit(2)
        .httpTokens(HttpTokens.REQUIRED)
        .instanceMetadataTags(true)
        .build();

// Example 2: Enforce IMDSv2 with minimal configuration
// Example 2: Enforce IMDSv2 with minimal configuration
Instance.Builder.create(this, "SecureInstance")
        .vpc(vpc)
        .instanceType(instanceType)
        .machineImage(machineImage)
        .httpTokens(HttpTokens.REQUIRED)
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
Vpc vpc;
InstanceType instanceType;
IMachineImage machineImage;


// Example 1: Enforce IMDSv2 with comprehensive options
// Example 1: Enforce IMDSv2 with comprehensive options
new Instance(this, "Instance", new InstanceProps {
    Vpc = vpc,
    InstanceType = instanceType,
    MachineImage = machineImage,
    HttpEndpoint = true,
    HttpProtocolIpv6 = false,
    HttpPutResponseHopLimit = 2,
    HttpTokens = HttpTokens.REQUIRED,
    InstanceMetadataTags = true
});

// Example 2: Enforce IMDSv2 with minimal configuration
// Example 2: Enforce IMDSv2 with minimal configuration
new Instance(this, "SecureInstance", new InstanceProps {
    Vpc = vpc,
    InstanceType = instanceType,
    MachineImage = machineImage,
    HttpTokens = HttpTokens.REQUIRED
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var vpc Vpc
var instanceType InstanceType
var machineImage IMachineImage


// Example 1: Enforce IMDSv2 with comprehensive options
// Example 1: Enforce IMDSv2 with comprehensive options
ec2.NewInstance(this, jsii.String("Instance"), &InstanceProps{
	Vpc: Vpc,
	InstanceType: InstanceType,
	MachineImage: MachineImage,
	HttpEndpoint: jsii.Boolean(true),
	HttpProtocolIpv6: jsii.Boolean(false),
	HttpPutResponseHopLimit: jsii.Number(2),
	HttpTokens: ec2.HttpTokens_REQUIRED,
	InstanceMetadataTags: jsii.Boolean(true),
})

// Example 2: Enforce IMDSv2 with minimal configuration
// Example 2: Enforce IMDSv2 with minimal configuration
ec2.NewInstance(this, jsii.String("SecureInstance"), &InstanceProps{
	Vpc: Vpc,
	InstanceType: InstanceType,
	MachineImage: MachineImage,
	HttpTokens: ec2.HttpTokens_REQUIRED,
})

Members ​

MemberDescription
OPTIONALIf the state is optional, you can choose to retrieve instance metadata with or without a signed token header on your request.
REQUIREDIf the state is required, you must send a signed token header with any instance metadata retrieval requests.

Referenced by ​

  • InstanceProps.httpTokenshttp_tokenshttpTokensHttpTokensHttpTokens